Skip to content

Commit

Permalink
testing: Add SkipTestOnError to test steps
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed Sep 25, 2020
1 parent 35d7fcb commit da9abaf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions helper/resource/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,11 @@ type TestStep struct {
// This is useful for defining test steps with platform-dependent checks
SkipFunc func() (bool, error)

// SkipTestOnError allows the construction of tests that we want to skip if
// they fail with an error. The specified regexp must match against the
// error for the test to skip.
SkipTestOnError *regexp.Regexp

//---------------------------------------------------------------
// ImportState testing
//---------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions helper/resource/testing_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func runNewTest(t testing.T, c TestCase, helper *tftest.Helper) {
if !step.ExpectError.MatchString(err.Error()) {
t.Fatalf("Step %d/%d error running import, expected an error with pattern (%s), no match on: %s", i+1, len(c.Steps), step.ExpectError.String(), err)
}
} else if step.SkipTestOnError != nil && err != nil && step.SkipTestOnError.MatchString(err.Error()) {
t.Skipf("[WARN] Skipping test, step %d/%d error running import matched pattern (%s): %s", i+1, len(c.Steps), step.SkipTestOnError.String(), err)
} else {
if err != nil {
t.Fatalf("Step %d/%d error running import: %s", i+1, len(c.Steps), err)
Expand All @@ -133,6 +135,8 @@ func runNewTest(t testing.T, c TestCase, helper *tftest.Helper) {
if !step.ExpectError.MatchString(err.Error()) {
t.Fatalf("Step %d/%d, expected an error with pattern, no match on: %s", i+1, len(c.Steps), err)
}
} else if step.SkipTestOnError != nil && err != nil && step.SkipTestOnError.MatchString(err.Error()) {
t.Skipf("[WARN] Skipping test, step %d/%d error matched pattern (%s): %s", i+1, len(c.Steps), step.SkipTestOnError.String(), err)
} else {
if err != nil {
t.Fatalf("Step %d/%d error: %s", i+1, len(c.Steps), err)
Expand Down

0 comments on commit da9abaf

Please sign in to comment.