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. How can I assert on the error?
assert.Error
asserts that a function returned an 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 :
string does not implement error (missing Error method)
Use OutputForKeys
must solve your issue, please try this :
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")
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.