Skip to content
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

Merged
merged 1 commit into from
Apr 28, 2020

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Mar 18, 2020

Reference: #71
Reference: bflad/tfproviderlint#104

The TestSchemaMap_InternalValidate tests also include TODOs for potential schema validation improvements.

…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.
},
},
},
false, // TODO: This should return an error as it will always error during runtime
Copy link
Contributor

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?

Copy link
Contributor Author

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

@appilon
Copy link
Contributor

appilon commented Apr 23, 2020

We have recently pushed V2's history onto master as the new mainline of development, I am retargeting your PR to v1-maint.

@appilon appilon changed the base branch from master to v1-maint April 23, 2020 18:19
Copy link
Contributor

@appilon appilon left a 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)

@appilon appilon merged commit a4210cb into hashicorp:v1-maint Apr 28, 2020
@ghost
Copy link

ghost commented May 29, 2020

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.

@ghost ghost locked and limited conversation to collaborators May 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants