You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/user/TestingPhilosophy.md
+30-33Lines changed: 30 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,52 +13,49 @@ The unit tests in this project are designed to quickly and efficiently verify th
13
13
14
14
### Unit Testing Structure
15
15
16
-
The unit tests are written as [table-driven tests](https://go.dev/wiki/TableDrivenTests) so that they are easier to read, understand, and expand. The tests are divided into two files, [default_unit_test.go](../../test/default_unit_test.go) and [non_default_unit_test.go](../../test/non_default_unit_test.go).
16
+
The unit tests are written as [table-driven tests](https://go.dev/wiki/TableDrivenTests) so that they are easier to read, understand, and expand. The tests are divided into two packages, [defaultplan](../../test/defaultplan) and [nondefaultplan](../../test/nondefaultplan).
17
17
18
-
The test file named default_unit_test.go validates the default values of a Terraform plan. This testing ensures that there are no regressions in the default behavior of the code base. The test file named non_default_unit_test.go modifies the input values before running the Terraform plan. After generating the plan file, the test verifies that it contains the expected values. Both files are written as table-driven tests.
18
+
The test package defaultplan validates the default values of a Terraform plan. This testing ensures that there are no regressions in the default behavior of the code base. The test package nondefaultplan modifies the input values before running the Terraform plan. After generating the plan file, the test verifies that it contains the expected values. Both sets of tests are written to be table-driven.
19
19
20
-
To see an example, look at the `TestPlanStorageDefaults` function in the default_unit_test.go file that is shown below.
20
+
To see an example, look at the `TestPlanStorage` function in the defaultplan/storage_test.go file that is shown below.
21
21
22
-
With the Table-Driven approach, each entry in the `storageTests` map is a test. These tests verify that the expected value matches the actual value of the "module.nfs[0].azurerm_linux_virtual_machine.vm" resource. We use the [k8s.io JsonPath](https://pkg.go.dev/k8s.io/[email protected]/util/jsonpath) library to parse the Terraform output and extract the desired attribute. The runTest call is a helper function that runs through each test in the map and perform assertions. See the [helpers.go](../../test/helpers.go) file for more information on the common helper functions.
22
+
With the Table-Driven approach, each entry in the `tests` map is a test. These tests verify that the expected value matches the actual value of the "module.nfs[0].azurerm_linux_virtual_machine.vm" resource. We use the [k8s.io JsonPath](https://pkg.go.dev/k8s.io/[email protected]/util/jsonpath) library to parse the Terraform output and extract the desired attribute. The RunTests call is a helper function that runs through each test in the map and perform the supplied assertions. See the [helpers](../../test/helpers) package for more information on the common helper functions.
23
23
24
24
```go
25
-
// Function containing all unit tests for the Storage type
26
-
// and its default values.
27
-
funcTestPlanStorageDefaults(t *testing.T) {
28
-
// Map containing the different tests. Each entry is
To create a unit test, you can add an entry to an existing test table in the [default_unit_test.go](../../test/default_unit_test.go) file or the [non_default_unit_test.go](../../test/non_default_unit_test.go) file, depending on the test type. If you don't see an existing test table that fits your needs, you are welcome to create a new function in a similar table-driven test format.
58
+
To create a unit test, you can add an entry to an existing test table if it's related to the resources being validated. If you don't see an existing test table that fits your needs, you are welcome to create a new file in a similar table-driven test format and drop it in the appropriate package.
0 commit comments