-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests/helper/schema: Add unit testing covering existing behavior of ConflictsWith and list index/map key syntax #364
Conversation
…onflictsWith and list index/map key syntax Reference: hashicorp#71 Reference: bflad/tfproviderlint#104 The `TestSchemaMap_InternalValidate` tests also include TODOs for potential schema validation improvements.
5f8e2b8
to
40d3b8a
Compare
}, | ||
}, | ||
}, | ||
false, // TODO: This should return an error as it will always error during runtime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you let me know more details on this TODO? If the test is supposed to error but currently doesn't doesn't that mean something is broken?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @appilon 👋 Yes, that TODO is meant to signify something is broken in the sense that InternalValidate()
does not fail when you self-reference in this manner, however the schema is invalid and will never work when the attribute is declared in a configuration.
Copying this configuration block schema into a real attribute of a real resource (I just randomly chose aws_devicefarm_project
):
func resourceAwsDevicefarmProject() *schema.Resource {
return &schema.Resource{
Create: resourceAwsDevicefarmProjectCreate,
Read: resourceAwsDevicefarmProjectRead,
Update: resourceAwsDevicefarmProjectUpdate,
Delete: resourceAwsDevicefarmProjectDelete,
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"config_block_attr": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nested_attr": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"config_block_attr.0.nested_attr"},
},
},
},
},
},
}
}
And adding the configuration to the test configuration:
func testAccDeviceFarmProjectConfig(rInt int) string {
return fmt.Sprintf(`
resource "aws_devicefarm_project" "foo" {
name = "tf-testproject-%d"
config_block_attr {
nested_attr = "test"
}
}
`, rInt)
}
Will always return a runtime error due to the self-reference:
=== CONT TestAccAWSDeviceFarmProject_basic
TestAccAWSDeviceFarmProject_basic: testing.go:669: Step 0 error: config is invalid: "config_block_attr.0.nested_attr": conflicts with config_block_attr.0.nested_attr
We have recently pushed V2's history onto master as the new mainline of development, I am retargeting your PR to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tests! Can you file an issue regarding the fact that you can write tests cases that should fail but don't and link to this PR (or the V2 one)
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Reference: #71
Reference: bflad/tfproviderlint#104
The
TestSchemaMap_InternalValidate
tests also include TODOs for potential schema validation improvements.