Skip to content

Commit a19f315

Browse files
committed
Refactor tfversion to testingiface
1 parent 4b45ede commit a19f315

File tree

14 files changed

+271
-250
lines changed

14 files changed

+271
-250
lines changed

helper/resource/testing.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515
"strings"
1616
"time"
1717

18-
"github.com/mitchellh/go-testing-interface"
19-
2018
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
2119
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
2220

@@ -31,6 +29,7 @@ import (
3129
"github.com/hashicorp/terraform-plugin-testing/internal/addrs"
3230
"github.com/hashicorp/terraform-plugin-testing/internal/logging"
3331
"github.com/hashicorp/terraform-plugin-testing/internal/plugintest"
32+
testing "github.com/hashicorp/terraform-plugin-testing/internal/testingiface"
3433
)
3534

3635
// flagSweep is a flag available when running tests on the command line. It

internal/logging/context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/hashicorp/terraform-plugin-log/tfsdklog"
1010
helperlogging "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
11-
testing "github.com/mitchellh/go-testing-interface"
11+
"github.com/hashicorp/terraform-plugin-testing/internal/testingiface"
1212
)
1313

1414
// InitContext creates SDK logger contexts when the provider is running in
@@ -34,7 +34,7 @@ func InitContext(ctx context.Context) context.Context {
3434
// The standard library log package handling is important as provider code
3535
// under test may be using that package or another logging library outside of
3636
// terraform-plugin-log.
37-
func InitTestContext(ctx context.Context, t testing.T) context.Context {
37+
func InitTestContext(ctx context.Context, t testingiface.T) context.Context {
3838
helperlogging.SetOutput(t)
3939

4040
ctx = tfsdklog.RegisterTestSink(ctx, t)

internal/plugintest/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func CopyDir(src, dest, baseDirName string) error {
151151
//
152152
// Since we do not want the wrapping test to fail when an expected test error
153153
// occurs, it is required that the testLogic passed in uses
154-
// github.com/mitchellh/go-testing-interface.RuntimeT instead of the real
154+
// github.com/mitchellh/go-testing-interface.RuntimeT instead of the real **
155155
// *testing.T.
156156
//
157157
// If Fatal() or Fatalf() is not called in the logic, the real (*testing.T).Fatal() will

tfversion/all_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import (
88

99
"github.com/hashicorp/go-version"
1010
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
11-
testinginterface "github.com/mitchellh/go-testing-interface"
1211

1312
r "github.com/hashicorp/terraform-plugin-testing/helper/resource"
14-
"github.com/hashicorp/terraform-plugin-testing/internal/plugintest"
1513
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider"
1614
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver"
15+
"github.com/hashicorp/terraform-plugin-testing/internal/testingiface"
1716
"github.com/hashicorp/terraform-plugin-testing/tfversion"
1817
)
1918

@@ -80,8 +79,8 @@ func Test_All_Error(t *testing.T) { //nolint:paralleltest
8079
t.Setenv("TF_ACC_TERRAFORM_PATH", "")
8180
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0")
8281

83-
plugintest.TestExpectTFatal(t, func() {
84-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
82+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
83+
r.UnitTest(mockT, r.TestCase{
8584
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
8685
"test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature
8786
return nil, nil

tfversion/any_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import (
88

99
"github.com/hashicorp/go-version"
1010
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
11-
testinginterface "github.com/mitchellh/go-testing-interface"
11+
"github.com/hashicorp/terraform-plugin-testing/internal/testingiface"
1212

1313
r "github.com/hashicorp/terraform-plugin-testing/helper/resource"
14-
"github.com/hashicorp/terraform-plugin-testing/internal/plugintest"
1514
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider"
1615
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver"
1716
"github.com/hashicorp/terraform-plugin-testing/tfversion"
@@ -73,8 +72,8 @@ func Test_Any_Error(t *testing.T) { //nolint:paralleltest
7372
t.Setenv("TF_ACC_TERRAFORM_PATH", "")
7473
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0")
7574

76-
plugintest.TestExpectTFatal(t, func() {
77-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
75+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
76+
r.UnitTest(mockT, r.TestCase{
7877
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
7978
"test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature
8079
return nil, nil

tfversion/require_above_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ import (
1010
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
1111

1212
r "github.com/hashicorp/terraform-plugin-testing/helper/resource"
13-
"github.com/hashicorp/terraform-plugin-testing/internal/plugintest"
1413
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider"
1514
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver"
1615
"github.com/hashicorp/terraform-plugin-testing/tfversion"
1716

18-
testinginterface "github.com/mitchellh/go-testing-interface"
17+
"github.com/hashicorp/terraform-plugin-testing/internal/testingiface"
1918
)
2019

2120
func Test_RequireAbove_Equal(t *testing.T) { //nolint:paralleltest
@@ -68,8 +67,8 @@ func Test_RequireAbove_Lower(t *testing.T) { //nolint:paralleltest
6867
t.Setenv("TF_ACC_TERRAFORM_PATH", "")
6968
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.0.7")
7069

71-
plugintest.TestExpectTFatal(t, func() {
72-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
70+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
71+
r.UnitTest(mockT, r.TestCase{
7372
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
7473
"test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature
7574
return nil, nil
@@ -139,8 +138,8 @@ func Test_RequireAbove_Prerelease_HigherCoreVersion(t *testing.T) { //nolint:par
139138
// 1.8.0 core version. This intentionally verifies that the logic does not
140139
// ignore the core version of the prerelease version when compared against
141140
// the core version of the check.
142-
plugintest.TestExpectTFatal(t, func() {
143-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
141+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
142+
r.UnitTest(mockT, r.TestCase{
144143
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
145144
"test": providerserver.NewProviderServer(testprovider.Provider{}),
146145
},
@@ -162,8 +161,8 @@ func Test_RequireAbove_Prerelease_HigherPrerelease(t *testing.T) { //nolint:para
162161

163162
// The 1.7.0-rc1 prerelease should always be considered to be
164163
// below the 1.7.0-rc2 prerelease.
165-
plugintest.TestExpectTFatal(t, func() {
166-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
164+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
165+
r.UnitTest(mockT, r.TestCase{
167166
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
168167
"test": providerserver.NewProviderServer(testprovider.Provider{}),
169168
},

tfversion/require_below_test.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ import (
1010
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
1111

1212
r "github.com/hashicorp/terraform-plugin-testing/helper/resource"
13-
"github.com/hashicorp/terraform-plugin-testing/internal/plugintest"
1413
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider"
1514
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver"
1615
"github.com/hashicorp/terraform-plugin-testing/tfversion"
1716

18-
testinginterface "github.com/mitchellh/go-testing-interface"
17+
"github.com/hashicorp/terraform-plugin-testing/internal/testingiface"
1918
)
2019

2120
func Test_RequireBelow_Equal(t *testing.T) { //nolint:paralleltest
2221
t.Setenv("TF_ACC_TERRAFORM_PATH", "")
2322
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.7.0")
2423

25-
plugintest.TestExpectTFatal(t, func() {
26-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
24+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
25+
r.UnitTest(mockT, r.TestCase{
2726
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
2827
"test": providerserver.NewProviderServer(testprovider.Provider{}),
2928
},
@@ -69,8 +68,8 @@ func Test_RequireBelow_Higher(t *testing.T) { //nolint:paralleltest
6968
t.Setenv("TF_ACC_TERRAFORM_PATH", "")
7069
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.4.0")
7170

72-
plugintest.TestExpectTFatal(t, func() {
73-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
71+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
72+
r.UnitTest(mockT, r.TestCase{
7473
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
7574
"test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature
7675
return nil, nil
@@ -98,8 +97,8 @@ func Test_RequireBelow_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:para
9897
// core versions.
9998
//
10099
// Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303
101-
plugintest.TestExpectTFatal(t, func() {
102-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
100+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
101+
r.UnitTest(mockT, r.TestCase{
103102
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
104103
"test": providerserver.NewProviderServer(testprovider.Provider{}),
105104
},
@@ -165,8 +164,8 @@ func Test_RequireBelow_Prerelease_LowerCoreVersion(t *testing.T) { //nolint:para
165164

166165
// The 1.8.0-rc1 prerelease should always be considered to be
167166
// above the 1.7.0 core version.
168-
plugintest.TestExpectTFatal(t, func() {
169-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
167+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
168+
r.UnitTest(mockT, r.TestCase{
170169
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
171170
"test": providerserver.NewProviderServer(testprovider.Provider{}),
172171
},
@@ -188,8 +187,8 @@ func Test_RequireBelow_Prerelease_LowerPrerelease(t *testing.T) { //nolint:paral
188187

189188
// The 1.8.0-rc1 prerelease should always be considered to be
190189
// above the 1.8.0-beta1 prerelease.
191-
plugintest.TestExpectTFatal(t, func() {
192-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
190+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
191+
r.UnitTest(mockT, r.TestCase{
193192
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
194193
"test": providerserver.NewProviderServer(testprovider.Provider{}),
195194
},

tfversion/require_between_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ import (
1010
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
1111

1212
r "github.com/hashicorp/terraform-plugin-testing/helper/resource"
13-
"github.com/hashicorp/terraform-plugin-testing/internal/plugintest"
1413
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider"
1514
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver"
1615
"github.com/hashicorp/terraform-plugin-testing/tfversion"
1716

18-
testinginterface "github.com/mitchellh/go-testing-interface"
17+
"github.com/hashicorp/terraform-plugin-testing/internal/testingiface"
1918
)
2019

2120
func Test_RequireBetween(t *testing.T) { //nolint:paralleltest
@@ -60,8 +59,8 @@ func Test_RequireBetween_Error_BelowMin(t *testing.T) { //nolint:paralleltest
6059
t.Setenv("TF_ACC_TERRAFORM_PATH", "")
6160
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0")
6261

63-
plugintest.TestExpectTFatal(t, func() {
64-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
62+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
63+
r.UnitTest(mockT, r.TestCase{
6564
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
6665
"test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature
6766
return nil, nil
@@ -82,8 +81,8 @@ func Test_RequireBetween_Error_BelowMin(t *testing.T) { //nolint:paralleltest
8281
func Test_RequireBetween_Error_EqToMax(t *testing.T) { //nolint:paralleltest
8382
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.3.0")
8483

85-
plugintest.TestExpectTFatal(t, func() {
86-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
84+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
85+
r.UnitTest(mockT, r.TestCase{
8786
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
8887
"test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature
8988
return nil, nil
@@ -111,8 +110,8 @@ func Test_RequireBetween_Prerelease_MaxEqualCoreVersion(t *testing.T) { //nolint
111110
// core versions.
112111
//
113112
// Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303
114-
plugintest.TestExpectTFatal(t, func() {
115-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
113+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
114+
r.UnitTest(mockT, r.TestCase{
116115
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
117116
"test": providerserver.NewProviderServer(testprovider.Provider{}),
118117
},
@@ -184,8 +183,8 @@ func Test_RequireBetween_Prerelease_MinHigherCoreVersion(t *testing.T) { //nolin
184183
// 1.8.0 core version. This intentionally verifies that the logic does not
185184
// ignore the core version of the prerelease version when compared against
186185
// the core version of the check.
187-
plugintest.TestExpectTFatal(t, func() {
188-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
186+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
187+
r.UnitTest(mockT, r.TestCase{
189188
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
190189
"test": providerserver.NewProviderServer(testprovider.Provider{}),
191190
},
@@ -228,8 +227,8 @@ func Test_RequireBetween_Prerelease_MinHigherPrerelease(t *testing.T) { //nolint
228227

229228
// The 1.7.0-rc1 prerelease should always be considered to be
230229
// below the 1.7.0-rc2 prerelease.
231-
plugintest.TestExpectTFatal(t, func() {
232-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
230+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
231+
r.UnitTest(mockT, r.TestCase{
233232
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
234233
"test": providerserver.NewProviderServer(testprovider.Provider{}),
235234
},
@@ -251,8 +250,8 @@ func Test_RequireBetween_Prerelease_MaxLowerCoreVersion(t *testing.T) { //nolint
251250

252251
// The 1.8.0-rc1 prerelease should always be considered to be
253252
// above the 1.7.0 core version.
254-
plugintest.TestExpectTFatal(t, func() {
255-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
253+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
254+
r.UnitTest(mockT, r.TestCase{
256255
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
257256
"test": providerserver.NewProviderServer(testprovider.Provider{}),
258257
},
@@ -295,8 +294,8 @@ func Test_RequireBetween_Prerelease_MaxLowerPrerelease(t *testing.T) { //nolint:
295294

296295
// The 1.8.0-rc1 prerelease should always be considered to be
297296
// above the 1.8.0-beta1 prerelease.
298-
plugintest.TestExpectTFatal(t, func() {
299-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
297+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
298+
r.UnitTest(mockT, r.TestCase{
300299
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
301300
"test": providerserver.NewProviderServer(testprovider.Provider{}),
302301
},

tfversion/require_not_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import (
88

99
"github.com/hashicorp/go-version"
1010
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
11+
"github.com/hashicorp/terraform-plugin-testing/internal/testingiface"
1112

1213
r "github.com/hashicorp/terraform-plugin-testing/helper/resource"
13-
"github.com/hashicorp/terraform-plugin-testing/internal/plugintest"
1414
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider"
1515
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver"
1616
"github.com/hashicorp/terraform-plugin-testing/tfversion"
17-
18-
testinginterface "github.com/mitchellh/go-testing-interface"
1917
)
2018

2119
func Test_RequireNot(t *testing.T) { //nolint:paralleltest
@@ -41,8 +39,8 @@ func Test_RequireNot_Error(t *testing.T) { //nolint:paralleltest
4139
t.Setenv("TF_ACC_TERRAFORM_PATH", "")
4240
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0")
4341

44-
plugintest.TestExpectTFatal(t, func() {
45-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
42+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
43+
r.UnitTest(mockT, r.TestCase{
4644
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
4745
"test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature
4846
return nil, nil
@@ -70,8 +68,8 @@ func Test_RequireNot_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:parall
7068
// core versions.
7169
//
7270
// Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303
73-
plugintest.TestExpectTFatal(t, func() {
74-
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{
71+
testingiface.ExpectFail(t, func(mockT *testingiface.MockT) {
72+
r.UnitTest(mockT, r.TestCase{
7573
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
7674
"test": providerserver.NewProviderServer(testprovider.Provider{}),
7775
},

0 commit comments

Comments
 (0)