Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper/resource: Add (testing.T).Logf() call and augment documentation for TestStep.SkipFunc #889

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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