Skip to content

Commit

Permalink
helper/resource: Add (testing.T).Logf() call and augment documentatio…
Browse files Browse the repository at this point in the history
…n for TestStep.SkipFunc (#889)

Reference: #824
Reference: https://pkg.go.dev/testing#T.Logf

The additional logging will be more visible, as it will appear in stdout instead of disabled by default.

The documentation updates should make the purpose and correct usage of this field more clear.
  • Loading branch information
bflad committed Feb 18, 2022
1 parent 6de4ff0 commit ca3e3ba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/889.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
helper/resource: Added more visible logging for test steps skipped via the `TestStep` type `SkipFunc` field.
```
11 changes: 9 additions & 2 deletions helper/resource/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,15 @@ type TestStep struct {
// are tested alongside real resources
PreventPostDestroyRefresh bool

// SkipFunc is called before applying config, but after PreConfig
// This is useful for defining test steps with platform-dependent checks
// SkipFunc enables skipping the TestStep, based on environment criteria.
// For example, this can prevent running certain steps that may be runtime
// platform or API configuration dependent.
//
// Return true with no error to skip the test step. The error return
// should be used to signify issues that prevented the function from
// completing as expected.
//
// SkipFunc is called after PreConfig but before applying the Config.
SkipFunc func() (bool, error)

//---------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion helper/resource/testing_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func runNewTest(t testing.T, c TestCase, helper *plugintest.Helper) {
t.Fatal(err)
}
if skip {
log.Printf("[WARN] Skipping step %d/%d", i+1, len(c.Steps))
t.Logf("Skipping step %d/%d due to SkipFunc", i+1, len(c.Steps))
log.Printf("[WARN] Skipping step %d/%d due to SkipFunc", i+1, len(c.Steps))
continue
}
}
Expand Down

0 comments on commit ca3e3ba

Please sign in to comment.