Commit a13eded
committed
helper/resource: introduce testOutcome type
In the plugin test framework, the core test step logic can indicate
error in two different ways:
- Return an `error` to the plugin test framework. This is the plugin
test framework's facility for test authors to make positive or
negative assertions for their provider's behavior. The test author
supplies a `TestStep.ExpectError` to match on the error.
- Call the Go testing library's `t.Fatal`. This is a lower-level error
that a test author cannot make assertions on.
Core test step logic -- such as `ImportState` -- does both of these. The
reason for using one or the other can be subtle and implicit. This
poses a cognitive hurdle for contributing code changes. It also poses a
hurdle to refactoring and breaking down large functions into smaller
ones: does every smaller function need a `testing.T` parameter so that
it can call `t.Fatal`?
This change separates concerns by introducing a type to embed the first
type of error in a result object: framework: `testOutcome`.
Smaller functions can return two values: `testOutcome` and `error`, with
the latter indicating a fatal error.
A test step's entry point -- such as `testStepNewImportState` -- is the
one place that knows that an `error` translates to `t.Fatalf` and a
failed `testOutcome` is simply returned to the plugin test framework.1 parent c4be868 commit a13eded
1 file changed
+46
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
28 | 48 | | |
29 | 49 | | |
30 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
31 | 68 | | |
32 | 69 | | |
33 | 70 | | |
34 | 71 | | |
35 | 72 | | |
36 | 73 | | |
37 | 74 | | |
38 | | - | |
| 75 | + | |
39 | 76 | | |
40 | 77 | | |
41 | 78 | | |
| |||
172 | 209 | | |
173 | 210 | | |
174 | 211 | | |
175 | | - | |
| 212 | + | |
176 | 213 | | |
177 | 214 | | |
178 | 215 | | |
| |||
182 | 219 | | |
183 | 220 | | |
184 | 221 | | |
185 | | - | |
| 222 | + | |
186 | 223 | | |
187 | 224 | | |
188 | 225 | | |
| |||
204 | 241 | | |
205 | 242 | | |
206 | 243 | | |
207 | | - | |
| 244 | + | |
208 | 245 | | |
209 | 246 | | |
210 | | - | |
| 247 | + | |
211 | 248 | | |
212 | 249 | | |
213 | 250 | | |
| |||
217 | 254 | | |
218 | 255 | | |
219 | 256 | | |
220 | | - | |
| 257 | + | |
221 | 258 | | |
222 | 259 | | |
223 | 260 | | |
224 | 261 | | |
225 | 262 | | |
226 | 263 | | |
227 | | - | |
| 264 | + | |
228 | 265 | | |
229 | 266 | | |
230 | 267 | | |
| |||
380 | 417 | | |
381 | 418 | | |
382 | 419 | | |
383 | | - | |
| 420 | + | |
384 | 421 | | |
385 | 422 | | |
386 | 423 | | |
387 | 424 | | |
388 | 425 | | |
389 | | - | |
| 426 | + | |
390 | 427 | | |
391 | 428 | | |
392 | 429 | | |
| |||
0 commit comments