-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Proposal: Combine Singular Data Source and Resource Acceptance Testing #8223
Comments
… configured APIs Reference: #12350 Reference: #8223 Previously: ``` TestAccDataSourceAwsApiGatewayRestApi_EndpointConfiguration_VpcEndpointIds: testing.go:669: Step 0 error: errors during apply: Error: error setting endpoint_configuration: endpoint_configuration.0.vpc_endpoint_ids: '': source data must be an array or slice, got struct on /var/folders/w8/05f3x02n27x72g0mc2jy6_180000gp/T/tf-test660234204/main.tf line 62: (source code not available) ``` Output from acceptance testing: ``` --- PASS: TestAccDataSourceAwsApiGatewayRestApi_basic (18.71s) --- PASS: TestAccDataSourceAwsApiGatewayRestApi_EndpointConfiguration_VpcEndpointIds (151.75s) --- PASS: TestAccAWSAPIGatewayRestApi_tags (66.14s) --- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration (89.86s) --- PASS: TestAccAWSAPIGatewayRestApi_disappears (118.54s) --- PASS: TestAccAWSAPIGatewayRestApi_api_key_source (187.17s) --- PASS: TestAccAWSAPIGatewayRestApi_openapi (239.32s) --- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration_VPCEndpoint (370.75s) --- PASS: TestAccAWSAPIGatewayRestApi_policy (459.60s) --- PASS: TestAccAWSAPIGatewayRestApi_basic (505.99s) --- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration_Private (690.91s) ```
… configured APIs (#12825) Reference: #12350 Reference: #8223 Previously: ``` TestAccDataSourceAwsApiGatewayRestApi_EndpointConfiguration_VpcEndpointIds: testing.go:669: Step 0 error: errors during apply: Error: error setting endpoint_configuration: endpoint_configuration.0.vpc_endpoint_ids: '': source data must be an array or slice, got struct on /var/folders/w8/05f3x02n27x72g0mc2jy6_180000gp/T/tf-test660234204/main.tf line 62: (source code not available) ``` Output from acceptance testing: ``` --- PASS: TestAccDataSourceAwsApiGatewayRestApi_basic (18.71s) --- PASS: TestAccDataSourceAwsApiGatewayRestApi_EndpointConfiguration_VpcEndpointIds (151.75s) --- PASS: TestAccAWSAPIGatewayRestApi_tags (66.14s) --- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration (89.86s) --- PASS: TestAccAWSAPIGatewayRestApi_disappears (118.54s) --- PASS: TestAccAWSAPIGatewayRestApi_api_key_source (187.17s) --- PASS: TestAccAWSAPIGatewayRestApi_openapi (239.32s) --- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration_VPCEndpoint (370.75s) --- PASS: TestAccAWSAPIGatewayRestApi_policy (459.60s) --- PASS: TestAccAWSAPIGatewayRestApi_basic (505.99s) --- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration_Private (690.91s) ```
… configured APIs (hashicorp#12825) Reference: hashicorp#12350 Reference: hashicorp#8223 Previously: ``` TestAccDataSourceAwsApiGatewayRestApi_EndpointConfiguration_VpcEndpointIds: testing.go:669: Step 0 error: errors during apply: Error: error setting endpoint_configuration: endpoint_configuration.0.vpc_endpoint_ids: '': source data must be an array or slice, got struct on /var/folders/w8/05f3x02n27x72g0mc2jy6_180000gp/T/tf-test660234204/main.tf line 62: (source code not available) ``` Output from acceptance testing: ``` --- PASS: TestAccDataSourceAwsApiGatewayRestApi_basic (18.71s) --- PASS: TestAccDataSourceAwsApiGatewayRestApi_EndpointConfiguration_VpcEndpointIds (151.75s) --- PASS: TestAccAWSAPIGatewayRestApi_tags (66.14s) --- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration (89.86s) --- PASS: TestAccAWSAPIGatewayRestApi_disappears (118.54s) --- PASS: TestAccAWSAPIGatewayRestApi_api_key_source (187.17s) --- PASS: TestAccAWSAPIGatewayRestApi_openapi (239.32s) --- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration_VPCEndpoint (370.75s) --- PASS: TestAccAWSAPIGatewayRestApi_policy (459.60s) --- PASS: TestAccAWSAPIGatewayRestApi_basic (505.99s) --- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration_Private (690.91s) ```
Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you! |
Bumping to keep this open. |
Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you! |
Community Note
Background
We have hit another regression scenario where a resource update for new functionality broke the respective data source.
Historically, the main reason for these types of issues was that the data source shared the
Read
function with the resource. When the data source does not have its schema (and preferably its acceptance testing) also updated, the mismatch in the data source can cause it return errors and prevent usage. We have since gone through and refactored many of the data sources to implement their ownRead
function to make the appropriate root level attributed.Set()
calls.This last occurrence was more subtle though and involved a new nested schema attribute under a configuration block. Typically for these configuration block attributes, the data source and resource
Read
functions call out to a sharedflattenXXX()
function to convert an SDK object from the API response into the expected Terraform state. Since there is yet another tightly coupled implementation and mostd.Set()
calls for configuration blocks are now correctly performing error checking, the mismatch of schemas causes the data source to return errors and prevent usage.Maintainers are procedurally accustomed to running acceptance testing for only the particular resource pattern (e.g.
TestAccAWSServiceThing_
) OR data source pattern (e.g.TestAccAWSServiceThingDataSource_
) affected by code changes as running the entire acceptance test suite is unrealistic due to time and money constraints.Currently, we write bespoke data source acceptance testing in
aws/data_source_RESOURCE_test.go
files. While many variations of resource test cases are created in theaws/resource_RESOURCE_test.go
file, there is very little parity to when a matching data source test case is created. The data source testing typically only covers basic use cases and the test configurations are usually exact duplicates of resource test configurations plus a data source declaration.Respective data sources are very common feature requests which are showing no signs of decrease, so problems outlined above will only continue to grow in size over time.
Regression Issue References:
Proposal
Migrate singular data source testing to the majority of resource test cases by adding a data source declaration to the each resource configuration along with relevant data source attribute checks.
This solves a few problems:
Acceptance Testing Configuration Updates
Generally data source configurations can use a straightforward argument reference to the resource identifier
More advanced data source cases can be handled by keeping the existing data source configurations and test checks as-is but updating the data source test names to match the resource test naming pattern.
Acceptance Testing Function Updates
Essentially we can take the current style of data source testing that prefers to utilize
resource.TestCheckResourceAttrPair()
to ensure the resource and data source attributes properly exist and have matching values where expected.Affected Resources and Data Sources
Abandoned Ideas
Read
from the resourceRead
by splitting theflattenXXX()
functions into resource and data source variants. Bug fixes will need to be implemented twice and adds unnecessary code complexity.Required
/Optional
/Computed
handling for every attribute. Reconciling this manually would be error prone and add unnecessary schema complexity.TestAccAWSServiceThing(DataSource)?_
while others would need complex matching likeTestAcc(DataSource)?A[wW][sS](S(ervice|ERVICE))?Thing(DataSource)?_
The text was updated successfully, but these errors were encountered: