dikhan / terraform-provider-openapi

OpenAPI Terraform Provider that configures itself at runtime with the resources exposed by the service provider (defined in a swagger file)
Apache License 2.0
275 stars 48 forks source link

Introduce testing standards to facilitate collaboration and enhance tests execution time #258

Closed dikhan closed 4 years ago

dikhan commented 4 years ago

Is your feature request related to a problem?

As a OpenAPI Terraform contributor I want an agreed upon testing strategy (currently there are more than 5 different testing patterns in the code such as BDD convey, using just assert, table driven, etc) So that I as a contributor I can follow certain guidelines and following some consistent tests in the OpenAPI Terraform repo while also fixing the performance in the tests which currently are using convey inefficiently causing extra test execution time

As a OpenAPI Terraform contributor I want the tests using convey to execute efficiently without extra iterations (as shown in the acceptance criteria) So that unit tests execute faster. At the moment the execution time running the tests is almost 1 minute. Without the extra convey iterations this can be reduced significantly to 40s or less.

make unittest  59.97s user 10.60s system 260% cpu 27.111 total

Describe the solution you'd like

A clear and concise description of what you want to happen.

Acceptance criteria

Scenario: Contributor has testing guidelines to follow when contributing to the code
Given new contributions to the OpenAPI Terraform repo
When committing code as well as tests
Then I want to make sure I follow testing standards
Scenario: Improve tests execution time
Given the current tests in the OpenAPI Terraform provider
When executing them
Then I want the tests to use convey efficiently (eg: no extra loops are present when performing the assertions). See the example below:
Convey("Given a resource factory initialized with a spec resource with a schema definition containing a string property", t, func() {
 // Use case - string property (terraform configuration pseudo representation below):
 // string_property = "some value"
 r, resourceData := testCreateResourceFactory(t, stringProperty)
 Convey("When populatePayload is called with an empty map, the string property in the resource schema and it's corresponding terraform resourceData state data value", func() {
   payload := map[string]interface{}{}
   dataValue, _ := resourceData.GetOkExists(stringProperty.GetTerraformCompliantPropertyName())
   err := r.populatePayload(payload, stringProperty, dataValue)
     Convey("Then the error should be nil", func() {
       So(err, ShouldBeNil)
     })
  Convey("Then the map returned should not be empty", func() {
     So(payload, ShouldNotBeEmpty)
  })
  Convey("And then payload returned should have the string property", func() {
     So(payload, ShouldContainKey, stringProperty.Name)
  })
  Convey("And then payload returned should have the data value from the state file", func() {
    So(payload[stringProperty.Name], ShouldEqual, stringProperty.Default)
  })
 })
})
Convey("Given a resource factory initialized with a spec resource with a schema definition containing a string property", t, func() {
 // Use case - string property (terraform configuration pseudo representation below):
 // string_property = "some value"
 r, resourceData := testCreateResourceFactory(t, stringProperty)
 Convey("When populatePayload is called with an empty map, the string property in the resource schema and it's corresponding terraform resourceData state data value", func() {
   payload := map[string]interface{}{}
   dataValue, _ := resourceData.GetOkExists(stringProperty.GetTerraformCompliantPropertyName())
   err := r.populatePayload(payload, stringProperty, dataValue)
     Convey("Then the result returned should be the expected one", func()
       So(err, ShouldBeNil)
       So(payload, ShouldNotBeEmpty)
       So(payload, ShouldContainKey, stringProperty.Name)
     })
})

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

Checklist (for admin only)

Don't forget to go through the checklist to make sure the issue is created properly: