[英]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.