Skip to content

Commit

Permalink
Rework as ErrorCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver authored and kmoe committed Nov 4, 2020
1 parent be14669 commit 68adfd1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 110 deletions.
32 changes: 0 additions & 32 deletions helper/acctest/skip_on_error.go

This file was deleted.

67 changes: 0 additions & 67 deletions helper/acctest/skip_on_error_test.go

This file was deleted.

12 changes: 5 additions & 7 deletions helper/resource/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,8 @@ type ImportStateCheckFunc func([]*terraform.InstanceState) error
// generation for ImportState tests.
type ImportStateIdFunc func(*terraform.State) (string, error)

// SkipOnErrorFunc is a function to determine whether an error should cause a
// test to be skipped.
type SkipOnErrorFunc func(error) bool
// ErrorCheckFunc is a function providers can use to handle errors.
type ErrorCheckFunc func(error) error

// TestCase is a single acceptance test case used to test the apply/destroy
// lifecycle of a resource in a specific configuration.
Expand Down Expand Up @@ -327,10 +326,9 @@ type TestCase struct {
// to allow the tester to test that the resource is truly gone.
CheckDestroy TestCheckFunc

// SkipOnError allows the construction of tests that we want to skip if
// they fail with particular errors. The error is passed to a function that
// determines whether to skip the test.
SkipOnError SkipOnErrorFunc
// ErrorCheck allows providers the option to handle errors such as skipping
// tests based on certain errors.
ErrorCheck ErrorCheckFunc

// Steps are the apply sequences done within the context of the
// same state. Each step can have its own check to verify correctness.
Expand Down
10 changes: 6 additions & 4 deletions helper/resource/testing_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ func runNewTest(t testing.T, c TestCase, helper *plugintest.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 err != nil && c.SkipOnError != nil && c.SkipOnError(err) {
t.Skipf("[WARN] Skipping test, step %d/%d error passed SkipOnError: %s", i+1, len(c.Steps), err)
} else {
if c.ErrorCheck != nil {
err = c.ErrorCheck(err)
}
if err != nil {
t.Fatalf("Step %d/%d error running import: %s", i+1, len(c.Steps), err)
}
Expand All @@ -132,9 +133,10 @@ func runNewTest(t testing.T, c TestCase, helper *plugintest.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 err != nil && c.SkipOnError != nil && c.SkipOnError(err) {
t.Skipf("[WARN] Skipping test, step %d/%d error passed SkipOnError: %s", i+1, len(c.Steps), err)
} else {
if c.ErrorCheck != nil {
err = c.ErrorCheck(err)
}
if err != nil {
t.Fatalf("Step %d/%d error: %s", i+1, len(c.Steps), err)
}
Expand Down

0 comments on commit 68adfd1

Please sign in to comment.