简体   繁体   English

Terratest 对错误的断言抛出错误

[英]Terratest throws error on assertions on errors

Hello I have the following test你好我有以下测试

func badTags(t *testing.T){
  terraformOptions := &terraform.Options{
        TerraformDir: "../bad_values",
    }
  tags := terraform.Output(t, terraformOptions, "test_required_tags")
  assert.Error(t, tags)

}

Note that the value of tag should throw an error but I keep getting the following error请注意,标签的值应该抛出错误,但我不断收到以下错误

string does not implement error (missing Error method)

If I remove the assertion , an error with a String message is throws as expected.如果我删除 assertion ,则会按预期抛出带有 String 消息的错误。 How can I assert on the error?我如何断言错误?

assert.Error asserts that a function returned an error. assert.Error断言函数返回了错误。 , it's just like : ,就像:

if err == nil {
    t.Error("no error returned")
}

But here the given parameter is tags , and tags is a string, according to the terratest documentation that why your receive the following error :但是这里给定的参数是tags ,并且tags是一个字符串,根据terratest 文档,为什么您会收到以下错误:

string does not implement error (missing Error method)

Use OutputForKeys must solve your issue, please try this :使用OutputForKeys必须解决您的问题,请尝试以下操作:

func badTags(t *testing.T){
  terraformOptions := &terraform.Options{
        TerraformDir: "../bad_values",
    }
  validTags := terraform.OutputForKeys(t, terraformOptions, []string{"test_required_tags"})
  assert.Contains(t, validTags, "test_required_tags")
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Terratest 多个目标 - Terratest multiple targets 如何在 terratest 中扮演一个角色 - how to pass an assume role in terratest 当我尝试运行我的 terratest go 代码以验证 AWS 上的 EKS 集群时,调用 spdy.NewRoundTripperWithProxy 错误时获取太多参数 - Getting too many arguments in call to spdy.NewRoundTripperWithProxy error when i try to run my terratest go code for validating EKS cluster on AWS Terratest 断言字符串因 GitHub 操作而失败 - Terratest assert string fails with GitHub Actions Terratest - 如何在函数之间传递 Terraform 输出 - Terratest - How to pass Terraform outputs between functions 如何在Terratest Terraform设置中覆盖远程状态 - How to override remote state in Terratest Terraform setup 在awsgosdk的帮助下尝试在terratest中调用cloudwatch loggroupname和logstreamname - trying to call cloudwatch loggroupname and logstreamname in terratest with the help of awsgosdk 如何使用自定义的“terraform apply”命令实现 terratest(golang)? - How do I implement terratest(golang) with customized "terraform apply" command? 使用 Go 任务的 Yaml Azure 管道安装 Terratest 问题 - 在子文件夹中触发 terratest 测试 - Issue installing Terratest using Go Task's Yaml Azure pipeline - issue triggering terratest tests in sub-folder 如何使用 terratest 针对多个标签选择器过滤 pod? - how to filter pods against multiple label selectors with terratest?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM