Terratest throws error on assertions on errors

Viewed 473

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?

1 Answers

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")
}
Related