From 4b45edeac1b93596b3cf1cef1d86a0ac99a2d412 Mon Sep 17 00:00:00 2001 From: Baraa Basata Date: Wed, 18 Dec 2024 19:28:48 -0500 Subject: [PATCH 1/6] Add testingiface package --- internal/testingiface/doc.go | 28 +++++ internal/testingiface/expect.go | 143 ++++++++++++++++++++++++ internal/testingiface/expect_test.go | 102 ++++++++++++++++++ internal/testingiface/mockt.go | 156 +++++++++++++++++++++++++++ internal/testingiface/t.go | 47 ++++++++ 5 files changed, 476 insertions(+) create mode 100644 internal/testingiface/doc.go create mode 100644 internal/testingiface/expect.go create mode 100644 internal/testingiface/expect_test.go create mode 100644 internal/testingiface/mockt.go create mode 100644 internal/testingiface/t.go diff --git a/internal/testingiface/doc.go b/internal/testingiface/doc.go new file mode 100644 index 000000000..8ff499708 --- /dev/null +++ b/internal/testingiface/doc.go @@ -0,0 +1,28 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// Package testingiface provides wrapper types compatible with the Go standard +// library [testing] package. These wrappers are necessary for implementing +// [testing] package helpers, since the Go standard library implementation is +// not extensible and the existing code in this Go module is built on directly +// interacting with [testing] functionality, such as calling [testing.T.Fatal]. +// +// The [T] interface has all methods of the [testing.T] type and the [MockT] +// type is a lightweight mock implementation of the [T] interface. There are a +// collection of assertion helper functions such as: +// - [ExpectFail]: That the test logic called the equivalent of +// [testing.T.Error] or [testing.T.Fatal]. +// - [ExpectParallel]: That the test logic called the equivalent of +// [testing.T.Parallel] and passed. +// - [ExpectPass]: That the test logic did not call the equivalent of +// [testing.T.Skip], since [testing] marks these tests as passing. +// - [ExpectSkip]: That the test logic called the equivalent of +// [testing.T.Skip]. +// +// This code in this package is intentionally internal and should not be exposed +// in the Go module API. It is compatible with the Go 1.17 [testing] package. +// It replaces the archived github.com/mitchellh/go-testing-interface Go module, +// but is implemented with different approaches that enable calls to behave +// more closely to the Go standard library, such as calling [runtime.Goexit] +// when skipping, and preserving any error/skip messaging. +package testingiface diff --git a/internal/testingiface/expect.go b/internal/testingiface/expect.go new file mode 100644 index 000000000..66aa66a54 --- /dev/null +++ b/internal/testingiface/expect.go @@ -0,0 +1,143 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package testingiface + +import ( + "sync" +) + +// ExpectFailed provides a wrapper for test logic which should call any of the +// following: +// - [testing.T.Error] +// - [testing.T.Errorf] +// - [testing.T.Fatal] +// - [testing.T.Fatalf] +// +// If none of those were called, the real [testing.T.Fatal] is called to fail +// the test. +func ExpectFail(t T, logic func(*MockT)) { + t.Helper() + + mockT := &MockT{} + + var wg sync.WaitGroup + wg.Add(1) + + go func() { + defer wg.Done() + + logic(mockT) + }() + + wg.Wait() + + if mockT.Failed() { + return + } + + t.Fatal("expected test failure") +} + +// ExpectParallel provides a wrapper for test logic which should call the +// [testing.T.Parallel] method. If it doesn't, the real [testing.T.Fatal] is +// called. +func ExpectParallel(t T, logic func(*MockT)) { + t.Helper() + + mockT := &MockT{} + + var wg sync.WaitGroup + wg.Add(1) + + go func() { + defer wg.Done() + + logic(mockT) + }() + + wg.Wait() + + if mockT.Failed() { + t.Fatalf("unexpected test failure: %s", mockT.LastError()) + } + + if mockT.Skipped() { + t.Fatalf("unexpected test skip: %s", mockT.LastSkipped()) + } + + if mockT.IsParallel() { + return + } + + t.Fatal("expected test parallel") +} + +// ExpectPass provides a wrapper for test logic which should not call any of the +// following, which would mark the real test as passing: +// - [testing.T.Skip] +// - [testing.T.Skipf] +// +// If one of those were called, the real [testing.T.Fatal] is called to fail +// the test. This is only necessary to check for false positives with skipped +// tests. +func ExpectPass(t T, logic func(*MockT)) { + t.Helper() + + mockT := &MockT{} + + var wg sync.WaitGroup + wg.Add(1) + + go func() { + defer wg.Done() + + logic(mockT) + }() + + wg.Wait() + + if mockT.Failed() { + t.Fatalf("unexpected test failure: %s", mockT.LastError()) + } + + if mockT.Skipped() { + t.Fatalf("unexpected test skip: %s", mockT.LastSkipped()) + } + + // test passed as expected +} + +// ExpectSkip provides a wrapper for test logic which should call any of the +// following: +// - [testing.T.Skip] +// - [testing.T.Skipf] +// +// If none of those were called, the real [testing.T.Fatal] is called to fail +// the test. +func ExpectSkip(t T, logic func(*MockT)) { + t.Helper() + + mockT := &MockT{} + + var wg sync.WaitGroup + wg.Add(1) + + go func() { + defer wg.Done() + + logic(mockT) + }() + + wg.Wait() + + if mockT.Failed() { + t.Fatalf("unexpected test failure: %s", mockT.LastError()) + } + + if mockT.Skipped() { + return + } + + t.Fatal("test passed, expected test skip") +} diff --git a/internal/testingiface/expect_test.go b/internal/testingiface/expect_test.go new file mode 100644 index 000000000..3f0f3690d --- /dev/null +++ b/internal/testingiface/expect_test.go @@ -0,0 +1,102 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package testingiface_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" +) + +func TestExpectFail(t *testing.T) { + t.Parallel() + + testingiface.ExpectPass(t, func(mockT1 *testingiface.MockT) { + testingiface.ExpectFail(mockT1, func(mockT2 *testingiface.MockT) { + mockT2.Fatal("test fatal") + }) + }) + + testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { + testingiface.ExpectFail(mockT1, func(_ *testingiface.MockT) { + // intentionally no test error or test skip + }) + }) + + testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { + testingiface.ExpectFail(mockT1, func(mockT2 *testingiface.MockT) { + mockT2.Skip("test skip") + }) + }) +} + +func TestExpectParallel(t *testing.T) { + t.Parallel() + + testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { + testingiface.ExpectParallel(mockT1, func(mockT2 *testingiface.MockT) { + mockT2.Fatal("test fatal") + }) + }) + + testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { + testingiface.ExpectParallel(mockT1, func(_ *testingiface.MockT) { + // intentionally no test error or test skip + }) + }) + + testingiface.ExpectPass(t, func(mockT1 *testingiface.MockT) { + testingiface.ExpectParallel(mockT1, func(mockT2 *testingiface.MockT) { + mockT2.Parallel() + }) + }) + + testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { + testingiface.ExpectParallel(mockT1, func(mockT2 *testingiface.MockT) { + mockT2.Skip("test skip") + }) + }) +} + +func TestExpectPass(t *testing.T) { + t.Parallel() + + testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { + testingiface.ExpectPass(mockT1, func(mockT2 *testingiface.MockT) { + mockT2.Fatal("test fatal") + }) + }) + + testingiface.ExpectPass(t, func(_ *testingiface.MockT) { + // intentionally no test error or test skip + }) + + testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { + testingiface.ExpectPass(mockT1, func(mockT2 *testingiface.MockT) { + mockT2.Skip("test skip") + }) + }) +} + +func TestExpectSkip(t *testing.T) { + t.Parallel() + + testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { + testingiface.ExpectSkip(mockT1, func(mockT2 *testingiface.MockT) { + mockT2.Fatal("test fatal") + }) + }) + + testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { + testingiface.ExpectSkip(mockT1, func(_ *testingiface.MockT) { + // intentionally no test error or test skip + }) + }) + + testingiface.ExpectPass(t, func(mockT1 *testingiface.MockT) { + testingiface.ExpectSkip(mockT1, func(mockT2 *testingiface.MockT) { + mockT2.Skip("test skip") + }) + }) +} diff --git a/internal/testingiface/mockt.go b/internal/testingiface/mockt.go new file mode 100644 index 000000000..9800fb237 --- /dev/null +++ b/internal/testingiface/mockt.go @@ -0,0 +1,156 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package testingiface + +import ( + "fmt" + "os" + "runtime" + "testing" + "time" +) + +var _ T = (*MockT)(nil) + +// MockT is a lightweight, mock implementation of the non-extensible Go +// standard library [*testing.T] implementation. This type should only be used +// in the unit testing of functionality within this Go module and never exposed +// in the Go module API. +// +// This type intentionally is not feature-complete and only includes the methods +// necessary for the existing code in this Go module. +type MockT struct { + // TestName can be set to the name of the test, such as calling the real + // [testing.T.Name]. This is returned in the [Name] method. + TestName string + + isHelper bool + isFailed bool + isSkipped bool + isParallel bool + lastError string + lastSkipped string +} + +// T interface implementations + +func (t *MockT) Cleanup(func()) { + panic("not implemented") +} + +func (t *MockT) Deadline() (deadline time.Time, ok bool) { + panic("not implemented") +} + +func (t *MockT) Error(args ...any) { + t.lastError = fmt.Sprintln(args...) + t.Log(args...) + t.Fail() +} + +func (t *MockT) Errorf(format string, args ...any) { + t.lastError = fmt.Sprintf(format, args...) + t.Logf(format, args...) + t.Fail() +} + +func (t *MockT) Fail() { + t.isFailed = true +} + +func (t *MockT) Failed() bool { + return t.isFailed +} + +func (t *MockT) FailNow() { + t.Fail() + runtime.Goexit() +} + +func (t *MockT) Fatal(args ...any) { + t.lastError = fmt.Sprintln(args...) + t.Log(args...) + t.FailNow() +} + +func (t *MockT) Fatalf(format string, args ...any) { + t.lastError = fmt.Sprintf(format, args...) + t.Log(args...) + t.FailNow() +} + +func (t *MockT) Helper() { + t.isHelper = true +} + +func (t *MockT) Log(args ...any) { + if args == nil { + return + } + + fmt.Fprintln(os.Stdout, args...) +} + +func (t *MockT) Logf(format string, args ...any) { + if format == "" { + return + } + + fmt.Fprintf(os.Stdout, format, args...) +} + +func (t *MockT) Name() string { + return t.TestName +} + +func (t *MockT) Parallel() { + t.isParallel = true +} + +func (t *MockT) Run(name string, f func(t *testing.T)) bool { + panic("not implemented") +} + +func (t *MockT) Setenv(key string, value string) { + panic("not implemented") +} + +func (t *MockT) Skip(args ...any) { + t.lastSkipped = fmt.Sprintln(args...) + t.Log(args...) + t.SkipNow() +} + +func (t *MockT) Skipf(format string, args ...any) { + t.lastSkipped = fmt.Sprintf(format, args...) + t.Logf(format, args...) + t.SkipNow() +} + +func (t *MockT) SkipNow() { + t.isSkipped = true + runtime.Goexit() +} + +func (t *MockT) Skipped() bool { + return t.isSkipped +} + +func (t *MockT) TempDir() string { + panic("not implemented") +} + +// Custom methods + +func (t *MockT) IsParallel() bool { + return t.isParallel +} + +func (t *MockT) LastError() string { + return t.lastError +} + +func (t *MockT) LastSkipped() string { + return t.lastSkipped +} diff --git a/internal/testingiface/t.go b/internal/testingiface/t.go new file mode 100644 index 000000000..8858bf3a0 --- /dev/null +++ b/internal/testingiface/t.go @@ -0,0 +1,47 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package testingiface + +// T is the interface that contains all the methods of the Go standard library +// [*testing.T] type as of Go 1.17. +// +// For complete backwards compatibility, it explicitly does not include the +// Deadline and Run methods to match the prior +// github.com/mitchellh/go-testing-interface.T interface. If either of those +// methods are needed, it should be relatively safe to add to this interface +// under the guise that this internal interface should match the [*testing.T] +// implementation. +type T interface { + Cleanup(func()) + + // Excluded to match the prior github.com/mitchellh/go-testing-interface.T + // interface for complete backwards compatibility. It is relatively safe to + // introduce if necessary in the future though. + // Deadline() (deadline time.Time, ok bool) + + Error(args ...any) + Errorf(format string, args ...any) + Fail() + Failed() bool + FailNow() + Fatal(args ...any) + Fatalf(format string, args ...any) + Helper() + Log(args ...any) + Logf(format string, args ...any) + Name() string + Parallel() + + // Excluded to match the prior github.com/mitchellh/go-testing-interface.T + // interface for complete backwards compatibility. It is relatively safe to + // introduce if necessary in the future though. + // Run(name string, f func(*testing.T)) bool + + Setenv(key string, value string) + Skip(args ...any) + Skipf(format string, args ...any) + SkipNow() + Skipped() bool + TempDir() string +} From 27ef1bde948ad185b15e8948a5d36f8560725ca7 Mon Sep 17 00:00:00 2001 From: Baraa Basata Date: Thu, 19 Dec 2024 10:16:41 -0500 Subject: [PATCH 2/6] refactor mockT to testingiface.MockT --- helper/resource/testcase_providers_test.go | 26 ++++++------- helper/resource/testing_test.go | 45 +++++++--------------- helper/resource/teststep_providers_test.go | 23 +++++------ helper/resource/teststep_test.go | 6 +-- helper/resource/tfversion_checks_test.go | 8 ++-- internal/plugintest/util.go | 40 ------------------- tfversion/all_test.go | 7 ++-- tfversion/any_test.go | 7 ++-- tfversion/require_above_test.go | 16 ++++---- tfversion/require_below_test.go | 24 ++++++------ tfversion/require_between_test.go | 32 ++++++++------- tfversion/require_not_test.go | 12 +++--- 12 files changed, 88 insertions(+), 158 deletions(-) diff --git a/helper/resource/testcase_providers_test.go b/helper/resource/testcase_providers_test.go index 45af1c784..9b2159d89 100644 --- a/helper/resource/testcase_providers_test.go +++ b/helper/resource/testcase_providers_test.go @@ -15,9 +15,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) @@ -344,8 +344,8 @@ func TestTest_TestCase_ExternalProvidersAndProviderFactories_NonHashiCorpNamespa func TestTest_TestCase_ExternalProviders_Error(t *testing.T) { t.Parallel() - plugintest.TestExpectTFatal(t, func() { - Test(&mockT{}, TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + Test(mockT, TestCase{ TerraformVersionChecks: []tfversion.TerraformVersionCheck{ tfversion.SkipBelow(tfversion.Version0_13_0), // ExternalProvider.Source }, @@ -366,7 +366,7 @@ func TestTest_TestCase_ExternalProviders_Error(t *testing.T) { func TestTest_TestCase_ProtoV5ProviderFactories(t *testing.T) { t.Parallel() - Test(&mockT{}, TestCase{ + Test(t, TestCase{ ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ "test": providerserver.NewProtov5ProviderServer(testprovider.Protov5Provider{}), }, @@ -381,8 +381,8 @@ func TestTest_TestCase_ProtoV5ProviderFactories(t *testing.T) { func TestTest_TestCase_ProtoV5ProviderFactories_Error(t *testing.T) { t.Parallel() - plugintest.TestExpectTFatal(t, func() { - Test(&mockT{}, TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + Test(mockT, TestCase{ ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ "test": func() (tfprotov5.ProviderServer, error) { //nolint:unparam // required signature return nil, fmt.Errorf("test") @@ -400,7 +400,7 @@ func TestTest_TestCase_ProtoV5ProviderFactories_Error(t *testing.T) { func TestTest_TestCase_ProtoV6ProviderFactories(t *testing.T) { t.Parallel() - Test(&mockT{}, TestCase{ + Test(t, TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -415,8 +415,8 @@ func TestTest_TestCase_ProtoV6ProviderFactories(t *testing.T) { func TestTest_TestCase_ProtoV6ProviderFactories_Error(t *testing.T) { t.Parallel() - plugintest.TestExpectTFatal(t, func() { - Test(&mockT{}, TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + Test(mockT, TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, fmt.Errorf("test") @@ -434,7 +434,7 @@ func TestTest_TestCase_ProtoV6ProviderFactories_Error(t *testing.T) { func TestTest_TestCase_ProviderFactories(t *testing.T) { t.Parallel() - Test(&mockT{}, TestCase{ + Test(t, TestCase{ ProviderFactories: map[string]func() (*schema.Provider, error){ "test": func() (*schema.Provider, error) { //nolint:unparam // required signature return &schema.Provider{}, nil @@ -451,8 +451,8 @@ func TestTest_TestCase_ProviderFactories(t *testing.T) { func TestTest_TestCase_ProviderFactories_Error(t *testing.T) { t.Parallel() - plugintest.TestExpectTFatal(t, func() { - Test(&mockT{}, TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + Test(mockT, TestCase{ ProviderFactories: map[string]func() (*schema.Provider, error){ "test": func() (*schema.Provider, error) { //nolint:unparam // required signature return nil, fmt.Errorf("test") @@ -470,7 +470,7 @@ func TestTest_TestCase_ProviderFactories_Error(t *testing.T) { func TestTest_TestCase_Providers(t *testing.T) { t.Parallel() - Test(&mockT{}, TestCase{ + Test(t, TestCase{ Providers: map[string]*schema.Provider{ "test": {}, }, diff --git a/helper/resource/testing_test.go b/helper/resource/testing_test.go index 00137efc9..56f281cdb 100644 --- a/helper/resource/testing_test.go +++ b/helper/resource/testing_test.go @@ -14,8 +14,8 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - testinginterface "github.com/mitchellh/go-testing-interface" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/terraform" ) @@ -28,25 +28,21 @@ func init() { func TestParallelTest(t *testing.T) { t.Parallel() - mt := new(mockT) - - ParallelTest(mt, TestCase{ - IsUnitTest: true, - ProviderFactories: map[string]func() (*schema.Provider, error){ - "test": func() (*schema.Provider, error) { //nolint:unparam // required signature - return &schema.Provider{}, nil + testingiface.ExpectParallel(t, func(mockT *testingiface.MockT) { + ParallelTest(mockt, TestCase{ + IsUnitTest: true, + ProviderFactories: map[string]func() (*schema.Provider, error){ + "test": func() (*schema.Provider, error) { //nolint:unparam // required signature + return &schema.Provider{}, nil + }, }, - }, - Steps: []TestStep{ - { - Config: "# not empty", + Steps: []TestStep{ + { + Config: "# not empty", + }, }, - }, + }) }) - - if !mt.ParallelCalled { - t.Fatal("Parallel() not called") - } } func TestComposeAggregateTestCheckFunc(t *testing.T) { @@ -131,21 +127,6 @@ func TestComposeTestCheckFunc(t *testing.T) { } } -// mockT implements TestT for testing -type mockT struct { - testinginterface.RuntimeT - - ParallelCalled bool -} - -func (t *mockT) Parallel() { - t.ParallelCalled = true -} - -func (t *mockT) Name() string { - return "MockedName" -} - func TestTest_Main(t *testing.T) { t.Parallel() diff --git a/helper/resource/teststep_providers_test.go b/helper/resource/teststep_providers_test.go index e4d1fd7fb..a929eddaa 100644 --- a/helper/resource/teststep_providers_test.go +++ b/helper/resource/teststep_providers_test.go @@ -29,6 +29,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/resource" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/internal/teststep" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-plugin-testing/tfversion" @@ -1946,8 +1947,8 @@ func TestTest_TestStep_ExternalProviders_DifferentVersions(t *testing.T) { func TestTest_TestStep_ExternalProviders_Error(t *testing.T) { t.Parallel() - plugintest.TestExpectTFatal(t, func() { - Test(&mockT{}, TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + Test(mockT, TestCase{ Steps: []TestStep{ { Config: "# not empty", @@ -2334,7 +2335,7 @@ func extractResourceAttr(resourceName string, attributeName string, attributeVal func TestTest_TestStep_ProtoV5ProviderFactories(t *testing.T) { t.Parallel() - UnitTest(&mockT{}, TestCase{ + UnitTest(t, TestCase{ Steps: []TestStep{ { Config: "# not empty", @@ -2349,8 +2350,8 @@ func TestTest_TestStep_ProtoV5ProviderFactories(t *testing.T) { func TestTest_TestStep_ProtoV5ProviderFactories_Error(t *testing.T) { t.Parallel() - plugintest.TestExpectTFatal(t, func() { - UnitTest(&mockT{}, TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + UnitTest(mockT, TestCase{ Steps: []TestStep{ { Config: "# not empty", @@ -2368,7 +2369,7 @@ func TestTest_TestStep_ProtoV5ProviderFactories_Error(t *testing.T) { func TestTest_TestStep_ProtoV6ProviderFactories(t *testing.T) { t.Parallel() - UnitTest(&mockT{}, TestCase{ + UnitTest(t, TestCase{ Steps: []TestStep{ { Config: "# not empty", @@ -2383,8 +2384,8 @@ func TestTest_TestStep_ProtoV6ProviderFactories(t *testing.T) { func TestTest_TestStep_ProtoV6ProviderFactories_Error(t *testing.T) { t.Parallel() - plugintest.TestExpectTFatal(t, func() { - UnitTest(&mockT{}, TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + UnitTest(mockT, TestCase{ Steps: []TestStep{ { Config: "# not empty", @@ -2465,7 +2466,7 @@ func TestTest_TestStep_ProtoV6ProviderFactories_To_ExternalProviders(t *testing. func TestTest_TestStep_ProviderFactories(t *testing.T) { t.Parallel() - UnitTest(&mockT{}, TestCase{ + UnitTest(t, TestCase{ Steps: []TestStep{ { Config: "# not empty", @@ -2482,8 +2483,8 @@ func TestTest_TestStep_ProviderFactories(t *testing.T) { func TestTest_TestStep_ProviderFactories_Error(t *testing.T) { t.Parallel() - plugintest.TestExpectTFatal(t, func() { - UnitTest(&mockT{}, TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + UnitTest(mockT, TestCase{ Steps: []TestStep{ { Config: "# not empty", diff --git a/helper/resource/teststep_test.go b/helper/resource/teststep_test.go index feffb7524..ad6003bdd 100644 --- a/helper/resource/teststep_test.go +++ b/helper/resource/teststep_test.go @@ -8,10 +8,10 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-go/tftypes" - "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/resource" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) @@ -111,8 +111,8 @@ func TestTestStep_ImportStateVerifyIdentifierAttribute(t *testing.T) { func TestTestStep_ImportStateVerifyIdentifierAttribute_Error(t *testing.T) { t.Parallel() - plugintest.TestExpectTFatal(t, func() { - Test(&mockT{}, TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + Test(mockT, TestCase{ TerraformVersionChecks: []tfversion.TerraformVersionCheck{ tfversion.SkipBelow(tfversion.Version1_0_0), // ProtoV6ProviderFactories }, diff --git a/helper/resource/tfversion_checks_test.go b/helper/resource/tfversion_checks_test.go index 0bc2238f4..160d8d168 100644 --- a/helper/resource/tfversion_checks_test.go +++ b/helper/resource/tfversion_checks_test.go @@ -9,10 +9,8 @@ import ( "github.com/hashicorp/go-version" - "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func TestRunTFVersionChecks(t *testing.T) { @@ -54,8 +52,8 @@ func TestRunTFVersionChecks(t *testing.T) { t.Parallel() if test.expectError { - plugintest.TestExpectTFatal(t, func() { - runTFVersionChecks(context.Background(), &testinginterface.RuntimeT{}, test.tfVersion, test.versionChecks) + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + runTFVersionChecks(context.Background(), mockT, test.tfVersion, test.versionChecks) }) } else { runTFVersionChecks(context.Background(), t, test.tfVersion, test.versionChecks) diff --git a/internal/plugintest/util.go b/internal/plugintest/util.go index be187a01b..830be3e4b 100644 --- a/internal/plugintest/util.go +++ b/internal/plugintest/util.go @@ -11,7 +11,6 @@ import ( "path" "path/filepath" "strings" - "testing" ) func symlinkFile(src string, dest string) error { @@ -145,42 +144,3 @@ func CopyDir(src, dest, baseDirName string) error { return nil } - -// TestExpectTFatal provides a wrapper for logic which should call -// (*testing.T).Fatal() or (*testing.T).Fatalf(). -// -// Since we do not want the wrapping test to fail when an expected test error -// occurs, it is required that the testLogic passed in uses -// github.com/mitchellh/go-testing-interface.RuntimeT instead of the real -// *testing.T. -// -// If Fatal() or Fatalf() is not called in the logic, the real (*testing.T).Fatal() will -// be called to fail the test. -func TestExpectTFatal(t *testing.T, testLogic func()) { - t.Helper() - - var recoverIface interface{} - - func() { - defer func() { - recoverIface = recover() - }() - - testLogic() - }() - - if recoverIface == nil { - t.Fatalf("expected t.Fatal(), got none") - } - - recoverStr, ok := recoverIface.(string) - - if !ok { - t.Fatalf("expected string from recover(), got: %v (%T)", recoverIface, recoverIface) - } - - // this string is hardcoded in github.com/mitchellh/go-testing-interface - if !strings.HasPrefix(recoverStr, "testing.T failed, see logs for output") { - t.Fatalf("expected t.Fatal(), got: %s", recoverStr) - } -} diff --git a/tfversion/all_test.go b/tfversion/all_test.go index aa326d6bf..db9cc545a 100644 --- a/tfversion/all_test.go +++ b/tfversion/all_test.go @@ -8,12 +8,11 @@ import ( "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-go/tfprotov6" - testinginterface "github.com/mitchellh/go-testing-interface" r "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) @@ -80,8 +79,8 @@ func Test_All_Error(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil diff --git a/tfversion/any_test.go b/tfversion/any_test.go index 76eacaa01..edc04ea9b 100644 --- a/tfversion/any_test.go +++ b/tfversion/any_test.go @@ -8,12 +8,11 @@ import ( "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-go/tfprotov6" - testinginterface "github.com/mitchellh/go-testing-interface" r "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) @@ -73,8 +72,8 @@ func Test_Any_Error(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil diff --git a/tfversion/require_above_test.go b/tfversion/require_above_test.go index 8e8c3ea8e..4a3e9f80b 100644 --- a/tfversion/require_above_test.go +++ b/tfversion/require_above_test.go @@ -10,12 +10,10 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" r "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_RequireAbove_Equal(t *testing.T) { //nolint:paralleltest @@ -68,8 +66,8 @@ func Test_RequireAbove_Lower(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.0.7") - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -139,8 +137,8 @@ func Test_RequireAbove_Prerelease_HigherCoreVersion(t *testing.T) { //nolint:par // 1.8.0 core version. This intentionally verifies that the logic does not // ignore the core version of the prerelease version when compared against // the core version of the check. - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -162,8 +160,8 @@ func Test_RequireAbove_Prerelease_HigherPrerelease(t *testing.T) { //nolint:para // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, diff --git a/tfversion/require_below_test.go b/tfversion/require_below_test.go index 01d09d6b8..80a525535 100644 --- a/tfversion/require_below_test.go +++ b/tfversion/require_below_test.go @@ -10,20 +10,18 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" r "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_RequireBelow_Equal(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.7.0") - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -69,8 +67,8 @@ func Test_RequireBelow_Higher(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.4.0") - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -98,8 +96,8 @@ func Test_RequireBelow_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:para // core versions. // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -165,8 +163,8 @@ func Test_RequireBelow_Prerelease_LowerCoreVersion(t *testing.T) { //nolint:para // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -188,8 +186,8 @@ func Test_RequireBelow_Prerelease_LowerPrerelease(t *testing.T) { //nolint:paral // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, diff --git a/tfversion/require_between_test.go b/tfversion/require_between_test.go index 9508ec2a3..140e39ff5 100644 --- a/tfversion/require_between_test.go +++ b/tfversion/require_between_test.go @@ -10,12 +10,10 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" r "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_RequireBetween(t *testing.T) { //nolint:paralleltest @@ -60,8 +58,8 @@ func Test_RequireBetween_Error_BelowMin(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -82,8 +80,8 @@ func Test_RequireBetween_Error_BelowMin(t *testing.T) { //nolint:paralleltest func Test_RequireBetween_Error_EqToMax(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.3.0") - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -111,8 +109,8 @@ func Test_RequireBetween_Prerelease_MaxEqualCoreVersion(t *testing.T) { //nolint // core versions. // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -184,8 +182,8 @@ func Test_RequireBetween_Prerelease_MinHigherCoreVersion(t *testing.T) { //nolin // 1.8.0 core version. This intentionally verifies that the logic does not // ignore the core version of the prerelease version when compared against // the core version of the check. - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -228,8 +226,8 @@ func Test_RequireBetween_Prerelease_MinHigherPrerelease(t *testing.T) { //nolint // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -251,8 +249,8 @@ func Test_RequireBetween_Prerelease_MaxLowerCoreVersion(t *testing.T) { //nolint // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -295,8 +293,8 @@ func Test_RequireBetween_Prerelease_MaxLowerPrerelease(t *testing.T) { //nolint: // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, diff --git a/tfversion/require_not_test.go b/tfversion/require_not_test.go index 6eba3e7ba..5fe370ae9 100644 --- a/tfversion/require_not_test.go +++ b/tfversion/require_not_test.go @@ -10,12 +10,10 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" r "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_RequireNot(t *testing.T) { //nolint:paralleltest @@ -41,8 +39,8 @@ func Test_RequireNot_Error(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -70,8 +68,8 @@ func Test_RequireNot_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:parall // core versions. // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 - plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, From efa79b9c0c0ac1ca317ce5c1a1f81bde6096e54b Mon Sep 17 00:00:00 2001 From: Baraa Basata Date: Thu, 19 Dec 2024 21:04:19 -0500 Subject: [PATCH 3/6] use testingiface.Expect* in tfversion tests --- helper/resource/testing_test.go | 2 +- tfversion/all_test.go | 72 ++--- tfversion/any_test.go | 62 ++-- tfversion/skip_above_test.go | 249 ++++++++-------- tfversion/skip_below_test.go | 239 +++++++++------- tfversion/skip_between_test.go | 347 ++++++++++++----------- tfversion/skip_if_not_alpha_test.go | 101 ++++--- tfversion/skip_if_not_prerelease_test.go | 101 ++++--- tfversion/skip_if_test.go | 185 ++++++------ 9 files changed, 732 insertions(+), 626 deletions(-) diff --git a/helper/resource/testing_test.go b/helper/resource/testing_test.go index 56f281cdb..c87bf9245 100644 --- a/helper/resource/testing_test.go +++ b/helper/resource/testing_test.go @@ -29,7 +29,7 @@ func TestParallelTest(t *testing.T) { t.Parallel() testingiface.ExpectParallel(t, func(mockT *testingiface.MockT) { - ParallelTest(mockt, TestCase{ + ParallelTest(mockT, TestCase{ IsUnitTest: true, ProviderFactories: map[string]func() (*schema.Provider, error){ "test": func() (*schema.Provider, error) { //nolint:unparam // required signature diff --git a/tfversion/all_test.go b/tfversion/all_test.go index db9cc545a..21f51db65 100644 --- a/tfversion/all_test.go +++ b/tfversion/all_test.go @@ -20,27 +20,29 @@ func Test_All_RunTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.Any( - tfversion.All( - tfversion.RequireNot(version.Must(version.NewVersion("0.15.0"))), //returns nil - tfversion.SkipIf(version.Must(version.NewVersion("1.2.0"))), //returns nil - tfversion.RequireBelow(version.Must(version.NewVersion("1.2.0"))), //returns nil + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.Any( + tfversion.All( + tfversion.RequireNot(version.Must(version.NewVersion("0.15.0"))), //returns nil + tfversion.SkipIf(version.Must(version.NewVersion("1.2.0"))), //returns nil + tfversion.RequireBelow(version.Must(version.NewVersion("1.2.0"))), //returns nil + ), ), - ), - }, - Steps: []r.TestStep{ - { - Config: `variable "a" { + }, + Steps: []r.TestStep{ + { + Config: `variable "a" { nullable = true default = "hello" }`, + }, }, - }, + }) }) } @@ -48,30 +50,32 @@ func Test_All_SkipTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.0.7") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature - return nil, nil + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature + return nil, nil + }, }, - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.Any( - tfversion.All( - tfversion.RequireNot(version.Must(version.NewVersion("0.15.0"))), //returns nil - tfversion.SkipBelow(version.Must(version.NewVersion("1.2.0"))), //returns skip - tfversion.SkipIf(version.Must(version.NewVersion("1.0.7"))), //returns skip - tfversion.RequireBelow(version.Must(version.NewVersion("1.2.0"))), //returns nil + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.Any( + tfversion.All( + tfversion.RequireNot(version.Must(version.NewVersion("0.15.0"))), //returns nil + tfversion.SkipBelow(version.Must(version.NewVersion("1.2.0"))), //returns skip + tfversion.SkipIf(version.Must(version.NewVersion("1.0.7"))), //returns skip + tfversion.RequireBelow(version.Must(version.NewVersion("1.2.0"))), //returns nil + ), ), - ), - }, - Steps: []r.TestStep{ - { - Config: `variable "a" { + }, + Steps: []r.TestStep{ + { + Config: `variable "a" { nullable = true default = "hello" }`, + }, }, - }, + }) }) } diff --git a/tfversion/any_test.go b/tfversion/any_test.go index edc04ea9b..8a6ca7dea 100644 --- a/tfversion/any_test.go +++ b/tfversion/any_test.go @@ -20,24 +20,26 @@ func Test_Any_RunTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.Any( - tfversion.RequireNot(version.Must(version.NewVersion("1.1.0"))), //returns error - tfversion.RequireBelow(version.Must(version.NewVersion("1.2.0"))), //returns nil - ), - }, - Steps: []r.TestStep{ - { - Config: `variable "a" { + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.Any( + tfversion.RequireNot(version.Must(version.NewVersion("1.1.0"))), //returns error + tfversion.RequireBelow(version.Must(version.NewVersion("1.2.0"))), //returns nil + ), + }, + Steps: []r.TestStep{ + { + Config: `variable "a" { nullable = true default = "hello" }`, + }, }, - }, + }) }) } @@ -45,26 +47,28 @@ func Test_Any_SkipTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature - return nil, nil + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature + return nil, nil + }, + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.Any( + tfversion.SkipIf(version.Must(version.NewVersion("1.1.0"))), //returns skip + tfversion.SkipBelow(version.Must(version.NewVersion("1.2.0"))), //returns skip + ), }, - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.Any( - tfversion.SkipIf(version.Must(version.NewVersion("1.1.0"))), //returns skip - tfversion.SkipBelow(version.Must(version.NewVersion("1.2.0"))), //returns skip - ), - }, - Steps: []r.TestStep{ - { - Config: `variable "a" { + Steps: []r.TestStep{ + { + Config: `variable "a" { nullable = true default = "hello" }`, + }, }, - }, + }) }) } diff --git a/tfversion/skip_above_test.go b/tfversion/skip_above_test.go index db9898c37..61fe7e015 100644 --- a/tfversion/skip_above_test.go +++ b/tfversion/skip_above_test.go @@ -12,6 +12,7 @@ import ( r "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) @@ -19,25 +20,27 @@ func Test_SkipAbove_Lower(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.3.0") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature - return nil, nil - }, - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipAbove(version.Must(version.NewVersion("1.2.9"))), - }, - Steps: []r.TestStep{ - { - //module_variable_optional_attrs experiment is deprecated in TF v1.3.0 - Config: ` + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature + return nil, nil + }, + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipAbove(version.Must(version.NewVersion("1.2.9"))), + }, + Steps: []r.TestStep{ + { + //module_variable_optional_attrs experiment is deprecated in TF v1.3.0 + Config: ` terraform { experiments = [module_variable_optional_attrs] } `, + }, }, - }, + }) }) } @@ -45,25 +48,27 @@ func Test_SkipAbove_Equal(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.2.9") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature - return nil, nil - }, - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipAbove(version.Must(version.NewVersion("1.2.9"))), - }, - Steps: []r.TestStep{ - { - //module_variable_optional_attrs experiment is deprecated in TF v1.3.0 - Config: ` + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature + return nil, nil + }, + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipAbove(version.Must(version.NewVersion("1.2.9"))), + }, + Steps: []r.TestStep{ + { + //module_variable_optional_attrs experiment is deprecated in TF v1.3.0 + Config: ` terraform { experiments = [module_variable_optional_attrs] } `, + }, }, - }, + }) }) } @@ -71,18 +76,20 @@ func Test_SkipAbove_Higher(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.7.1") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipAbove(version.Must(version.NewVersion("1.7.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipAbove(version.Must(version.NewVersion("1.7.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -96,18 +103,22 @@ func Test_SkipAbove_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:paralle // core versions. // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipAbove(version.Must(version.NewVersion("1.8.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + + // Invert + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipAbove(version.Must(version.NewVersion("1.8.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -115,18 +126,20 @@ func Test_SkipAbove_Prerelease_EqualPrerelease(t *testing.T) { //nolint:parallel t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-rc1") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipAbove(version.Must(version.NewVersion("1.8.0-rc1"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipAbove(version.Must(version.NewVersion("1.8.0-rc1"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -138,18 +151,21 @@ func Test_SkipAbove_Prerelease_HigherCoreVersion(t *testing.T) { //nolint:parall // 1.8.0 core version. This intentionally verifies that the logic does not // ignore the core version of the prerelease version when compared against // the core version of the check. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipAbove(version.Must(version.NewVersion("1.8.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + // Want Pass + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipAbove(version.Must(version.NewVersion("1.8.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -159,18 +175,21 @@ func Test_SkipAbove_Prerelease_HigherPrerelease(t *testing.T) { //nolint:paralle // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipAbove(version.Must(version.NewVersion("1.7.0-rc2"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipAbove(version.Must(version.NewVersion("1.7.0-rc2"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -180,18 +199,21 @@ func Test_SkipAbove_Prerelease_LowerCoreVersion(t *testing.T) { //nolint:paralle // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipAbove(version.Must(version.NewVersion("1.7.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + // Want Pass + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipAbove(version.Must(version.NewVersion("1.7.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -201,17 +223,20 @@ func Test_SkipAbove_Prerelease_LowerPrerelease(t *testing.T) { //nolint:parallel // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipAbove(version.Must(version.NewVersion("1.8.0-beta1"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipAbove(version.Must(version.NewVersion("1.8.0-beta1"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } diff --git a/tfversion/skip_below_test.go b/tfversion/skip_below_test.go index 4999a2dea..3eea90dc1 100644 --- a/tfversion/skip_below_test.go +++ b/tfversion/skip_below_test.go @@ -12,6 +12,7 @@ import ( r "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) @@ -19,24 +20,26 @@ func Test_SkipBelow_Lower(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.0.7") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature - return nil, nil - }, - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBelow(version.Must(version.NewVersion("1.1.0"))), - }, - Steps: []r.TestStep{ - { - //nullable argument only available in TF v1.1.0+ - Config: `variable "a" { + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature + return nil, nil + }, + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBelow(version.Must(version.NewVersion("1.1.0"))), + }, + Steps: []r.TestStep{ + { + //nullable argument only available in TF v1.1.0+ + Config: `variable "a" { nullable = true default = "hello" }`, + }, }, - }, + }) }) } @@ -44,22 +47,24 @@ func Test_SkipBelow_Equal(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBelow(version.Must(version.NewVersion("1.1.0"))), - }, - Steps: []r.TestStep{ - { - //nullable argument only available in TF v1.1.0+ - Config: `variable "a" { + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBelow(version.Must(version.NewVersion("1.1.0"))), + }, + Steps: []r.TestStep{ + { + //nullable argument only available in TF v1.1.0+ + Config: `variable "a" { nullable = true default = "hello" }`, + }, }, - }, + }) }) } @@ -67,22 +72,24 @@ func Test_SkipBelow_Higher(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.1") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBelow(version.Must(version.NewVersion("1.1.0"))), - }, - Steps: []r.TestStep{ - { - //nullable argument only available in TF v1.1.0+ - Config: `variable "a" { + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBelow(version.Must(version.NewVersion("1.1.0"))), + }, + Steps: []r.TestStep{ + { + //nullable argument only available in TF v1.1.0+ + Config: `variable "a" { nullable = true default = "hello" }`, + }, }, - }, + }) }) } @@ -96,18 +103,20 @@ func Test_SkipBelow_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:paralle // core versions. // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -115,18 +124,20 @@ func Test_SkipBelow_Prerelease_EqualPrerelease(t *testing.T) { //nolint:parallel t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-rc1") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0-rc1"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0-rc1"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -138,18 +149,20 @@ func Test_SkipBelow_Prerelease_HigherCoreVersion(t *testing.T) { //nolint:parall // 1.8.0 core version. This intentionally verifies that the logic does not // ignore the core version of the prerelease version when compared against // the core version of the check. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -159,18 +172,20 @@ func Test_SkipBelow_Prerelease_HigherPrerelease(t *testing.T) { //nolint:paralle // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBelow(version.Must(version.NewVersion("1.7.0-rc2"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBelow(version.Must(version.NewVersion("1.7.0-rc2"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -180,18 +195,20 @@ func Test_SkipBelow_Prerelease_LowerCoreVersion(t *testing.T) { //nolint:paralle // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBelow(version.Must(version.NewVersion("1.7.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBelow(version.Must(version.NewVersion("1.7.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -201,17 +218,19 @@ func Test_SkipBelow_Prerelease_LowerPrerelease(t *testing.T) { //nolint:parallel // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0-beta1"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBelow(version.Must(version.NewVersion("1.8.0-beta1"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } diff --git a/tfversion/skip_between_test.go b/tfversion/skip_between_test.go index 35ced5279..b91d64ff0 100644 --- a/tfversion/skip_between_test.go +++ b/tfversion/skip_between_test.go @@ -12,29 +12,29 @@ import ( r "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_SkipBetween_SkipTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.2.0") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature - return nil, nil - }, - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBetween(version.Must(version.NewVersion("1.2.0")), version.Must(version.NewVersion("1.3.0"))), - }, - Steps: []r.TestStep{ - { - //module_variable_optional_attrs experiment is deprecated in TF v1.3.0 - //precondition block is only available in TF v1.2.0+ - Config: ` + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature + return nil, nil + }, + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBetween(version.Must(version.NewVersion("1.2.0")), version.Must(version.NewVersion("1.3.0"))), + }, + Steps: []r.TestStep{ + { + //module_variable_optional_attrs experiment is deprecated in TF v1.3.0 + //precondition block is only available in TF v1.2.0+ + Config: ` terraform { experiments = [module_variable_optional_attrs] } @@ -50,8 +50,9 @@ func Test_SkipBetween_SkipTest(t *testing.T) { //nolint:paralleltest error_message = "precondition_error" } }`, + }, }, - }, + }) }) } @@ -59,18 +60,20 @@ func Test_SkipBetween_RunTest_AboveMax(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.3.0") - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBetween(version.Must(version.NewVersion("1.2.0")), version.Must(version.NewVersion("1.3.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBetween(version.Must(version.NewVersion("1.2.0")), version.Must(version.NewVersion("1.3.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -78,18 +81,20 @@ func Test_SkipBetween_RunTest_EqToMin(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.2.0") - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBetween(version.Must(version.NewVersion("1.2.0")), version.Must(version.NewVersion("1.3.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBetween(version.Must(version.NewVersion("1.2.0")), version.Must(version.NewVersion("1.3.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -103,18 +108,20 @@ func Test_SkipBetween_Prerelease_MaxEqualCoreVersion(t *testing.T) { //nolint:pa // core versions. // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBetween(version.Must(version.NewVersion("1.7.0")), version.Must(version.NewVersion("1.8.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBetween(version.Must(version.NewVersion("1.7.0")), version.Must(version.NewVersion("1.8.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -128,18 +135,20 @@ func Test_SkipBetween_Prerelease_MinEqualCoreVersion(t *testing.T) { //nolint:pa // core versions. // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBetween(version.Must(version.NewVersion("1.8.0")), version.Must(version.NewVersion("1.9.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBetween(version.Must(version.NewVersion("1.8.0")), version.Must(version.NewVersion("1.9.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -151,18 +160,20 @@ func Test_SkipBetween_Prerelease_MaxHigherCoreVersion(t *testing.T) { //nolint:p // 1.8.0 core version. This intentionally verifies that the logic does not // ignore the core version of the prerelease version when compared against // the core version of the check. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBetween(version.Must(version.NewVersion("1.6.0")), version.Must(version.NewVersion("1.8.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBetween(version.Must(version.NewVersion("1.6.0")), version.Must(version.NewVersion("1.8.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -174,18 +185,20 @@ func Test_SkipBetween_Prerelease_MinHigherCoreVersion(t *testing.T) { //nolint:p // 1.8.0 core version. This intentionally verifies that the logic does not // ignore the core version of the prerelease version when compared against // the core version of the check. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBetween(version.Must(version.NewVersion("1.8.0")), version.Must(version.NewVersion("1.9.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBetween(version.Must(version.NewVersion("1.8.0")), version.Must(version.NewVersion("1.9.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -195,18 +208,20 @@ func Test_SkipBetween_Prerelease_MaxHigherPrerelease(t *testing.T) { //nolint:pa // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBetween(version.Must(version.NewVersion("1.6.0")), version.Must(version.NewVersion("1.7.0-rc2"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBetween(version.Must(version.NewVersion("1.6.0")), version.Must(version.NewVersion("1.7.0-rc2"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -216,18 +231,20 @@ func Test_SkipBetween_Prerelease_MinHigherPrerelease(t *testing.T) { //nolint:pa // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBetween(version.Must(version.NewVersion("1.7.0-rc2")), version.Must(version.NewVersion("1.8.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBetween(version.Must(version.NewVersion("1.7.0-rc2")), version.Must(version.NewVersion("1.8.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -237,18 +254,20 @@ func Test_SkipBetween_Prerelease_MaxLowerCoreVersion(t *testing.T) { //nolint:pa // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBetween(version.Must(version.NewVersion("1.6.0")), version.Must(version.NewVersion("1.7.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBetween(version.Must(version.NewVersion("1.6.0")), version.Must(version.NewVersion("1.7.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -258,18 +277,20 @@ func Test_SkipBetween_Prerelease_MinLowerCoreVersion(t *testing.T) { //nolint:pa // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBetween(version.Must(version.NewVersion("1.7.0")), version.Must(version.NewVersion("1.9.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBetween(version.Must(version.NewVersion("1.7.0")), version.Must(version.NewVersion("1.9.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -279,18 +300,20 @@ func Test_SkipBetween_Prerelease_MaxLowerPrerelease(t *testing.T) { //nolint:par // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBetween(version.Must(version.NewVersion("1.7.0")), version.Must(version.NewVersion("1.8.0-beta1"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBetween(version.Must(version.NewVersion("1.7.0")), version.Must(version.NewVersion("1.8.0-beta1"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -300,17 +323,19 @@ func Test_SkipBetween_Prerelease_MinLowerPrerelease(t *testing.T) { //nolint:par // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipBetween(version.Must(version.NewVersion("1.8.0-beta1")), version.Must(version.NewVersion("1.9.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBetween(version.Must(version.NewVersion("1.8.0-beta1")), version.Must(version.NewVersion("1.9.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } diff --git a/tfversion/skip_if_not_alpha_test.go b/tfversion/skip_if_not_alpha_test.go index f778968a9..7da9cfcf3 100644 --- a/tfversion/skip_if_not_alpha_test.go +++ b/tfversion/skip_if_not_alpha_test.go @@ -11,29 +11,30 @@ import ( r "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_SkipIfNotAlpha_SkipTest_Stable(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature - return nil, nil + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature + return nil, nil + }, + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIfNotAlpha(), }, - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIfNotAlpha(), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, }, - }, + }) }) } @@ -41,36 +42,40 @@ func Test_SkipIfNotAlpha_SkipTest_Beta1(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-beta1") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIfNotAlpha(), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIfNotAlpha(), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, }, - }, + }) }) } func Test_SkipIfNotAlpha_SkipTest_RC(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-rc2") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIfNotAlpha(), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), }, - }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIfNotAlpha(), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -78,17 +83,19 @@ func Test_SkipIfNotAlpha_RunTest_Alpha(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.9.0-alpha20240501") - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIfNotAlpha(), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIfNotAlpha(), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, }, - }, + }) }) } diff --git a/tfversion/skip_if_not_prerelease_test.go b/tfversion/skip_if_not_prerelease_test.go index 545017ed0..b84b9167f 100644 --- a/tfversion/skip_if_not_prerelease_test.go +++ b/tfversion/skip_if_not_prerelease_test.go @@ -11,29 +11,32 @@ import ( r "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" - testinginterface "github.com/mitchellh/go-testing-interface" + testinginterface "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" ) func Test_SkipIfNotPrerelease_SkipTest_Stable(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature - return nil, nil + testingiface.ExpectSkip(t, func(mockT *testinginterface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature + return nil, nil + }, }, - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIfNotPrerelease(), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIfNotPrerelease(), }, - }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -41,18 +44,20 @@ func Test_SkipIfNotPrerelease_RunTest_Alpha(t *testing.T) { //nolint:paralleltes t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.9.0-alpha20240501") - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIfNotPrerelease(), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, + testingiface.ExpectPass(t, func(mockT *testinginterface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIfNotPrerelease(), }, - }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -60,35 +65,39 @@ func Test_SkipIfNotPrerelease_RunTest_Beta1(t *testing.T) { //nolint:paralleltes t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-beta1") - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIfNotPrerelease(), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, + testingiface.ExpectPass(t, func(mockT *testinginterface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIfNotPrerelease(), }, - }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } func Test_SkipIfNotPrerelease_RunTest_RC(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-rc2") - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIfNotPrerelease(), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, + testingiface.ExpectPass(t, func(mockT *testinginterface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIfNotPrerelease(), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, }, - }, + }) }) } diff --git a/tfversion/skip_if_test.go b/tfversion/skip_if_test.go index 5b645b954..5da7ebc84 100644 --- a/tfversion/skip_if_test.go +++ b/tfversion/skip_if_test.go @@ -12,29 +12,30 @@ import ( r "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_SkipIf_SkipTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.4.3") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature - return nil, nil + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature + return nil, nil + }, + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIf(version.Must(version.NewVersion("1.4.3"))), }, - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIf(version.Must(version.NewVersion("1.4.3"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, }, - }, + }) }) } @@ -42,18 +43,20 @@ func Test_SkipIf_RunTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIf(version.Must(version.NewVersion("1.2.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIf(version.Must(version.NewVersion("1.2.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -67,18 +70,20 @@ func Test_SkipIf_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:parallelte // core versions. // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIf(version.Must(version.NewVersion("1.8.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIf(version.Must(version.NewVersion("1.8.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -90,18 +95,20 @@ func Test_SkipIf_Prerelease_HigherCoreVersion(t *testing.T) { //nolint:parallelt // 1.8.0 core version. This intentionally verifies that the logic does not // ignore the core version of the prerelease version when compared against // the core version of the check. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIf(version.Must(version.NewVersion("1.8.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIf(version.Must(version.NewVersion("1.8.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -111,18 +118,20 @@ func Test_SkipIf_Prerelease_HigherPrerelease(t *testing.T) { //nolint:parallelte // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIf(version.Must(version.NewVersion("1.7.0-rc2"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIf(version.Must(version.NewVersion("1.7.0-rc2"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -132,18 +141,20 @@ func Test_SkipIf_Prerelease_LowerCoreVersion(t *testing.T) { //nolint:parallelte // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIf(version.Must(version.NewVersion("1.7.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIf(version.Must(version.NewVersion("1.7.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -153,17 +164,19 @@ func Test_SkipIf_Prerelease_LowerPrerelease(t *testing.T) { //nolint:paralleltes // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.SkipIf(version.Must(version.NewVersion("1.8.0-beta1"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipIf(version.Must(version.NewVersion("1.8.0-beta1"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } From 0c062bf0dd76a3815b9fd32198269a6dfa7db58a Mon Sep 17 00:00:00 2001 From: Baraa Basata Date: Thu, 19 Dec 2024 21:23:53 -0500 Subject: [PATCH 4/6] remove direct dependency on mitchellh/go-testing-interface --- go.mod | 2 +- helper/logging/logging.go | 6 +++--- helper/resource/plan_checks.go | 4 ++-- helper/resource/plugin.go | 4 ++-- helper/resource/state_checks.go | 4 ++-- helper/resource/testcase_validate.go | 5 ++--- helper/resource/testing.go | 9 ++++----- helper/resource/testing_new.go | 12 ++++++------ helper/resource/testing_new_config.go | 4 ++-- helper/resource/testing_new_import_state.go | 4 ++-- helper/resource/testing_new_refresh_state.go | 4 ++-- helper/resource/tfversion_checks.go | 4 ++-- internal/logging/context.go | 4 ++-- 13 files changed, 32 insertions(+), 34 deletions(-) diff --git a/go.mod b/go.mod index c5bfcd7dd..46c05bb66 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,6 @@ require ( github.com/hashicorp/terraform-plugin-go v0.25.0 github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0 - github.com/mitchellh/go-testing-interface v1.14.1 github.com/zclconf/go-cty v1.15.1 golang.org/x/crypto v0.31.0 ) @@ -42,6 +41,7 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/go-wordwrap v1.0.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect diff --git a/helper/logging/logging.go b/helper/logging/logging.go index c13453e49..c462eb0f8 100644 --- a/helper/logging/logging.go +++ b/helper/logging/logging.go @@ -12,7 +12,7 @@ import ( "syscall" "github.com/hashicorp/logutils" - "github.com/mitchellh/go-testing-interface" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" ) // These are the environmental variables that determine if we log, and if @@ -33,7 +33,7 @@ var ValidLevels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"} // logging controlled by Terraform itself and managed with the TF_ACC_LOG_PATH // environment variable. Calls to tflog.* will have their output managed by the // tfsdklog sink. -func LogOutput(t testing.T) (logOutput io.Writer, err error) { +func LogOutput(t testingiface.T) (logOutput io.Writer, err error) { logOutput = io.Discard logLevel := LogLevel() @@ -91,7 +91,7 @@ func LogOutput(t testing.T) (logOutput io.Writer, err error) { // SetOutput checks for a log destination with LogOutput, and calls // log.SetOutput with the result. If LogOutput returns nil, SetOutput uses // io.Discard. Any error from LogOutout is fatal. -func SetOutput(t testing.T) { +func SetOutput(t testingiface.T) { out, err := LogOutput(t) if err != nil { log.Fatal(err) diff --git a/helper/resource/plan_checks.go b/helper/resource/plan_checks.go index c64c02ba8..f6a0d52c5 100644 --- a/helper/resource/plan_checks.go +++ b/helper/resource/plan_checks.go @@ -8,11 +8,11 @@ import ( "errors" tfjson "github.com/hashicorp/terraform-json" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/plancheck" - "github.com/mitchellh/go-testing-interface" ) -func runPlanChecks(ctx context.Context, t testing.T, plan *tfjson.Plan, planChecks []plancheck.PlanCheck) error { +func runPlanChecks(ctx context.Context, t testingiface.T, plan *tfjson.Plan, planChecks []plancheck.PlanCheck) error { t.Helper() var result []error diff --git a/helper/resource/plugin.go b/helper/resource/plugin.go index 5c92f3ab9..6e7ac997d 100644 --- a/helper/resource/plugin.go +++ b/helper/resource/plugin.go @@ -17,10 +17,10 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" - "github.com/mitchellh/go-testing-interface" "github.com/hashicorp/terraform-plugin-testing/internal/logging" "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" ) // protov5ProviderFactory is a function which is called to start a protocol @@ -113,7 +113,7 @@ type providerFactories struct { protov6 protov6ProviderFactories } -func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *plugintest.WorkingDir, factories *providerFactories) error { +func runProviderCommand(ctx context.Context, t testingiface.T, f func() error, wd *plugintest.WorkingDir, factories *providerFactories) error { // don't point to this as a test failure location // point to whatever called it t.Helper() diff --git a/helper/resource/state_checks.go b/helper/resource/state_checks.go index 66c850eae..70f12d1e6 100644 --- a/helper/resource/state_checks.go +++ b/helper/resource/state_checks.go @@ -8,12 +8,12 @@ import ( "errors" tfjson "github.com/hashicorp/terraform-json" - "github.com/mitchellh/go-testing-interface" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/statecheck" ) -func runStateChecks(ctx context.Context, t testing.T, state *tfjson.State, stateChecks []statecheck.StateCheck) error { +func runStateChecks(ctx context.Context, t testingiface.T, state *tfjson.State, stateChecks []statecheck.StateCheck) error { t.Helper() var result []error diff --git a/helper/resource/testcase_validate.go b/helper/resource/testcase_validate.go index 6640f8c84..0b6904434 100644 --- a/helper/resource/testcase_validate.go +++ b/helper/resource/testcase_validate.go @@ -7,10 +7,9 @@ import ( "context" "fmt" - "github.com/mitchellh/go-testing-interface" - "github.com/hashicorp/terraform-plugin-testing/config" "github.com/hashicorp/terraform-plugin-testing/internal/logging" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/internal/teststep" ) @@ -51,7 +50,7 @@ func (c TestCase) hasProviders(_ context.Context) bool { // - No overlapping ExternalProviders and Providers entries // - No overlapping ExternalProviders and ProviderFactories entries // - TestStep validations performed by the (TestStep).validate() method. -func (c TestCase) validate(ctx context.Context, t testing.T) error { +func (c TestCase) validate(ctx context.Context, t testingiface.T) error { logging.HelperResourceTrace(ctx, "Validating TestCase") if len(c.Steps) == 0 { diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 9e1961a46..3fa0e80c7 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -15,8 +15,6 @@ import ( "strings" "time" - "github.com/mitchellh/go-testing-interface" - "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-go/tfprotov6" @@ -31,6 +29,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/internal/addrs" "github.com/hashicorp/terraform-plugin-testing/internal/logging" "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" ) // flagSweep is a flag available when running tests on the command line. It @@ -812,7 +811,7 @@ type RefreshPlanChecks struct { // tests to occur against the same resource or service (e.g. random naming). // // Test() function requirements and documentation also apply to this function. -func ParallelTest(t testing.T, c TestCase) { +func ParallelTest(t testingiface.T, c TestCase) { t.Helper() t.Parallel() Test(t, c) @@ -849,7 +848,7 @@ func ParallelTest(t testing.T, c TestCase) { // // Refer to the Env prefixed constants for additional details about these // environment variables, and others, that control testing functionality. -func Test(t testing.T, c TestCase) { +func Test(t testingiface.T, c TestCase) { t.Helper() ctx := context.Background() @@ -933,7 +932,7 @@ func Test(t testing.T, c TestCase) { // have any external dependencies. // // Test() function requirements and documentation also apply to this function. -func UnitTest(t testing.T, c TestCase) { +func UnitTest(t testingiface.T, c TestCase) { t.Helper() c.IsUnitTest = true diff --git a/helper/resource/testing_new.go b/helper/resource/testing_new.go index 0a7c7e7f7..a9c6e959e 100644 --- a/helper/resource/testing_new.go +++ b/helper/resource/testing_new.go @@ -15,16 +15,16 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/go-version" tfjson "github.com/hashicorp/terraform-json" - "github.com/mitchellh/go-testing-interface" "github.com/hashicorp/terraform-plugin-testing/config" "github.com/hashicorp/terraform-plugin-testing/internal/logging" "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/internal/teststep" "github.com/hashicorp/terraform-plugin-testing/terraform" ) -func runPostTestDestroy(ctx context.Context, t testing.T, c TestCase, wd *plugintest.WorkingDir, providers *providerFactories, statePreDestroy *terraform.State) error { +func runPostTestDestroy(ctx context.Context, t testingiface.T, c TestCase, wd *plugintest.WorkingDir, providers *providerFactories, statePreDestroy *terraform.State) error { t.Helper() err := runProviderCommand(ctx, t, func() error { @@ -48,7 +48,7 @@ func runPostTestDestroy(ctx context.Context, t testing.T, c TestCase, wd *plugin return nil } -func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest.Helper) { +func runNewTest(ctx context.Context, t testingiface.T, c TestCase, helper *plugintest.Helper) { t.Helper() wd := helper.RequireNewWorkingDir(ctx, t, c.WorkingDir) @@ -461,7 +461,7 @@ func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest } } -func getState(ctx context.Context, t testing.T, wd *plugintest.WorkingDir) (*terraform.State, error) { +func getState(ctx context.Context, t testingiface.T, wd *plugintest.WorkingDir) (*terraform.State, error) { t.Helper() jsonState, err := wd.State(ctx) @@ -501,7 +501,7 @@ func planIsEmpty(plan *tfjson.Plan, tfVersion *version.Version) bool { return true } -func testIDRefresh(ctx context.Context, t testing.T, c TestCase, wd *plugintest.WorkingDir, step TestStep, r *terraform.ResourceState, providers *providerFactories, stepIndex int, helper *plugintest.Helper) error { +func testIDRefresh(ctx context.Context, t testingiface.T, c TestCase, wd *plugintest.WorkingDir, step TestStep, r *terraform.ResourceState, providers *providerFactories, stepIndex int, helper *plugintest.Helper) error { t.Helper() // Build the state. The state is just the resource with an ID. There @@ -643,7 +643,7 @@ func testIDRefresh(ctx context.Context, t testing.T, c TestCase, wd *plugintest. return nil } -func copyWorkingDir(ctx context.Context, t testing.T, stepNumber int, wd *plugintest.WorkingDir) { +func copyWorkingDir(ctx context.Context, t testingiface.T, stepNumber int, wd *plugintest.WorkingDir) { if os.Getenv(plugintest.EnvTfAccPersistWorkingDir) == "" { return } diff --git a/helper/resource/testing_new_config.go b/helper/resource/testing_new_config.go index 1456f7fba..33261719a 100644 --- a/helper/resource/testing_new_config.go +++ b/helper/resource/testing_new_config.go @@ -10,9 +10,9 @@ import ( "github.com/hashicorp/terraform-exec/tfexec" tfjson "github.com/hashicorp/terraform-json" - "github.com/mitchellh/go-testing-interface" "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/internal/teststep" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-plugin-testing/tfversion" @@ -26,7 +26,7 @@ import ( // changes. Those older versions will always show outputs being created. var expectNonEmptyPlanOutputChangesMinTFVersion = tfversion.Version0_14_0 -func testStepNewConfig(ctx context.Context, t testing.T, c TestCase, wd *plugintest.WorkingDir, step TestStep, providers *providerFactories, stepIndex int, helper *plugintest.Helper) error { +func testStepNewConfig(ctx context.Context, t testingiface.T, c TestCase, wd *plugintest.WorkingDir, step TestStep, providers *providerFactories, stepIndex int, helper *plugintest.Helper) error { t.Helper() configRequest := teststep.PrepareConfigurationRequest{ diff --git a/helper/resource/testing_new_import_state.go b/helper/resource/testing_new_import_state.go index 7dbc0b800..e12a251e1 100644 --- a/helper/resource/testing_new_import_state.go +++ b/helper/resource/testing_new_import_state.go @@ -10,9 +10,9 @@ import ( "strings" "github.com/google/go-cmp/cmp" - "github.com/mitchellh/go-testing-interface" "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/internal/teststep" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -20,7 +20,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" ) -func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest.Helper, wd *plugintest.WorkingDir, step TestStep, cfg teststep.Config, providers *providerFactories, stepIndex int) error { +func testStepNewImportState(ctx context.Context, t testingiface.T, helper *plugintest.Helper, wd *plugintest.WorkingDir, step TestStep, cfg teststep.Config, providers *providerFactories, stepIndex int) error { t.Helper() configRequest := teststep.PrepareConfigurationRequest{ diff --git a/helper/resource/testing_new_refresh_state.go b/helper/resource/testing_new_refresh_state.go index 5c0e38758..cb552bb75 100644 --- a/helper/resource/testing_new_refresh_state.go +++ b/helper/resource/testing_new_refresh_state.go @@ -8,15 +8,15 @@ import ( "fmt" tfjson "github.com/hashicorp/terraform-json" - "github.com/mitchellh/go-testing-interface" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-plugin-testing/internal/logging" "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" ) -func testStepNewRefreshState(ctx context.Context, t testing.T, wd *plugintest.WorkingDir, step TestStep, providers *providerFactories) error { +func testStepNewRefreshState(ctx context.Context, t testingiface.T, wd *plugintest.WorkingDir, step TestStep, providers *providerFactories) error { t.Helper() var err error diff --git a/helper/resource/tfversion_checks.go b/helper/resource/tfversion_checks.go index 1bec0abd6..bf8526733 100644 --- a/helper/resource/tfversion_checks.go +++ b/helper/resource/tfversion_checks.go @@ -7,12 +7,12 @@ import ( "context" "github.com/hashicorp/go-version" - "github.com/mitchellh/go-testing-interface" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) -func runTFVersionChecks(ctx context.Context, t testing.T, terraformVersion *version.Version, terraformVersionChecks []tfversion.TerraformVersionCheck) { +func runTFVersionChecks(ctx context.Context, t testingiface.T, terraformVersion *version.Version, terraformVersionChecks []tfversion.TerraformVersionCheck) { t.Helper() for _, tfVersionCheck := range terraformVersionChecks { diff --git a/internal/logging/context.go b/internal/logging/context.go index 0fe8002aa..aadec229a 100644 --- a/internal/logging/context.go +++ b/internal/logging/context.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-log/tfsdklog" helperlogging "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" - testing "github.com/mitchellh/go-testing-interface" + "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" ) // InitContext creates SDK logger contexts when the provider is running in @@ -34,7 +34,7 @@ func InitContext(ctx context.Context) context.Context { // The standard library log package handling is important as provider code // under test may be using that package or another logging library outside of // terraform-plugin-log. -func InitTestContext(ctx context.Context, t testing.T) context.Context { +func InitTestContext(ctx context.Context, t testingiface.T) context.Context { helperlogging.SetOutput(t) ctx = tfsdklog.RegisterTestSink(ctx, t) From 16515b577583e2f7d52529a7dbea895fdef48874 Mon Sep 17 00:00:00 2001 From: Baraa Basata Date: Fri, 20 Dec 2024 10:48:05 -0500 Subject: [PATCH 5/6] missed a few --- tfversion/require_above_test.go | 156 +++++++++++++++------------- tfversion/require_below_test.go | 82 ++++++++------- tfversion/require_between_test.go | 162 ++++++++++++++++-------------- tfversion/require_not_test.go | 130 +++++++++++++----------- 4 files changed, 285 insertions(+), 245 deletions(-) diff --git a/tfversion/require_above_test.go b/tfversion/require_above_test.go index 4a3e9f80b..c9a49427d 100644 --- a/tfversion/require_above_test.go +++ b/tfversion/require_above_test.go @@ -20,22 +20,24 @@ func Test_RequireAbove_Equal(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireAbove(version.Must(version.NewVersion("1.1.0"))), - }, - Steps: []r.TestStep{ - { - //nullable argument only available in TF v1.1.0+ - Config: `variable "a" { + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(version.Must(version.NewVersion("1.1.0"))), + }, + Steps: []r.TestStep{ + { + //nullable argument only available in TF v1.1.0+ + Config: `variable "a" { nullable = true default = "hello" }`, + }, }, - }, + }) }) } @@ -43,22 +45,24 @@ func Test_RequireAbove_Higher(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.1") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireAbove(version.Must(version.NewVersion("1.1.0"))), - }, - Steps: []r.TestStep{ - { - //nullable argument only available in TF v1.1.0+ - Config: `variable "a" { + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(version.Must(version.NewVersion("1.1.0"))), + }, + Steps: []r.TestStep{ + { + //nullable argument only available in TF v1.1.0+ + Config: `variable "a" { nullable = true default = "hello" }`, + }, }, - }, + }) }) } @@ -95,18 +99,20 @@ func Test_RequireAbove_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:para // core versions. // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireAbove(version.Must(version.NewVersion("1.8.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(version.Must(version.NewVersion("1.8.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -114,18 +120,20 @@ func Test_RequireAbove_Prerelease_EqualPrerelease(t *testing.T) { //nolint:paral t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-rc1") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireAbove(version.Must(version.NewVersion("1.8.0-rc1"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(version.Must(version.NewVersion("1.8.0-rc1"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -183,18 +191,20 @@ func Test_RequireAbove_Prerelease_LowerCoreVersion(t *testing.T) { //nolint:para // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireAbove(version.Must(version.NewVersion("1.7.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(version.Must(version.NewVersion("1.7.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -204,17 +214,19 @@ func Test_RequireAbove_Prerelease_LowerPrerelease(t *testing.T) { //nolint:paral // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireAbove(version.Must(version.NewVersion("1.8.0-beta1"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireAbove(version.Must(version.NewVersion("1.8.0-beta1"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } diff --git a/tfversion/require_below_test.go b/tfversion/require_below_test.go index 80a525535..6c11ce7f2 100644 --- a/tfversion/require_below_test.go +++ b/tfversion/require_below_test.go @@ -41,25 +41,27 @@ func Test_RequireBelow_Lower(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.2.0") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature - return nil, nil - }, - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireBelow(version.Must(version.NewVersion("1.3.0"))), - }, - Steps: []r.TestStep{ - { - //module_variable_optional_attrs experiment is deprecated in TF v1.3.0 - Config: ` + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature + return nil, nil + }, + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireBelow(version.Must(version.NewVersion("1.3.0"))), + }, + Steps: []r.TestStep{ + { + //module_variable_optional_attrs experiment is deprecated in TF v1.3.0 + Config: ` terraform { experiments = [module_variable_optional_attrs] } `, + }, }, - }, + }) }) } @@ -121,18 +123,20 @@ func Test_RequireBelow_Prerelease_HigherCoreVersion(t *testing.T) { //nolint:par // 1.8.0 core version. This intentionally verifies that the logic does not // ignore the core version of the prerelease version when compared against // the core version of the check. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireBelow(version.Must(version.NewVersion("1.8.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireBelow(version.Must(version.NewVersion("1.8.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -142,18 +146,20 @@ func Test_RequireBelow_Prerelease_HigherPrerelease(t *testing.T) { //nolint:para // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireBelow(version.Must(version.NewVersion("1.7.0-rc2"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireBelow(version.Must(version.NewVersion("1.7.0-rc2"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } diff --git a/tfversion/require_between_test.go b/tfversion/require_between_test.go index 140e39ff5..737b91e53 100644 --- a/tfversion/require_between_test.go +++ b/tfversion/require_between_test.go @@ -20,20 +20,21 @@ func Test_RequireBetween(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.2.0") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature - return nil, nil - }, - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireBetween(version.Must(version.NewVersion("1.2.0")), version.Must(version.NewVersion("1.3.0"))), - }, - Steps: []r.TestStep{ - { - //module_variable_optional_attrs experiment is deprecated in TF v1.3.0 - //precondition block is only available in TF v1.2.0+ - Config: ` + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature + return nil, nil + }, + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireBetween(version.Must(version.NewVersion("1.2.0")), version.Must(version.NewVersion("1.3.0"))), + }, + Steps: []r.TestStep{ + { + //module_variable_optional_attrs experiment is deprecated in TF v1.3.0 + //precondition block is only available in TF v1.2.0+ + Config: ` terraform { experiments = [module_variable_optional_attrs] } @@ -49,8 +50,9 @@ func Test_RequireBetween(t *testing.T) { //nolint:paralleltest error_message = "precondition_error" } }`, + }, }, - }, + }) }) } @@ -136,18 +138,20 @@ func Test_RequireBetween_Prerelease_MinEqualCoreVersion(t *testing.T) { //nolint // core versions. // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireBetween(version.Must(version.NewVersion("1.8.0")), version.Must(version.NewVersion("1.9.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireBetween(version.Must(version.NewVersion("1.8.0")), version.Must(version.NewVersion("1.9.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -159,18 +163,20 @@ func Test_RequireBetween_Prerelease_MaxHigherCoreVersion(t *testing.T) { //nolin // 1.8.0 core version. This intentionally verifies that the logic does not // ignore the core version of the prerelease version when compared against // the core version of the check. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireBetween(version.Must(version.NewVersion("1.6.0")), version.Must(version.NewVersion("1.8.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireBetween(version.Must(version.NewVersion("1.6.0")), version.Must(version.NewVersion("1.8.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -205,18 +211,20 @@ func Test_RequireBetween_Prerelease_MaxHigherPrerelease(t *testing.T) { //nolint // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireBetween(version.Must(version.NewVersion("1.6.0")), version.Must(version.NewVersion("1.7.0-rc2"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireBetween(version.Must(version.NewVersion("1.6.0")), version.Must(version.NewVersion("1.7.0-rc2"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -272,18 +280,20 @@ func Test_RequireBetween_Prerelease_MinLowerCoreVersion(t *testing.T) { //nolint // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireBetween(version.Must(version.NewVersion("1.7.0")), version.Must(version.NewVersion("1.9.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireBetween(version.Must(version.NewVersion("1.7.0")), version.Must(version.NewVersion("1.9.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -316,17 +326,19 @@ func Test_RequireBetween_Prerelease_MinLowerPrerelease(t *testing.T) { //nolint: // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireBetween(version.Must(version.NewVersion("1.8.0-beta1")), version.Must(version.NewVersion("1.9.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireBetween(version.Must(version.NewVersion("1.8.0-beta1")), version.Must(version.NewVersion("1.9.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } diff --git a/tfversion/require_not_test.go b/tfversion/require_not_test.go index 5fe370ae9..e2ea10435 100644 --- a/tfversion/require_not_test.go +++ b/tfversion/require_not_test.go @@ -20,18 +20,20 @@ func Test_RequireNot(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_PATH", "") t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.4.3") - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireNot(version.Must(version.NewVersion("1.1.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireNot(version.Must(version.NewVersion("1.1.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -93,18 +95,20 @@ func Test_RequireNot_Prerelease_HigherCoreVersion(t *testing.T) { //nolint:paral // 1.8.0 core version. This intentionally verifies that the logic does not // ignore the core version of the prerelease version when compared against // the core version of the check. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireNot(version.Must(version.NewVersion("1.8.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireNot(version.Must(version.NewVersion("1.8.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -114,18 +118,20 @@ func Test_RequireNot_Prerelease_HigherPrerelease(t *testing.T) { //nolint:parall // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireNot(version.Must(version.NewVersion("1.7.0-rc2"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireNot(version.Must(version.NewVersion("1.7.0-rc2"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -135,18 +141,20 @@ func Test_RequireNot_Prerelease_LowerCoreVersion(t *testing.T) { //nolint:parall // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireNot(version.Must(version.NewVersion("1.7.0"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireNot(version.Must(version.NewVersion("1.7.0"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } @@ -156,17 +164,19 @@ func Test_RequireNot_Prerelease_LowerPrerelease(t *testing.T) { //nolint:paralle // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. - r.UnitTest(t, r.TestCase{ - ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ - "test": providerserver.NewProviderServer(testprovider.Provider{}), - }, - TerraformVersionChecks: []tfversion.TerraformVersionCheck{ - tfversion.RequireNot(version.Must(version.NewVersion("1.8.0-beta1"))), - }, - Steps: []r.TestStep{ - { - Config: `//non-empty config`, - }, - }, + testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { + r.UnitTest(mockT, r.TestCase{ + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ + "test": providerserver.NewProviderServer(testprovider.Provider{}), + }, + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.RequireNot(version.Must(version.NewVersion("1.8.0-beta1"))), + }, + Steps: []r.TestStep{ + { + Config: `//non-empty config`, + }, + }, + }) }) } From 9f04495bd1e95643a09042b67aee22d8b1e2a104 Mon Sep 17 00:00:00 2001 From: Baraa Basata Date: Fri, 20 Dec 2024 13:40:16 -0500 Subject: [PATCH 6/6] introduce tshim and T.Run --- helper/resource/testing.go | 43 +- helper/resource/testing_new.go | 483 ++++++++++---------- helper/resource/testing_new_import_state.go | 74 +-- internal/testingiface/expect.go | 9 +- internal/testingiface/expect_test.go | 102 ----- internal/testingiface/mockt.go | 9 +- internal/testingiface/t.go | 2 +- tfversion/all_test.go | 6 +- tfversion/any_test.go | 6 +- tfversion/require_above_test.go | 18 +- tfversion/require_below_test.go | 16 +- tfversion/require_between_test.go | 26 +- tfversion/require_not_test.go | 14 +- tfversion/skip_above_test.go | 18 +- tfversion/skip_below_test.go | 18 +- tfversion/skip_between_test.go | 26 +- tfversion/skip_if_not_alpha_test.go | 8 +- tfversion/skip_if_not_prerelease_test.go | 8 +- tfversion/skip_if_test.go | 14 +- 19 files changed, 426 insertions(+), 474 deletions(-) delete mode 100644 internal/testingiface/expect_test.go diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 3fa0e80c7..38aeae8e8 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -13,6 +13,7 @@ import ( "regexp" "strconv" "strings" + "testing" "time" "github.com/hashicorp/terraform-plugin-go/tfprotov5" @@ -811,10 +812,14 @@ type RefreshPlanChecks struct { // tests to occur against the same resource or service (e.g. random naming). // // Test() function requirements and documentation also apply to this function. -func ParallelTest(t testingiface.T, c TestCase) { +func ParallelTestT(t testingiface.T, c TestCase) { t.Helper() t.Parallel() - Test(t, c) + TestT(t, c) +} + +func ParallelTest(t *testing.T, c TestCase) { + ParallelTestT(tshim{t}, c) } // Test performs an acceptance test on a resource. @@ -848,7 +853,7 @@ func ParallelTest(t testingiface.T, c TestCase) { // // Refer to the Env prefixed constants for additional details about these // environment variables, and others, that control testing functionality. -func Test(t testingiface.T, c TestCase) { +func TestT(t testingiface.T, c TestCase) { t.Helper() ctx := context.Background() @@ -915,11 +920,11 @@ func Test(t testingiface.T, c TestCase) { // This is done after creating the helper because a working directory is required // to retrieve the Terraform version. if c.TerraformVersionChecks != nil { - logging.HelperResourceDebug(ctx, "Calling TestCase Terraform version checks") - - runTFVersionChecks(ctx, t, helper.TerraformVersion(), c.TerraformVersionChecks) - - logging.HelperResourceDebug(ctx, "Called TestCase Terraform version checks") + t.Run("TerraformVersionChecks", func(t testingiface.T) { + logging.HelperResourceDebug(ctx, "Calling TestCase Terraform version checks") + runTFVersionChecks(ctx, t, helper.TerraformVersion(), c.TerraformVersionChecks) + logging.HelperResourceDebug(ctx, "Called TestCase Terraform version checks") + }) } runNewTest(ctx, t, c, helper) @@ -927,16 +932,34 @@ func Test(t testingiface.T, c TestCase) { logging.HelperResourceDebug(ctx, "Finished TestCase") } +func Test(t *testing.T, c TestCase) { + TestT(tshim{t}, c) +} + // UnitTest is a helper to force the acceptance testing harness to run in the // normal unit test suite. This should only be used for resource that don't // have any external dependencies. // // Test() function requirements and documentation also apply to this function. -func UnitTest(t testingiface.T, c TestCase) { +func UnitTestT(t testingiface.T, c TestCase) { t.Helper() c.IsUnitTest = true - Test(t, c) + TestT(t, c) +} + +type tshim struct { + *testing.T +} + +func (t tshim) Run(name string, f func(t testingiface.T)) bool { + return t.T.Run(name, func(t *testing.T) { + f(tshim{t}) + }) +} + +func UnitTest(t *testing.T, c TestCase) { + UnitTestT(tshim{t}, c) } func testResource(c TestStep, state *terraform.State) (*terraform.ResourceState, error) { diff --git a/helper/resource/testing_new.go b/helper/resource/testing_new.go index a9c6e959e..8faa13c6c 100644 --- a/helper/resource/testing_new.go +++ b/helper/resource/testing_new.go @@ -143,317 +143,332 @@ func runNewTest(ctx context.Context, t testingiface.T, c TestCase, helper *plugi stepNumber = stepIndex + 1 // 1-based indexing for humans - configRequest := teststep.PrepareConfigurationRequest{ - Directory: step.ConfigDirectory, - File: step.ConfigFile, - Raw: step.Config, - TestStepConfigRequest: config.TestStepConfigRequest{ - StepNumber: stepNumber, - TestName: t.Name(), - }, - }.Exec() - - cfg := teststep.Configuration(configRequest) - - ctx = logging.TestStepNumberContext(ctx, stepNumber) - - logging.HelperResourceDebug(ctx, "Starting TestStep") - - if step.PreConfig != nil { - logging.HelperResourceDebug(ctx, "Calling TestStep PreConfig") - step.PreConfig() - logging.HelperResourceDebug(ctx, "Called TestStep PreConfig") + var testMode string + if step.ImportState { + testMode = "import mode" + } else if step.RefreshState { + testMode = "refresh mode" + } else { + testMode = "lifecycle mode" } - if step.SkipFunc != nil { - logging.HelperResourceDebug(ctx, "Calling TestStep SkipFunc") + stepDescription := fmt.Sprintf("step %d %s", stepNumber, testMode) + t.Run(stepDescription, func(t testingiface.T) { - skip, err := step.SkipFunc() - if err != nil { - logging.HelperResourceError(ctx, - "Error calling TestStep SkipFunc", - map[string]interface{}{logging.KeyError: err}, - ) - t.Fatalf("Error calling TestStep SkipFunc: %s", err.Error()) - } + configRequest := teststep.PrepareConfigurationRequest{ + Directory: step.ConfigDirectory, + File: step.ConfigFile, + Raw: step.Config, + TestStepConfigRequest: config.TestStepConfigRequest{ + StepNumber: stepNumber, + TestName: t.Name(), + }, + }.Exec() - logging.HelperResourceDebug(ctx, "Called TestStep SkipFunc") + cfg := teststep.Configuration(configRequest) - if skip { - t.Logf("Skipping step %d/%d due to SkipFunc", stepNumber, len(c.Steps)) - logging.HelperResourceWarn(ctx, "Skipping TestStep due to SkipFunc") - continue - } - } + ctx = logging.TestStepNumberContext(ctx, stepNumber) - if cfg != nil && !step.Destroy && len(step.Taint) > 0 { - err := testStepTaint(ctx, step, wd) + logging.HelperResourceDebug(ctx, "Starting TestStep") - if err != nil { - logging.HelperResourceError(ctx, - "TestStep error tainting resources", - map[string]interface{}{logging.KeyError: err}, - ) - t.Fatalf("TestStep %d/%d error tainting resources: %s", stepNumber, len(c.Steps), err) + if step.PreConfig != nil { + logging.HelperResourceDebug(ctx, "Calling TestStep PreConfig") + step.PreConfig() + logging.HelperResourceDebug(ctx, "Called TestStep PreConfig") } - } - hasProviders, err := step.hasProviders(ctx, stepIndex, t.Name()) + if step.SkipFunc != nil { + logging.HelperResourceDebug(ctx, "Calling TestStep SkipFunc") - if err != nil { - logging.HelperResourceError(ctx, - "TestStep error checking for providers", - map[string]interface{}{logging.KeyError: err}, - ) - t.Fatalf("TestStep %d/%d error checking for providers: %s", stepNumber, len(c.Steps), err) - } + skip, err := step.SkipFunc() + if err != nil { + logging.HelperResourceError(ctx, + "Error calling TestStep SkipFunc", + map[string]interface{}{logging.KeyError: err}, + ) + t.Fatalf("Error calling TestStep SkipFunc: %s", err.Error()) + } - if hasProviders { - providers = &providerFactories{ - legacy: sdkProviderFactories(c.ProviderFactories).merge(step.ProviderFactories), - protov5: protov5ProviderFactories(c.ProtoV5ProviderFactories).merge(step.ProtoV5ProviderFactories), - protov6: protov6ProviderFactories(c.ProtoV6ProviderFactories).merge(step.ProtoV6ProviderFactories), - } + logging.HelperResourceDebug(ctx, "Called TestStep SkipFunc") - var hasProviderBlock bool + if skip { + t.Logf("Skipping step %d/%d due to SkipFunc", stepNumber, len(c.Steps)) + logging.HelperResourceWarn(ctx, "Skipping TestStep due to SkipFunc") + return + } + } - if cfg != nil { - hasProviderBlock, err = cfg.HasProviderBlock(ctx) + if cfg != nil && !step.Destroy && len(step.Taint) > 0 { + err := testStepTaint(ctx, step, wd) if err != nil { logging.HelperResourceError(ctx, - "TestStep error determining whether configuration contains provider block", + "TestStep error tainting resources", map[string]interface{}{logging.KeyError: err}, ) - t.Fatalf("TestStep %d/%d error determining whether configuration contains provider block: %s", stepNumber, len(c.Steps), err) + t.Fatalf("TestStep %d/%d error tainting resources: %s", stepNumber, len(c.Steps), err) } } - var testStepConfig teststep.Config - - rawCfg, err := step.providerConfig(ctx, hasProviderBlock, helper.TerraformVersion()) + hasProviders, err := step.hasProviders(ctx, stepIndex, t.Name()) if err != nil { logging.HelperResourceError(ctx, - "TestStep error generating provider configuration", + "TestStep error checking for providers", map[string]interface{}{logging.KeyError: err}, ) - t.Fatalf("TestStep %d/%d error generating provider configuration: %s", stepNumber, len(c.Steps), err) + t.Fatalf("TestStep %d/%d error checking for providers: %s", stepNumber, len(c.Steps), err) } - // Return value from step.providerConfig() is assigned to Raw as this was previously being - // passed to wd.SetConfig() directly when the second argument to wd.SetConfig() accepted a - // configuration string. - confRequest := teststep.PrepareConfigurationRequest{ - Directory: step.ConfigDirectory, - File: step.ConfigFile, - Raw: rawCfg, - TestStepConfigRequest: config.TestStepConfigRequest{ - StepNumber: stepIndex + 1, - TestName: t.Name(), - }, - }.Exec() + if hasProviders { + providers = &providerFactories{ + legacy: sdkProviderFactories(c.ProviderFactories).merge(step.ProviderFactories), + protov5: protov5ProviderFactories(c.ProtoV5ProviderFactories).merge(step.ProtoV5ProviderFactories), + protov6: protov6ProviderFactories(c.ProtoV6ProviderFactories).merge(step.ProtoV6ProviderFactories), + } - testStepConfig = teststep.Configuration(confRequest) + var hasProviderBlock bool - err = wd.SetConfig(ctx, testStepConfig, step.ConfigVariables) + if cfg != nil { + hasProviderBlock, err = cfg.HasProviderBlock(ctx) - if err != nil { - logging.HelperResourceError(ctx, - "TestStep error setting provider configuration", - map[string]interface{}{logging.KeyError: err}, - ) - t.Fatalf("TestStep %d/%d error setting test provider configuration: %s", stepNumber, len(c.Steps), err) - } + if err != nil { + logging.HelperResourceError(ctx, + "TestStep error determining whether configuration contains provider block", + map[string]interface{}{logging.KeyError: err}, + ) + t.Fatalf("TestStep %d/%d error determining whether configuration contains provider block: %s", stepNumber, len(c.Steps), err) + } + } - err = runProviderCommand( - ctx, - t, - func() error { - return wd.Init(ctx) - }, - wd, - providers, - ) + var testStepConfig teststep.Config - if err != nil { - logging.HelperResourceError(ctx, - "TestStep error running init", - map[string]interface{}{logging.KeyError: err}, - ) - t.Fatalf("TestStep %d/%d running init: %s", stepNumber, len(c.Steps), err.Error()) - return - } - } - - if step.ImportState { - logging.HelperResourceTrace(ctx, "TestStep is ImportState mode") + rawCfg, err := step.providerConfig(ctx, hasProviderBlock, helper.TerraformVersion()) - err := testStepNewImportState(ctx, t, helper, wd, step, appliedCfg, providers, stepIndex) - if step.ExpectError != nil { - logging.HelperResourceDebug(ctx, "Checking TestStep ExpectError") - if err == nil { - logging.HelperResourceError(ctx, - "Error running import: expected an error but got none", - ) - t.Fatalf("Step %d/%d error running import: expected an error but got none", stepNumber, len(c.Steps)) - } - if !step.ExpectError.MatchString(err.Error()) { - logging.HelperResourceError(ctx, - fmt.Sprintf("Error running import: expected an error with pattern (%s)", step.ExpectError.String()), - map[string]interface{}{logging.KeyError: err}, - ) - t.Fatalf("Step %d/%d error running import, expected an error with pattern (%s), no match on: %s", stepNumber, len(c.Steps), step.ExpectError.String(), err) - } - } else { - if err != nil && c.ErrorCheck != nil { - logging.HelperResourceDebug(ctx, "Calling TestCase ErrorCheck") - err = c.ErrorCheck(err) - logging.HelperResourceDebug(ctx, "Called TestCase ErrorCheck") - } if err != nil { logging.HelperResourceError(ctx, - "Error running import", + "TestStep error generating provider configuration", map[string]interface{}{logging.KeyError: err}, ) - t.Fatalf("Step %d/%d error running import: %s", stepNumber, len(c.Steps), err) + t.Fatalf("TestStep %d/%d error generating provider configuration: %s", stepNumber, len(c.Steps), err) } - } - logging.HelperResourceDebug(ctx, "Finished TestStep") + // Return value from step.providerConfig() is assigned to Raw as this was previously being + // passed to wd.SetConfig() directly when the second argument to wd.SetConfig() accepted a + // configuration string. + confRequest := teststep.PrepareConfigurationRequest{ + Directory: step.ConfigDirectory, + File: step.ConfigFile, + Raw: rawCfg, + TestStepConfigRequest: config.TestStepConfigRequest{ + StepNumber: stepIndex + 1, + TestName: t.Name(), + }, + }.Exec() - continue - } + testStepConfig = teststep.Configuration(confRequest) - if step.RefreshState { - logging.HelperResourceTrace(ctx, "TestStep is RefreshState mode") + err = wd.SetConfig(ctx, testStepConfig, step.ConfigVariables) - err := testStepNewRefreshState(ctx, t, wd, step, providers) - if step.ExpectError != nil { - logging.HelperResourceDebug(ctx, "Checking TestStep ExpectError") - if err == nil { - logging.HelperResourceError(ctx, - "Error running refresh: expected an error but got none", - ) - t.Fatalf("Step %d/%d error running refresh: expected an error but got none", stepNumber, len(c.Steps)) - } - if !step.ExpectError.MatchString(err.Error()) { + if err != nil { logging.HelperResourceError(ctx, - fmt.Sprintf("Error running refresh: expected an error with pattern (%s)", step.ExpectError.String()), + "TestStep error setting provider configuration", map[string]interface{}{logging.KeyError: err}, ) - t.Fatalf("Step %d/%d error running refresh, expected an error with pattern (%s), no match on: %s", stepNumber, len(c.Steps), step.ExpectError.String(), err) - } - } else { - if err != nil && c.ErrorCheck != nil { - logging.HelperResourceDebug(ctx, "Calling TestCase ErrorCheck") - err = c.ErrorCheck(err) - logging.HelperResourceDebug(ctx, "Called TestCase ErrorCheck") + t.Fatalf("TestStep %d/%d error setting test provider configuration: %s", stepNumber, len(c.Steps), err) } + + err = runProviderCommand( + ctx, + t, + func() error { + return wd.Init(ctx) + }, + wd, + providers, + ) + if err != nil { logging.HelperResourceError(ctx, - "Error running refresh", + "TestStep error running init", map[string]interface{}{logging.KeyError: err}, ) - t.Fatalf("Step %d/%d error running refresh: %s", stepNumber, len(c.Steps), err) + t.Fatalf("TestStep %d/%d running init: %s", stepNumber, len(c.Steps), err.Error()) + return } } - logging.HelperResourceDebug(ctx, "Finished TestStep") - - continue - } + if step.ImportState { + logging.HelperResourceTrace(ctx, "TestStep is ImportState mode") + + err := testStepNewImportState(ctx, t, helper, wd, step, appliedCfg, providers, stepIndex) + if step.ExpectError != nil { + logging.HelperResourceDebug(ctx, "Checking TestStep ExpectError") + if err == nil { + logging.HelperResourceError(ctx, + "Error running import: expected an error but got none", + ) + t.Fatalf("Step %d/%d error running import: expected an error but got none", stepNumber, len(c.Steps)) + } + if !step.ExpectError.MatchString(err.Error()) { + logging.HelperResourceError(ctx, + fmt.Sprintf("Error running import: expected an error with pattern (%s)", step.ExpectError.String()), + map[string]interface{}{logging.KeyError: err}, + ) + t.Fatalf("Step %d/%d error running import, expected an error with pattern (%s), no match on: %s", stepNumber, len(c.Steps), step.ExpectError.String(), err) + } + } else { + t.Run("deep equal", func(t testingiface.T) { + if err != nil && c.ErrorCheck != nil { + logging.HelperResourceDebug(ctx, "Calling TestCase ErrorCheck") + err = c.ErrorCheck(err) + logging.HelperResourceDebug(ctx, "Called TestCase ErrorCheck") + } + if err != nil { + logging.HelperResourceError(ctx, + "Error running import", + map[string]interface{}{logging.KeyError: err}, + ) + t.Fatalf("Step %d/%d error running import: %s", stepNumber, len(c.Steps), err) + } + }) + } - if cfg != nil { - logging.HelperResourceTrace(ctx, "TestStep is Config mode") + logging.HelperResourceDebug(ctx, "Finished TestStep") - err := testStepNewConfig(ctx, t, c, wd, step, providers, stepIndex, helper) - if step.ExpectError != nil { - logging.HelperResourceDebug(ctx, "Checking TestStep ExpectError") + return + } - if err == nil { - logging.HelperResourceError(ctx, - "Expected an error but got none", - ) - t.Fatalf("Step %d/%d, expected an error but got none", stepNumber, len(c.Steps)) + if step.RefreshState { + logging.HelperResourceTrace(ctx, "TestStep is RefreshState mode") + + err := testStepNewRefreshState(ctx, t, wd, step, providers) + if step.ExpectError != nil { + logging.HelperResourceDebug(ctx, "Checking TestStep ExpectError") + if err == nil { + logging.HelperResourceError(ctx, + "Error running refresh: expected an error but got none", + ) + t.Fatalf("Step %d/%d error running refresh: expected an error but got none", stepNumber, len(c.Steps)) + } + if !step.ExpectError.MatchString(err.Error()) { + logging.HelperResourceError(ctx, + fmt.Sprintf("Error running refresh: expected an error with pattern (%s)", step.ExpectError.String()), + map[string]interface{}{logging.KeyError: err}, + ) + t.Fatalf("Step %d/%d error running refresh, expected an error with pattern (%s), no match on: %s", stepNumber, len(c.Steps), step.ExpectError.String(), err) + } + } else { + if err != nil && c.ErrorCheck != nil { + logging.HelperResourceDebug(ctx, "Calling TestCase ErrorCheck") + err = c.ErrorCheck(err) + logging.HelperResourceDebug(ctx, "Called TestCase ErrorCheck") + } + if err != nil { + logging.HelperResourceError(ctx, + "Error running refresh", + map[string]interface{}{logging.KeyError: err}, + ) + t.Fatalf("Step %d/%d error running refresh: %s", stepNumber, len(c.Steps), err) + } } - if !step.ExpectError.MatchString(err.Error()) { - logging.HelperResourceError(ctx, - fmt.Sprintf("Expected an error with pattern (%s)", step.ExpectError.String()), - map[string]interface{}{logging.KeyError: err}, - ) - t.Fatalf("Step %d/%d, expected an error with pattern, no match on: %s", stepNumber, len(c.Steps), err) - } - } else { - if err != nil && c.ErrorCheck != nil { - logging.HelperResourceDebug(ctx, "Calling TestCase ErrorCheck") - err = c.ErrorCheck(err) + logging.HelperResourceDebug(ctx, "Finished TestStep") - logging.HelperResourceDebug(ctx, "Called TestCase ErrorCheck") - } - if err != nil { - logging.HelperResourceError(ctx, - "Unexpected error", - map[string]interface{}{logging.KeyError: err}, - ) - t.Fatalf("Step %d/%d error: %s", stepNumber, len(c.Steps), err) - } + return } - var hasTerraformBlock bool - var hasProviderBlock bool - if cfg != nil { - hasTerraformBlock, err = cfg.HasTerraformBlock(ctx) + logging.HelperResourceTrace(ctx, "TestStep is Config mode") + + err := testStepNewConfig(ctx, t, c, wd, step, providers, stepIndex, helper) + if step.ExpectError != nil { + logging.HelperResourceDebug(ctx, "Checking TestStep ExpectError") + + if err == nil { + logging.HelperResourceError(ctx, + "Expected an error but got none", + ) + t.Fatalf("Step %d/%d, expected an error but got none", stepNumber, len(c.Steps)) + } + if !step.ExpectError.MatchString(err.Error()) { + logging.HelperResourceError(ctx, + fmt.Sprintf("Expected an error with pattern (%s)", step.ExpectError.String()), + map[string]interface{}{logging.KeyError: err}, + ) + t.Fatalf("Step %d/%d, expected an error with pattern, no match on: %s", stepNumber, len(c.Steps), err) + } + } else { + if err != nil && c.ErrorCheck != nil { + logging.HelperResourceDebug(ctx, "Calling TestCase ErrorCheck") + + err = c.ErrorCheck(err) + + logging.HelperResourceDebug(ctx, "Called TestCase ErrorCheck") + } + if err != nil { + logging.HelperResourceError(ctx, + "Unexpected error", + map[string]interface{}{logging.KeyError: err}, + ) + t.Fatalf("Step %d/%d error: %s", stepNumber, len(c.Steps), err) + } + } - if err != nil { - logging.HelperResourceError(ctx, - "Error determining whether configuration contains terraform block", - map[string]interface{}{logging.KeyError: err}, - ) - t.Fatalf("Error determining whether configuration contains terraform block: %s", err) + var hasTerraformBlock bool + var hasProviderBlock bool + + if cfg != nil { + hasTerraformBlock, err = cfg.HasTerraformBlock(ctx) + + if err != nil { + logging.HelperResourceError(ctx, + "Error determining whether configuration contains terraform block", + map[string]interface{}{logging.KeyError: err}, + ) + t.Fatalf("Error determining whether configuration contains terraform block: %s", err) + } + + hasProviderBlock, err = cfg.HasProviderBlock(ctx) + + if err != nil { + logging.HelperResourceError(ctx, + "Error determining whether configuration contains provider block", + map[string]interface{}{logging.KeyError: err}, + ) + t.Fatalf("Error determining whether configuration contains provider block: %s", err) + } } - hasProviderBlock, err = cfg.HasProviderBlock(ctx) + mergedConfig, err := step.mergedConfig(ctx, c, hasTerraformBlock, hasProviderBlock, helper.TerraformVersion()) if err != nil { logging.HelperResourceError(ctx, - "Error determining whether configuration contains provider block", + "Error generating merged configuration", map[string]interface{}{logging.KeyError: err}, ) - t.Fatalf("Error determining whether configuration contains provider block: %s", err) + t.Fatalf("Error generating merged configuration: %s", err) } - } - mergedConfig, err := step.mergedConfig(ctx, c, hasTerraformBlock, hasProviderBlock, helper.TerraformVersion()) + confRequest := teststep.PrepareConfigurationRequest{ + Directory: step.ConfigDirectory, + File: step.ConfigFile, + Raw: mergedConfig, + TestStepConfigRequest: config.TestStepConfigRequest{ + StepNumber: stepIndex + 1, + TestName: t.Name(), + }, + }.Exec() - if err != nil { - logging.HelperResourceError(ctx, - "Error generating merged configuration", - map[string]interface{}{logging.KeyError: err}, - ) - t.Fatalf("Error generating merged configuration: %s", err) - } + appliedCfg = teststep.Configuration(confRequest) - confRequest := teststep.PrepareConfigurationRequest{ - Directory: step.ConfigDirectory, - File: step.ConfigFile, - Raw: mergedConfig, - TestStepConfigRequest: config.TestStepConfigRequest{ - StepNumber: stepIndex + 1, - TestName: t.Name(), - }, - }.Exec() - - appliedCfg = teststep.Configuration(confRequest) - - logging.HelperResourceDebug(ctx, "Finished TestStep") + logging.HelperResourceDebug(ctx, "Finished TestStep") - continue - } + return + } - t.Fatalf("Step %d/%d, unsupported test mode", stepNumber, len(c.Steps)) + t.Fatalf("Step %d/%d, unsupported test mode", stepNumber, len(c.Steps)) + }) } if stepNumber > 0 { diff --git a/helper/resource/testing_new_import_state.go b/helper/resource/testing_new_import_state.go index e12a251e1..52ffaf2da 100644 --- a/helper/resource/testing_new_import_state.go +++ b/helper/resource/testing_new_import_state.go @@ -129,23 +129,33 @@ func testStepNewImportState(ctx context.Context, t testingiface.T, helper *plugi } } - err = runProviderCommand(ctx, t, func() error { - return importWd.Import(ctx, step.ResourceName, importId) - }, importWd, providers) - if err != nil { - return err - } - + var errorInTest error var importState *terraform.State - err = runProviderCommand(ctx, t, func() error { - importState, err = getState(ctx, t, importWd) + + t.Run("import into a new statefile", func(t testingiface.T) { + err = runProviderCommand(ctx, t, func() error { + return importWd.Import(ctx, step.ResourceName, importId) + }, importWd, providers) if err != nil { - return err + errorInTest = err + t.Skipf("Error running import: %s", err) + return } - return nil - }, importWd, providers) - if err != nil { - t.Fatalf("Error getting state: %s", err) + + err = runProviderCommand(ctx, t, func() error { + importState, err = getState(ctx, t, importWd) + if err != nil { + return err + } + return nil + }, importWd, providers) + if err != nil { + t.Fatalf("Error getting state: %s", err) + } + }) + + if errorInTest != nil { + return errorInTest } // Go through the imported state and verify @@ -212,27 +222,29 @@ func testStepNewImportState(ctx context.Context, t testingiface.T, helper *plugi // Find the existing resource var oldR *terraform.ResourceState - for _, r2 := range oldResources { - if r2.Primary == nil || r2.Type != r.Type || r2.Provider != r.Provider { - continue - } + t.Run(fmt.Sprintf("find created resource %s in old state for comparison", rIdentifier), func(t testingiface.T) { + for _, r2 := range oldResources { + if r2.Primary == nil || r2.Type != r.Type || r2.Provider != r.Provider { + continue + } - r2Identifier, ok := r2.Primary.Attributes[identifierAttribute] + r2Identifier, ok := r2.Primary.Attributes[identifierAttribute] - if !ok { - t.Fatalf("ImportStateVerify: Old resource missing identifier attribute %q, ensure attribute value is properly set or use ImportStateVerifyIdentifierAttribute to choose different attribute", identifierAttribute) - } + if !ok { + t.Fatalf("ImportStateVerify: Old resource missing identifier attribute %q, ensure attribute value is properly set or use ImportStateVerifyIdentifierAttribute to choose different attribute", identifierAttribute) + } - if r2Identifier == rIdentifier { - oldR = r2 - break + if r2Identifier == rIdentifier { + oldR = r2 + break + } } - } - if oldR == nil || oldR.Primary == nil { - t.Fatalf( - "Failed state verification, resource with ID %s not found", - rIdentifier) - } + if oldR == nil || oldR.Primary == nil { + t.Fatalf( + "Failed state verification, resource with ID %s not found", + rIdentifier) + } + }) // don't add empty flatmapped containers, so we can more easily // compare the attributes diff --git a/internal/testingiface/expect.go b/internal/testingiface/expect.go index 66aa66a54..2e03d2d09 100644 --- a/internal/testingiface/expect.go +++ b/internal/testingiface/expect.go @@ -5,6 +5,7 @@ package testingiface import ( "sync" + "testing" ) // ExpectFailed provides a wrapper for test logic which should call any of the @@ -16,7 +17,7 @@ import ( // // If none of those were called, the real [testing.T.Fatal] is called to fail // the test. -func ExpectFail(t T, logic func(*MockT)) { +func ExpectFail(t *testing.T, logic func(*MockT)) { t.Helper() mockT := &MockT{} @@ -42,7 +43,7 @@ func ExpectFail(t T, logic func(*MockT)) { // ExpectParallel provides a wrapper for test logic which should call the // [testing.T.Parallel] method. If it doesn't, the real [testing.T.Fatal] is // called. -func ExpectParallel(t T, logic func(*MockT)) { +func ExpectParallel(t *testing.T, logic func(*MockT)) { t.Helper() mockT := &MockT{} @@ -81,7 +82,7 @@ func ExpectParallel(t T, logic func(*MockT)) { // If one of those were called, the real [testing.T.Fatal] is called to fail // the test. This is only necessary to check for false positives with skipped // tests. -func ExpectPass(t T, logic func(*MockT)) { +func ExpectPass(t *testing.T, logic func(*MockT)) { t.Helper() mockT := &MockT{} @@ -115,7 +116,7 @@ func ExpectPass(t T, logic func(*MockT)) { // // If none of those were called, the real [testing.T.Fatal] is called to fail // the test. -func ExpectSkip(t T, logic func(*MockT)) { +func ExpectSkip(t *testing.T, logic func(*MockT)) { t.Helper() mockT := &MockT{} diff --git a/internal/testingiface/expect_test.go b/internal/testingiface/expect_test.go deleted file mode 100644 index 3f0f3690d..000000000 --- a/internal/testingiface/expect_test.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package testingiface_test - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-testing/internal/testingiface" -) - -func TestExpectFail(t *testing.T) { - t.Parallel() - - testingiface.ExpectPass(t, func(mockT1 *testingiface.MockT) { - testingiface.ExpectFail(mockT1, func(mockT2 *testingiface.MockT) { - mockT2.Fatal("test fatal") - }) - }) - - testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { - testingiface.ExpectFail(mockT1, func(_ *testingiface.MockT) { - // intentionally no test error or test skip - }) - }) - - testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { - testingiface.ExpectFail(mockT1, func(mockT2 *testingiface.MockT) { - mockT2.Skip("test skip") - }) - }) -} - -func TestExpectParallel(t *testing.T) { - t.Parallel() - - testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { - testingiface.ExpectParallel(mockT1, func(mockT2 *testingiface.MockT) { - mockT2.Fatal("test fatal") - }) - }) - - testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { - testingiface.ExpectParallel(mockT1, func(_ *testingiface.MockT) { - // intentionally no test error or test skip - }) - }) - - testingiface.ExpectPass(t, func(mockT1 *testingiface.MockT) { - testingiface.ExpectParallel(mockT1, func(mockT2 *testingiface.MockT) { - mockT2.Parallel() - }) - }) - - testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { - testingiface.ExpectParallel(mockT1, func(mockT2 *testingiface.MockT) { - mockT2.Skip("test skip") - }) - }) -} - -func TestExpectPass(t *testing.T) { - t.Parallel() - - testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { - testingiface.ExpectPass(mockT1, func(mockT2 *testingiface.MockT) { - mockT2.Fatal("test fatal") - }) - }) - - testingiface.ExpectPass(t, func(_ *testingiface.MockT) { - // intentionally no test error or test skip - }) - - testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { - testingiface.ExpectPass(mockT1, func(mockT2 *testingiface.MockT) { - mockT2.Skip("test skip") - }) - }) -} - -func TestExpectSkip(t *testing.T) { - t.Parallel() - - testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { - testingiface.ExpectSkip(mockT1, func(mockT2 *testingiface.MockT) { - mockT2.Fatal("test fatal") - }) - }) - - testingiface.ExpectFail(t, func(mockT1 *testingiface.MockT) { - testingiface.ExpectSkip(mockT1, func(_ *testingiface.MockT) { - // intentionally no test error or test skip - }) - }) - - testingiface.ExpectPass(t, func(mockT1 *testingiface.MockT) { - testingiface.ExpectSkip(mockT1, func(mockT2 *testingiface.MockT) { - mockT2.Skip("test skip") - }) - }) -} diff --git a/internal/testingiface/mockt.go b/internal/testingiface/mockt.go index 9800fb237..72dc5e582 100644 --- a/internal/testingiface/mockt.go +++ b/internal/testingiface/mockt.go @@ -7,7 +7,6 @@ import ( "fmt" "os" "runtime" - "testing" "time" ) @@ -108,8 +107,12 @@ func (t *MockT) Parallel() { t.isParallel = true } -func (t *MockT) Run(name string, f func(t *testing.T)) bool { - panic("not implemented") +func (t *MockT) Run(name string, f func(t T)) bool { + t.Log("Running subtest:", name) + defer t.Log("Finished subtest:", name) + + f(t) + return !t.isFailed } func (t *MockT) Setenv(key string, value string) { diff --git a/internal/testingiface/t.go b/internal/testingiface/t.go index 8858bf3a0..4cb507e7a 100644 --- a/internal/testingiface/t.go +++ b/internal/testingiface/t.go @@ -36,7 +36,7 @@ type T interface { // Excluded to match the prior github.com/mitchellh/go-testing-interface.T // interface for complete backwards compatibility. It is relatively safe to // introduce if necessary in the future though. - // Run(name string, f func(*testing.T)) bool + Run(name string, f func(T)) bool Setenv(key string, value string) Skip(args ...any) diff --git a/tfversion/all_test.go b/tfversion/all_test.go index 21f51db65..aa7d34dba 100644 --- a/tfversion/all_test.go +++ b/tfversion/all_test.go @@ -21,7 +21,7 @@ func Test_All_RunTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -51,7 +51,7 @@ func Test_All_SkipTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.0.7") testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -84,7 +84,7 @@ func Test_All_Error(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil diff --git a/tfversion/any_test.go b/tfversion/any_test.go index 8a6ca7dea..ca1e9f339 100644 --- a/tfversion/any_test.go +++ b/tfversion/any_test.go @@ -21,7 +21,7 @@ func Test_Any_RunTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -48,7 +48,7 @@ func Test_Any_SkipTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -77,7 +77,7 @@ func Test_Any_Error(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil diff --git a/tfversion/require_above_test.go b/tfversion/require_above_test.go index c9a49427d..d86d92234 100644 --- a/tfversion/require_above_test.go +++ b/tfversion/require_above_test.go @@ -21,7 +21,7 @@ func Test_RequireAbove_Equal(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -46,7 +46,7 @@ func Test_RequireAbove_Higher(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.1") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -71,7 +71,7 @@ func Test_RequireAbove_Lower(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.0.7") testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -100,7 +100,7 @@ func Test_RequireAbove_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:para // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -121,7 +121,7 @@ func Test_RequireAbove_Prerelease_EqualPrerelease(t *testing.T) { //nolint:paral t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-rc1") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -146,7 +146,7 @@ func Test_RequireAbove_Prerelease_HigherCoreVersion(t *testing.T) { //nolint:par // ignore the core version of the prerelease version when compared against // the core version of the check. testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -169,7 +169,7 @@ func Test_RequireAbove_Prerelease_HigherPrerelease(t *testing.T) { //nolint:para // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -192,7 +192,7 @@ func Test_RequireAbove_Prerelease_LowerCoreVersion(t *testing.T) { //nolint:para // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -215,7 +215,7 @@ func Test_RequireAbove_Prerelease_LowerPrerelease(t *testing.T) { //nolint:paral // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, diff --git a/tfversion/require_below_test.go b/tfversion/require_below_test.go index 6c11ce7f2..fe109bd2d 100644 --- a/tfversion/require_below_test.go +++ b/tfversion/require_below_test.go @@ -21,7 +21,7 @@ func Test_RequireBelow_Equal(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.7.0") testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -42,7 +42,7 @@ func Test_RequireBelow_Lower(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.2.0") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -70,7 +70,7 @@ func Test_RequireBelow_Higher(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.4.0") testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -99,7 +99,7 @@ func Test_RequireBelow_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:para // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -124,7 +124,7 @@ func Test_RequireBelow_Prerelease_HigherCoreVersion(t *testing.T) { //nolint:par // ignore the core version of the prerelease version when compared against // the core version of the check. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -147,7 +147,7 @@ func Test_RequireBelow_Prerelease_HigherPrerelease(t *testing.T) { //nolint:para // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -170,7 +170,7 @@ func Test_RequireBelow_Prerelease_LowerCoreVersion(t *testing.T) { //nolint:para // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -193,7 +193,7 @@ func Test_RequireBelow_Prerelease_LowerPrerelease(t *testing.T) { //nolint:paral // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, diff --git a/tfversion/require_between_test.go b/tfversion/require_between_test.go index 737b91e53..796ea3c5d 100644 --- a/tfversion/require_between_test.go +++ b/tfversion/require_between_test.go @@ -21,7 +21,7 @@ func Test_RequireBetween(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.2.0") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -61,7 +61,7 @@ func Test_RequireBetween_Error_BelowMin(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -83,7 +83,7 @@ func Test_RequireBetween_Error_EqToMax(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.3.0") testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -112,7 +112,7 @@ func Test_RequireBetween_Prerelease_MaxEqualCoreVersion(t *testing.T) { //nolint // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -139,7 +139,7 @@ func Test_RequireBetween_Prerelease_MinEqualCoreVersion(t *testing.T) { //nolint // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -164,7 +164,7 @@ func Test_RequireBetween_Prerelease_MaxHigherCoreVersion(t *testing.T) { //nolin // ignore the core version of the prerelease version when compared against // the core version of the check. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -189,7 +189,7 @@ func Test_RequireBetween_Prerelease_MinHigherCoreVersion(t *testing.T) { //nolin // ignore the core version of the prerelease version when compared against // the core version of the check. testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -212,7 +212,7 @@ func Test_RequireBetween_Prerelease_MaxHigherPrerelease(t *testing.T) { //nolint // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -235,7 +235,7 @@ func Test_RequireBetween_Prerelease_MinHigherPrerelease(t *testing.T) { //nolint // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -258,7 +258,7 @@ func Test_RequireBetween_Prerelease_MaxLowerCoreVersion(t *testing.T) { //nolint // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -281,7 +281,7 @@ func Test_RequireBetween_Prerelease_MinLowerCoreVersion(t *testing.T) { //nolint // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -304,7 +304,7 @@ func Test_RequireBetween_Prerelease_MaxLowerPrerelease(t *testing.T) { //nolint: // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -327,7 +327,7 @@ func Test_RequireBetween_Prerelease_MinLowerPrerelease(t *testing.T) { //nolint: // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, diff --git a/tfversion/require_not_test.go b/tfversion/require_not_test.go index e2ea10435..aaaa8f64e 100644 --- a/tfversion/require_not_test.go +++ b/tfversion/require_not_test.go @@ -21,7 +21,7 @@ func Test_RequireNot(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.4.3") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -42,7 +42,7 @@ func Test_RequireNot_Error(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -71,7 +71,7 @@ func Test_RequireNot_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:parall // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 testingiface.ExpectFail(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -96,7 +96,7 @@ func Test_RequireNot_Prerelease_HigherCoreVersion(t *testing.T) { //nolint:paral // ignore the core version of the prerelease version when compared against // the core version of the check. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -119,7 +119,7 @@ func Test_RequireNot_Prerelease_HigherPrerelease(t *testing.T) { //nolint:parall // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -142,7 +142,7 @@ func Test_RequireNot_Prerelease_LowerCoreVersion(t *testing.T) { //nolint:parall // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -165,7 +165,7 @@ func Test_RequireNot_Prerelease_LowerPrerelease(t *testing.T) { //nolint:paralle // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, diff --git a/tfversion/skip_above_test.go b/tfversion/skip_above_test.go index 61fe7e015..bf7127786 100644 --- a/tfversion/skip_above_test.go +++ b/tfversion/skip_above_test.go @@ -21,7 +21,7 @@ func Test_SkipAbove_Lower(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.3.0") testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -49,7 +49,7 @@ func Test_SkipAbove_Equal(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.2.9") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -77,7 +77,7 @@ func Test_SkipAbove_Higher(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.7.1") testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -106,7 +106,7 @@ func Test_SkipAbove_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:paralle // Invert testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -127,7 +127,7 @@ func Test_SkipAbove_Prerelease_EqualPrerelease(t *testing.T) { //nolint:parallel t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-rc1") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -153,7 +153,7 @@ func Test_SkipAbove_Prerelease_HigherCoreVersion(t *testing.T) { //nolint:parall // the core version of the check. // Want Pass testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -177,7 +177,7 @@ func Test_SkipAbove_Prerelease_HigherPrerelease(t *testing.T) { //nolint:paralle // below the 1.7.0-rc2 prerelease. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -201,7 +201,7 @@ func Test_SkipAbove_Prerelease_LowerCoreVersion(t *testing.T) { //nolint:paralle // above the 1.7.0 core version. // Want Pass testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -225,7 +225,7 @@ func Test_SkipAbove_Prerelease_LowerPrerelease(t *testing.T) { //nolint:parallel // above the 1.8.0-beta1 prerelease. testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, diff --git a/tfversion/skip_below_test.go b/tfversion/skip_below_test.go index 3eea90dc1..53ac40df2 100644 --- a/tfversion/skip_below_test.go +++ b/tfversion/skip_below_test.go @@ -21,7 +21,7 @@ func Test_SkipBelow_Lower(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.0.7") testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -48,7 +48,7 @@ func Test_SkipBelow_Equal(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -73,7 +73,7 @@ func Test_SkipBelow_Higher(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.1") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -104,7 +104,7 @@ func Test_SkipBelow_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:paralle // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -125,7 +125,7 @@ func Test_SkipBelow_Prerelease_EqualPrerelease(t *testing.T) { //nolint:parallel t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-rc1") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -150,7 +150,7 @@ func Test_SkipBelow_Prerelease_HigherCoreVersion(t *testing.T) { //nolint:parall // ignore the core version of the prerelease version when compared against // the core version of the check. testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -173,7 +173,7 @@ func Test_SkipBelow_Prerelease_HigherPrerelease(t *testing.T) { //nolint:paralle // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -196,7 +196,7 @@ func Test_SkipBelow_Prerelease_LowerCoreVersion(t *testing.T) { //nolint:paralle // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -219,7 +219,7 @@ func Test_SkipBelow_Prerelease_LowerPrerelease(t *testing.T) { //nolint:parallel // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, diff --git a/tfversion/skip_between_test.go b/tfversion/skip_between_test.go index b91d64ff0..36e234287 100644 --- a/tfversion/skip_between_test.go +++ b/tfversion/skip_between_test.go @@ -21,7 +21,7 @@ func Test_SkipBetween_SkipTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.2.0") testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -61,7 +61,7 @@ func Test_SkipBetween_RunTest_AboveMax(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.3.0") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -82,7 +82,7 @@ func Test_SkipBetween_RunTest_EqToMin(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.2.0") testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -109,7 +109,7 @@ func Test_SkipBetween_Prerelease_MaxEqualCoreVersion(t *testing.T) { //nolint:pa // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -136,7 +136,7 @@ func Test_SkipBetween_Prerelease_MinEqualCoreVersion(t *testing.T) { //nolint:pa // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -161,7 +161,7 @@ func Test_SkipBetween_Prerelease_MaxHigherCoreVersion(t *testing.T) { //nolint:p // ignore the core version of the prerelease version when compared against // the core version of the check. testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -186,7 +186,7 @@ func Test_SkipBetween_Prerelease_MinHigherCoreVersion(t *testing.T) { //nolint:p // ignore the core version of the prerelease version when compared against // the core version of the check. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -209,7 +209,7 @@ func Test_SkipBetween_Prerelease_MaxHigherPrerelease(t *testing.T) { //nolint:pa // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -232,7 +232,7 @@ func Test_SkipBetween_Prerelease_MinHigherPrerelease(t *testing.T) { //nolint:pa // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -255,7 +255,7 @@ func Test_SkipBetween_Prerelease_MaxLowerCoreVersion(t *testing.T) { //nolint:pa // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -278,7 +278,7 @@ func Test_SkipBetween_Prerelease_MinLowerCoreVersion(t *testing.T) { //nolint:pa // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -301,7 +301,7 @@ func Test_SkipBetween_Prerelease_MaxLowerPrerelease(t *testing.T) { //nolint:par // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -324,7 +324,7 @@ func Test_SkipBetween_Prerelease_MinLowerPrerelease(t *testing.T) { //nolint:par // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, diff --git a/tfversion/skip_if_not_alpha_test.go b/tfversion/skip_if_not_alpha_test.go index 7da9cfcf3..e1238dc08 100644 --- a/tfversion/skip_if_not_alpha_test.go +++ b/tfversion/skip_if_not_alpha_test.go @@ -20,7 +20,7 @@ func Test_SkipIfNotAlpha_SkipTest_Stable(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0") testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -43,7 +43,7 @@ func Test_SkipIfNotAlpha_SkipTest_Beta1(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-beta1") testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -63,7 +63,7 @@ func Test_SkipIfNotAlpha_SkipTest_RC(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-rc2") testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -84,7 +84,7 @@ func Test_SkipIfNotAlpha_RunTest_Alpha(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.9.0-alpha20240501") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, diff --git a/tfversion/skip_if_not_prerelease_test.go b/tfversion/skip_if_not_prerelease_test.go index b84b9167f..533226327 100644 --- a/tfversion/skip_if_not_prerelease_test.go +++ b/tfversion/skip_if_not_prerelease_test.go @@ -22,7 +22,7 @@ func Test_SkipIfNotPrerelease_SkipTest_Stable(t *testing.T) { //nolint:parallelt t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0") testingiface.ExpectSkip(t, func(mockT *testinginterface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -45,7 +45,7 @@ func Test_SkipIfNotPrerelease_RunTest_Alpha(t *testing.T) { //nolint:paralleltes t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.9.0-alpha20240501") testingiface.ExpectPass(t, func(mockT *testinginterface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -66,7 +66,7 @@ func Test_SkipIfNotPrerelease_RunTest_Beta1(t *testing.T) { //nolint:paralleltes t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-beta1") testingiface.ExpectPass(t, func(mockT *testinginterface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -86,7 +86,7 @@ func Test_SkipIfNotPrerelease_RunTest_RC(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-rc2") testingiface.ExpectPass(t, func(mockT *testinginterface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, diff --git a/tfversion/skip_if_test.go b/tfversion/skip_if_test.go index 5da7ebc84..12c011ef8 100644 --- a/tfversion/skip_if_test.go +++ b/tfversion/skip_if_test.go @@ -21,7 +21,7 @@ func Test_SkipIf_SkipTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.4.3") testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -44,7 +44,7 @@ func Test_SkipIf_RunTest(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -71,7 +71,7 @@ func Test_SkipIf_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:parallelte // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 testingiface.ExpectSkip(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -96,7 +96,7 @@ func Test_SkipIf_Prerelease_HigherCoreVersion(t *testing.T) { //nolint:parallelt // ignore the core version of the prerelease version when compared against // the core version of the check. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -119,7 +119,7 @@ func Test_SkipIf_Prerelease_HigherPrerelease(t *testing.T) { //nolint:parallelte // The 1.7.0-rc1 prerelease should always be considered to be // below the 1.7.0-rc2 prerelease. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -142,7 +142,7 @@ func Test_SkipIf_Prerelease_LowerCoreVersion(t *testing.T) { //nolint:parallelte // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.7.0 core version. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -165,7 +165,7 @@ func Test_SkipIf_Prerelease_LowerPrerelease(t *testing.T) { //nolint:paralleltes // The 1.8.0-rc1 prerelease should always be considered to be // above the 1.8.0-beta1 prerelease. testingiface.ExpectPass(t, func(mockT *testingiface.MockT) { - r.UnitTest(mockT, r.TestCase{ + r.UnitTestT(mockT, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), },