Skip to content

Latest commit

 

History

History
67 lines (50 loc) · 2.72 KB

TESTING.md

File metadata and controls

67 lines (50 loc) · 2.72 KB

Testing

We have basically 2 types of tests: Acceptance tests and Unit tests.

Acceptance Tests:

We're using terraform-plugin-testing Golang module for writing acceptance tests.

For more information, please refer to the acceptance tests documentation.

In order to run the acceptance tests, several environment variables should be present. BA_API_URI to communicate with the Biganimal API. We also use the BA_TF_ACC_VAR_<resource_type>_<variable_name> environment variables to run the acceptance tests. Example variable names can be found in the .env.example file.

You can run the acceptance tests with the following command:

$> make testacc

or if you would like to run an individual test, For example:

$> TF_ACC=1 go test -timeout 600s -run ^TestAccResourceCluster_basic$ github.com/EnterpriseDB/terraform-provider-biganimal/pkg/provider

For more details, please refer to Running Acceptance Tests.

Adding a new env var for your Acceptance tests:

When you want to introduce a new env var for your tests, please make sure to pay attention to those points:

  1. The environment variable name is in the form of BA_TF_ACC_VAR_<resource_type>_<variable_name>
  2. Add the variable to the acc_env_vars_checklist.
  3. Make sure that the testAccResourcePreCheck is called in the PreCheck function of the test. For example:
func TestAccBiganimalRegionResource_basic(t *testing.T) {
    var (
		acc_env_vars_checklist = []string{
			"BA_TF_ACC_VAR_region_project_id",
            ...
		}

        ...
		projectID  = os.Getenv("BA_TF_ACC_VAR_region_project_id")
        ...
	)

	resource.Test(t, resource.TestCase{
		PreCheck: func() {
			testAccPreCheck(t)
			testAccResourcePreCheck(t, "region", acc_env_vars_checklist)
		},
        ...
  1. Also, add the new env var to the .env.example file.

Unit Tests:

Especially for isolated functions, unit tests are essential to ensure that the plugin code works. Please refer to Unit Testing page of the official terraform documentation for further details on the topic.

You can run the acceptance tests with the following command:

make test

Other Resources: