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
In the above example each `TestCase` invokes a function to retrieve it’s desired
82
+
In the above example each `TestCase` invokes a function to retrieve it's desired
83
83
configuration, based on a randomized name provided, however an in-line string or
84
84
constant string would work as well, so long as they contain valid Terraform
85
85
configuration for the plugin or resource under test. This pattern of first
86
86
applying and checking a basic configuration, followed by applying a modified
87
87
configuration with updated or additional checks is a common pattern used to test
88
88
update functionality.
89
89
90
-
## State Check Functions
90
+
## Plan Checks
91
+
Before and after the configuration for a `TestStep` is applied, Terraform's testing framework provides developers an opportunity to make test assertions against `terraform plan` results via the plan file. This is provided via [Plan Checks](/terraform/plugin/testing/acceptance-tests/plan-checks), which provide both built-in plan checks and an interface to implement custom plan checks.
92
+
93
+
## State Checks
94
+
95
+
After the configuration for a `TestStep` is applied, Terraform's testing
96
+
framework provides developers an opportunity to check the results by providing one
97
+
or more [state check implementations](/terraform/plugin/testing/acceptance-tests/state-checks).
98
+
While possible to only supply a single state check, it is recommended you use multiple state checks
99
+
to validate specific information about the results of the `terraform apply` ran in each `TestStep`.
91
100
92
-
After the configuration for a `TestStep` is applied, Terraform’s testing
93
-
framework provides developers an opportunity to check the results by providing a
94
-
“Check” function. While possible to only supply a single function, it is
95
-
recommended you use multiple functions to validate specific information about
96
-
the results of the `terraform apply` ran in each `TestStep`. The `Check`
101
+
See the [State Checks](/terraform/plugin/testing/acceptance-tests/state-checks) section for more information about the built-in state checks for resources, data sources,
102
+
output values, and how to write custom state checks.
103
+
104
+
### Legacy Check function
105
+
106
+
<Note>
107
+
108
+
Use the new `ConfigStateChecks` attribute and [State Check implementations](/terraform/plugin/testing/acceptance-tests/state-checks)
109
+
instead of the `Check` function.
110
+
111
+
</Note>
112
+
113
+
The `Check` function is used to check results of a Terraform operation. The `Check`
97
114
attribute of `TestStep` is singular, so in order to include multiple checks
98
115
developers should use either `ComposeTestCheckFunc` or
99
116
`ComposeAggregateTestCheckFunc` (defined below) to group multiple check
100
117
functions, defined below:
101
118
102
-
### ComposeTestCheckFunc
119
+
####ComposeTestCheckFunc
103
120
104
121
ComposeTestCheckFunc lets you compose multiple TestCheckFunc functions into a
105
122
single check. As a user testing their provider, this lets you decompose your
@@ -124,10 +141,10 @@ Steps: []resource.TestStep{
124
141
},
125
142
```
126
143
127
-
### ComposeAggregateTestCheckFunc
144
+
####ComposeAggregateTestCheckFunc
128
145
129
146
ComposeAggregateTestCheckFunc lets you compose multiple TestCheckFunc functions
130
-
into a single check. It’s purpose and usage is identical to
147
+
into a single check. It's purpose and usage is identical to
131
148
ComposeTestCheckFunc, however each check is ran in order even if a previous
132
149
check failed, collecting the errors returned from any checks and returning a
133
150
single aggregate error. The entire `TestCase` is still stopped, and Terraform
@@ -149,7 +166,7 @@ Steps: []resource.TestStep{
149
166
},
150
167
```
151
168
152
-
##Builtin check functions
169
+
#### Built-in check functions
153
170
154
171
Terraform has several TestCheckFunc functions built in for developers to use for
155
172
common checks, such as verifying the status and value of a specific attribute in
@@ -204,7 +221,7 @@ All of these functions also accept the below syntax in attribute keys to enable
204
221
|`.#`| Number of elements in list or set |`TestCheckResourceAttr("example_widget.foo", "some_list.#", "2")`|
205
222
|`.%`| Number of keys in map |`TestCheckResourceAttr("example_widget.foo", "some_map.%", "2")`|
206
223
207
-
## Custom check functions
224
+
###Custom check functions
208
225
209
226
The `Check` field of `TestStep` accepts any function of type
Before and after the configuration for a `TestStep` is applied, Terraform's testing framework provides developers an opportunity to make test assertions against `terraform plan` results via the plan file. This is provided via [Plan Checks](/terraform/plugin/testing/acceptance-tests/plan-checks), which provide both built-in plan checks and an interface to implement custom plan checks.
304
-
305
319
## Sweepers
306
320
307
-
Acceptance Testing is an essential approach to validating the implementation of a Terraform Provider. Using actual APIs to provision resources for testing can leave behind real infrastructure that costs money between tests. The reasons for these leaks can vary, regardless Terraform provides a mechanism known as [Sweepers](/terraform/plugin/testing/acceptance-tests/sweepers) to help keep the testing account clean.
321
+
Acceptance Testing is an essential approach to validating the implementation of a Terraform Provider. Using actual APIs to provision resources for testing can leave behind real infrastructure that costs money between tests. The reasons for these leaks can vary, regardless Terraform provides a mechanism known as [Sweepers](/terraform/plugin/testing/acceptance-tests/sweepers) to help keep the testing account clean.
0 commit comments