版本
问题
我根据可怕的博士创建了一个测试。测试的代码可以在标题下找到:iam_role_standard_test.go
当我在本地运行测试时,一切都如预期的那样工作。
但是,我使用GitHub操作作为CI/CD工具。执行工作流作业时,会出现以下错误(工作流文件位于标题workflow.yaml):下面)
错误跟踪: iam_role_standard_test.go:63 错误:不相等: 预期:"TestIamRole_dRGsKn“ 实际:"command/home/runner/work/_temp/e5c5b8d2-62c5-4e73-b99f-d2e79eaa9765/terraform-bin输出-没有颜色的name\nTestIamRole_dRGsKn\n::debug::Terraform与代码0.\n::set::stdout: TestIamRole_dRGsKn%0A\n::debug::stderr:\n::exitcode:0\n:set- name=stdout::TestIamRole_dRGsKn%0A\n::set-output name=stderr::n::set- output name=exitcode::0“ 迪夫: --预期 +++实数 @@ -1 +1,9 @@ +command/home/runner/work/_temp/e5c5b8d2-62c5-4e73-b99f-d2e79eaa9765/terraform-bin输出-无颜色名称 TestIamRole_dRGsKn +:调试::Terraform与代码0一起退出。 +::调试::stdout: TestIamRole_dRGsKn%0A +:调试::stderr: +:调试::exitcode:0 +::设置输出name=stdout::TestIamRole_dRGsKn%0A +::set-输出name=stderr:: +::设置输出name=exitcode::0 测试: TestIamRole
据我所知,这是失败的,因为"TestIamRole_dRGsKn"和TestIamRole_dRGsKn是不一样的。
问题
如何格式化terraform的输出,使字符串被断言为相等?
iam_role_standard_test.go
package test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
)
func TestIamRole(t *testing.T) {
uniqueId := random.UniqueId()
expectedRoleName := fmt.Sprintf("TestIamRole_%s", uniqueId)
// Retryable errors in terraform testing.
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: "../path/to/terraform",
Lock: true,
// Configure backend to assume IamManager role
BackendConfig: map[string]interface{}{
"bucket": "terraform-state-bucket",
"dynamodb_table": "terraform_state_lock",
"encrypt": true,
"key": "my/key/terraform.tfstate",
"kms_key_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"region": "us-east-1",
"role_arn": "arn:aws:iam::123456789012:role/my-role",
},
// Variables to pass to our Terraform code using -var options
Vars: map[string]interface{}{
"create": "true",
"account_id": "123456789012",
"is_instance_profile": "false",
"name": expectedRoleName,
"description": "A test IAM role",
"path": "/",
"force_detach_policies": "true",
"max_session_duration": "43200",
},
})
defer terraform.Destroy(t, terraformOptions)
// Deploy configuration
terraform.InitAndApply(t, terraformOptions)
// Capture outputs
actualRoleName := terraform.Output(t, terraformOptions, "name")
// Assert output vaules
assert.Equal(t, expectedRoleName, actualRoleName)workflow.yaml
name: terratest
on: [ push ]
jobs:
terratest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.15.2'
- uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.13.5
- run: go mod init github.com/my-org/my-repo
- run: go test -v -count=1 -timeout 30m
working-directory: tests
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}发布于 2020-12-23 12:16:00
发现了问题。
这是参考的在这些问题上的最迟的GitHub回购
在这里张贴答案,以防其他人在这上面浪费他们生命中的一分钟!
更改我的workflow.yaml文件解决了这个问题:
name: terratest
on: [ push ]
jobs:
terratest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.15.2'
- uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.13.5
terraform_wrapper: false
- run: go mod init github.com/my-org/my-repo
- run: go test -v -count=1 -timeout 30m
working-directory: tests
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}https://stackoverflow.com/questions/65391466
复制相似问题