Skip to content

Commit 42eb444

Browse files
appilonkmoe
authored andcommitted
add to TestT interface to be compatible with interface found
in terraform-plugin-test, unexposing testing package
1 parent 6962faf commit 42eb444

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

helper/resource/testing.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ func Test(t TestT, c TestCase) {
576576
t.Fatal("Please configure the acctest binary driver")
577577
}
578578

579-
RunNewTest(t.(*testing.T), c, providers)
579+
RunNewTest(t, c, providers)
580580
}
581581

582582
// testProviderConfig takes the list of Providers in a TestCase and returns a
@@ -985,10 +985,15 @@ func TestMatchOutput(name string, r *regexp.Regexp) TestCheckFunc {
985985
// Users should just use a *testing.T object, which implements this.
986986
type TestT interface {
987987
Error(args ...interface{})
988+
FailNow()
988989
Fatal(args ...interface{})
989-
Skip(args ...interface{})
990+
Fatalf(format string, args ...interface{})
991+
Helper()
992+
Log(args ...interface{})
990993
Name() string
991994
Parallel()
995+
Skip(args ...interface{})
996+
SkipNow()
992997
}
993998

994999
// modulePrimaryInstanceState returns the instance state for the given resource

helper/resource/testing_new.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"log"
66
"reflect"
77
"strings"
8-
"testing"
98

109
"github.com/davecgh/go-spew/spew"
1110
tfjson "github.com/hashicorp/terraform-json"
@@ -16,7 +15,7 @@ import (
1615
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1716
)
1817

19-
func runPostTestDestroy(t *testing.T, c TestCase, wd *tftest.WorkingDir) error {
18+
func runPostTestDestroy(t TestT, c TestCase, wd *tftest.WorkingDir) error {
2019
wd.RequireDestroy(t)
2120

2221
if c.CheckDestroy != nil {
@@ -30,7 +29,7 @@ func runPostTestDestroy(t *testing.T, c TestCase, wd *tftest.WorkingDir) error {
3029
return nil
3130
}
3231

33-
func RunNewTest(t *testing.T, c TestCase, providers map[string]*schema.Provider) {
32+
func RunNewTest(t TestT, c TestCase, providers map[string]*schema.Provider) {
3433
spewConf := spew.NewDefaultConfig()
3534
spewConf.SortKeys = true
3635
wd := acctest.TestHelper.RequireNewWorkingDir(t)
@@ -102,7 +101,7 @@ func RunNewTest(t *testing.T, c TestCase, providers map[string]*schema.Provider)
102101
}
103102
}
104103

105-
func getState(t *testing.T, wd *tftest.WorkingDir) *terraform.State {
104+
func getState(t TestT, wd *tftest.WorkingDir) *terraform.State {
106105
jsonState := wd.RequireState(t)
107106
state, err := shimStateFromJson(jsonState)
108107
if err != nil {
@@ -132,7 +131,7 @@ func planIsEmpty(plan *tfjson.Plan) bool {
132131
return true
133132
}
134133

135-
func testIDRefresh(c TestCase, t *testing.T, wd *tftest.WorkingDir, step TestStep, r *terraform.ResourceState) error {
134+
func testIDRefresh(c TestCase, t TestT, wd *tftest.WorkingDir, step TestStep, r *terraform.ResourceState) error {
136135
spewConf := spew.NewDefaultConfig()
137136
spewConf.SortKeys = true
138137

helper/resource/testing_new_config.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package resource
22

33
import (
4-
"testing"
5-
64
"github.com/davecgh/go-spew/spew"
75
tftest "github.com/hashicorp/terraform-plugin-test"
86

97
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
108
)
119

12-
func testStepNewConfig(t *testing.T, c TestCase, wd *tftest.WorkingDir, step TestStep) error {
10+
func testStepNewConfig(t TestT, c TestCase, wd *tftest.WorkingDir, step TestStep) error {
1311
spewConf := spew.NewDefaultConfig()
1412
spewConf.SortKeys = true
1513

helper/resource/testing_new_import_state.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package resource
33
import (
44
"reflect"
55
"strings"
6-
"testing"
76

87
"github.com/davecgh/go-spew/spew"
98
tftest "github.com/hashicorp/terraform-plugin-test"
@@ -14,7 +13,7 @@ import (
1413
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1514
)
1615

17-
func testStepNewImportState(t *testing.T, c TestCase, wd *tftest.WorkingDir, step TestStep, cfg string) error {
16+
func testStepNewImportState(t TestT, c TestCase, wd *tftest.WorkingDir, step TestStep, cfg string) error {
1817
spewConf := spew.NewDefaultConfig()
1918
spewConf.SortKeys = true
2019

helper/resource/testing_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ func (t *mockT) Error(args ...interface{}) {
173173
t.f = true
174174
}
175175

176+
func (t *mockT) FailNow() {
177+
panic("mockT.FailNow")
178+
}
179+
176180
func (t *mockT) Fatal(args ...interface{}) {
177181
t.FatalCalled = true
178182
t.FatalArgs = args
@@ -181,6 +185,14 @@ func (t *mockT) Fatal(args ...interface{}) {
181185
panic("mockT.Fatal")
182186
}
183187

188+
func (t *mockT) Fatalf(format string, args ...interface{}) {
189+
t.Fatal(format, args)
190+
}
191+
192+
func (t *mockT) Helper() {}
193+
194+
func (t *mockT) Log(args ...interface{}) {}
195+
184196
func (t *mockT) Parallel() {
185197
t.ParallelCalled = true
186198
}
@@ -191,6 +203,10 @@ func (t *mockT) Skip(args ...interface{}) {
191203
t.f = true
192204
}
193205

206+
func (t *mockT) SkipNow() {
207+
t.Skip()
208+
}
209+
194210
func (t *mockT) Name() string {
195211
return "MockedName"
196212
}

0 commit comments

Comments
 (0)