diff --git a/go.mod b/go.mod index 2d304ebc0..cdf2bdf8d 100644 --- a/go.mod +++ b/go.mod @@ -10,11 +10,10 @@ require ( github.com/hashicorp/go-version v1.7.0 github.com/hashicorp/hc-install v0.9.2 github.com/hashicorp/hcl/v2 v2.24.0 - github.com/hashicorp/logutils v1.0.0 github.com/hashicorp/terraform-exec v0.24.0 github.com/hashicorp/terraform-json v0.27.2 github.com/hashicorp/terraform-plugin-go v0.29.0 - github.com/hashicorp/terraform-plugin-log v0.9.0 + github.com/hashicorp/terraform-plugin-log v0.10.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.1 github.com/mitchellh/go-testing-interface v1.14.1 github.com/zclconf/go-cty v1.17.0 @@ -34,6 +33,7 @@ require ( github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-plugin v1.7.0 // indirect github.com/hashicorp/go-retryablehttp v0.7.7 // indirect + github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/terraform-registry-address v0.4.0 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/yamux v0.1.2 // indirect diff --git a/go.sum b/go.sum index 4a9a91b75..84193f33f 100644 --- a/go.sum +++ b/go.sum @@ -83,8 +83,8 @@ github.com/hashicorp/terraform-json v0.27.2 h1:BwGuzM6iUPqf9JYM/Z4AF1OJ5VVJEEzoK github.com/hashicorp/terraform-json v0.27.2/go.mod h1:GzPLJ1PLdUG5xL6xn1OXWIjteQRT2CNT9o/6A9mi9hE= github.com/hashicorp/terraform-plugin-go v0.29.0 h1:1nXKl/nSpaYIUBU1IG/EsDOX0vv+9JxAltQyDMpq5mU= github.com/hashicorp/terraform-plugin-go v0.29.0/go.mod h1:vYZbIyvxyy0FWSmDHChCqKvI40cFTDGSb3D8D70i9GM= -github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= -github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= +github.com/hashicorp/terraform-plugin-log v0.10.0 h1:eu2kW6/QBVdN4P3Ju2WiB2W3ObjkAsyfBsL3Wh1fj3g= +github.com/hashicorp/terraform-plugin-log v0.10.0/go.mod h1:/9RR5Cv2aAbrqcTSdNmY1NRHP4E3ekrXRGjqORpXyB0= github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.1 h1:mlAq/OrMlg04IuJT7NpefI1wwtdpWudnEmjuQs04t/4= github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.1/go.mod h1:GQhpKVvvuwzD79e8/NZ+xzj+ZpWovdPAe8nfV/skwNU= github.com/hashicorp/terraform-registry-address v0.4.0 h1:S1yCGomj30Sao4l5BMPjTGZmCNzuv7/GDTDX99E9gTk= diff --git a/helper/logging/logging.go b/helper/logging/logging.go deleted file mode 100644 index c13453e49..000000000 --- a/helper/logging/logging.go +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package logging - -import ( - "fmt" - "io" - "log" - "os" - "strings" - "syscall" - - "github.com/hashicorp/logutils" - "github.com/mitchellh/go-testing-interface" -) - -// These are the environmental variables that determine if we log, and if -// we log whether or not the log should go to a file. -const ( - EnvLog = "TF_LOG" // See ValidLevels - EnvLogFile = "TF_LOG_PATH" // Set to a file - EnvAccLogFile = "TF_ACC_LOG_PATH" // Set to a file - // EnvLogPathMask splits test log files by name. - EnvLogPathMask = "TF_LOG_PATH_MASK" -) - -var ValidLevels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"} - -// LogOutput determines where we should send logs (if anywhere) and the log -// level. This only effects this log.Print* functions called in the provider -// under test. Dependency providers for the provider under test will have their -// 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) { - logOutput = io.Discard - - logLevel := LogLevel() - if logLevel == "" { - if os.Getenv(EnvAccLogFile) != "" { - // plugintest defaults to TRACE when TF_ACC_LOG_PATH is - // set for Terraform and dependency providers of the - // provider under test. We should do the same for the - // provider under test. - logLevel = "TRACE" - } else { - return - } - } - - logOutput = os.Stderr - if logPath := os.Getenv(EnvLogFile); logPath != "" { - var err error - logOutput, err = os.OpenFile(logPath, syscall.O_CREAT|syscall.O_RDWR|syscall.O_APPEND, 0666) - if err != nil { - return nil, err - } - } - - if logPath := os.Getenv(EnvAccLogFile); logPath != "" { - var err error - logOutput, err = os.OpenFile(logPath, syscall.O_CREAT|syscall.O_RDWR|syscall.O_APPEND, 0666) - if err != nil { - return nil, err - } - } - - if logPathMask := os.Getenv(EnvLogPathMask); logPathMask != "" { - // Escape special characters which may appear if we have subtests - testName := strings.Replace(t.Name(), "/", "__", -1) - - logPath := fmt.Sprintf(logPathMask, testName) - var err error - logOutput, err = os.OpenFile(logPath, syscall.O_CREAT|syscall.O_RDWR|syscall.O_APPEND, 0666) - if err != nil { - return nil, err - } - } - - // This was the default since the beginning - logOutput = &logutils.LevelFilter{ - Levels: ValidLevels, - MinLevel: logutils.LogLevel(logLevel), - Writer: logOutput, - } - - return -} - -// 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) { - out, err := LogOutput(t) - if err != nil { - log.Fatal(err) - } - - if out == nil { - out = io.Discard - } - - log.SetOutput(out) -} - -// LogLevel returns the current log level string based the environment vars -func LogLevel() string { - envLevel := os.Getenv(EnvLog) - if envLevel == "" { - return "" - } - - logLevel := "TRACE" - if isValidLogLevel(envLevel) { - // allow following for better ux: info, Info or INFO - logLevel = strings.ToUpper(envLevel) - } else { - log.Printf("[WARN] Invalid log level: %q. Defaulting to level: TRACE. Valid levels are: %+v", - envLevel, ValidLevels) - } - - return logLevel -} - -// IsDebugOrHigher returns whether or not the current log level is debug or trace -func IsDebugOrHigher() bool { - level := LogLevel() - return level == "DEBUG" || level == "TRACE" -} - -func isValidLogLevel(level string) bool { - for _, l := range ValidLevels { - if strings.ToUpper(level) == string(l) { - return true - } - } - - return false -} diff --git a/helper/resource/plan_checks.go b/helper/resource/plan_checks.go index c64c02ba8..a6f01222f 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/testing/hack" "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 hack.BaseT, 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 86c3b77ba..c7db1ef2e 100644 --- a/helper/resource/plugin.go +++ b/helper/resource/plugin.go @@ -18,10 +18,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/testing/hack" ) // protov5ProviderFactory is a function which is called to start a protocol @@ -114,7 +114,7 @@ type providerFactories struct { protov6 protov6ProviderFactories } -func runProviderCommandApplyRefreshOnly(ctx context.Context, t testing.T, wd *plugintest.WorkingDir, factories *providerFactories) error { +func runProviderCommandApplyRefreshOnly(ctx context.Context, t hack.BaseT, wd *plugintest.WorkingDir, factories *providerFactories) error { t.Helper() fn := func() error { @@ -123,7 +123,7 @@ func runProviderCommandApplyRefreshOnly(ctx context.Context, t testing.T, wd *pl return runProviderCommand(ctx, t, wd, factories, fn) } -func runProviderCommandCreatePlan(ctx context.Context, t testing.T, wd *plugintest.WorkingDir, factories *providerFactories) error { +func runProviderCommandCreatePlan(ctx context.Context, t hack.BaseT, wd *plugintest.WorkingDir, factories *providerFactories) error { t.Helper() fn := func() error { @@ -132,7 +132,7 @@ func runProviderCommandCreatePlan(ctx context.Context, t testing.T, wd *pluginte return runProviderCommand(ctx, t, wd, factories, fn) } -func runProviderCommandSavedPlan(ctx context.Context, t testing.T, wd *plugintest.WorkingDir, factories *providerFactories) (*tfjson.Plan, error) { +func runProviderCommandSavedPlan(ctx context.Context, t hack.BaseT, wd *plugintest.WorkingDir, factories *providerFactories) (*tfjson.Plan, error) { t.Helper() var plan *tfjson.Plan @@ -149,7 +149,7 @@ func runProviderCommandSavedPlan(ctx context.Context, t testing.T, wd *plugintes return plan, nil } -func runProviderCommand(ctx context.Context, t testing.T, wd *plugintest.WorkingDir, factories *providerFactories, f func() error) error { +func runProviderCommand(ctx context.Context, t hack.BaseT, wd *plugintest.WorkingDir, factories *providerFactories, f func() error) error { // don't point to this as a test failure location // point to whatever called it t.Helper() diff --git a/helper/resource/query/query_checks.go b/helper/resource/query/query_checks.go index 8ef9a3e09..6f4481d62 100644 --- a/helper/resource/query/query_checks.go +++ b/helper/resource/query/query_checks.go @@ -9,12 +9,12 @@ import ( "fmt" tfjson "github.com/hashicorp/terraform-json" - "github.com/mitchellh/go-testing-interface" + "github.com/hashicorp/terraform-plugin-testing/internal/testing/hack" "github.com/hashicorp/terraform-plugin-testing/querycheck" ) -func RunQueryChecks(ctx context.Context, t testing.T, query []tfjson.LogMsg, queryChecks []querycheck.QueryResultCheck) error { +func RunQueryChecks(ctx context.Context, t hack.BaseT, query []tfjson.LogMsg, queryChecks []querycheck.QueryResultCheck) error { t.Helper() var result []error diff --git a/helper/resource/state_checks.go b/helper/resource/state_checks.go index 66c850eae..fefab0a14 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/testing/hack" "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 hack.BaseT, 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..a2c39b7b3 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/testing/hack" "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 hack.BaseT) error { logging.HelperResourceTrace(ctx, "Validating TestCase") if len(c.Steps) == 0 { diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 4ba1961bf..468aafd39 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -17,7 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/querycheck" - "github.com/mitchellh/go-testing-interface" + testing "github.com/hashicorp/terraform-plugin-testing/internal/testing/hack" "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-go/tfprotov6" @@ -887,7 +887,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 testing.BaseT, c TestCase) { t.Helper() t.Parallel() Test(t, c) @@ -899,7 +899,7 @@ func ParallelTest(t testing.T, c TestCase) { // set to some non-empty value. This is to avoid test cases surprising // a user by creating real resources. // -// Use the ParallelTest() function to automatically set (*testing.T).Parallel() +// Use the ParallelTest() function to automatically set (*testing.BaseT).Parallel() // to enable testing concurrency. Use the UnitTest() function to automatically // set the TestCase type IsUnitTest field. // @@ -919,7 +919,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 testing.BaseT, c TestCase) { t.Helper() ctx := context.Background() @@ -999,7 +999,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 testing.BaseT, c TestCase) { t.Helper() c.IsUnitTest = true diff --git a/helper/resource/testing_new.go b/helper/resource/testing_new.go index 0faf05892..89f7dcd82 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/testing/hack" "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 hack.BaseT, c TestCase, wd *plugintest.WorkingDir, providers *providerFactories, statePreDestroy *terraform.State) error { t.Helper() err := runProviderCommand(ctx, t, wd, providers, 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 hack.BaseT, c TestCase, helper *plugintest.Helper) { t.Helper() wd := helper.RequireNewWorkingDir(ctx, t, c.WorkingDir) @@ -492,7 +492,7 @@ func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest } } -func getState(ctx context.Context, t testing.T, wd *plugintest.WorkingDir) (*tfjson.State, *terraform.State, error) { +func getState(ctx context.Context, t hack.BaseT, wd *plugintest.WorkingDir) (*tfjson.State, *terraform.State, error) { t.Helper() jsonState, err := wd.State(ctx) @@ -532,7 +532,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 hack.BaseT, 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 @@ -674,7 +674,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 hack.BaseT, 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 1145c8e4e..58b06c2e0 100644 --- a/helper/resource/testing_new_config.go +++ b/helper/resource/testing_new_config.go @@ -11,9 +11,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/testing/hack" "github.com/hashicorp/terraform-plugin-testing/internal/teststep" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-plugin-testing/tfversion" @@ -27,7 +27,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 hack.BaseT, c TestCase, wd *plugintest.WorkingDir, step TestStep, providers *providerFactories, stepIndex int, helper *plugintest.Helper) error { t.Helper() // When `refreshAfterApply` is true, a `Config`-mode test step will invoke diff --git a/helper/resource/testing_new_import_state.go b/helper/resource/testing_new_import_state.go index d2d71311c..bb1ccb895 100644 --- a/helper/resource/testing_new_import_state.go +++ b/helper/resource/testing_new_import_state.go @@ -15,17 +15,17 @@ import ( tfjson "github.com/hashicorp/terraform-json" "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/logging" "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" + "github.com/hashicorp/terraform-plugin-testing/internal/testing/hack" "github.com/hashicorp/terraform-plugin-testing/internal/teststep" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) -func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest.Helper, testCaseWorkingDir *plugintest.WorkingDir, step TestStep, priorStepCfg teststep.Config, providers *providerFactories, stepNumber int) error { +func testStepNewImportState(ctx context.Context, t hack.BaseT, helper *plugintest.Helper, testCaseWorkingDir *plugintest.WorkingDir, step TestStep, priorStepCfg teststep.Config, providers *providerFactories, stepNumber int) error { t.Helper() // step.ImportStateKind implicitly defaults to the zero-value (ImportCommandWithID) for backward compatibility @@ -183,7 +183,7 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest } } -func testImportBlock(ctx context.Context, t testing.T, workingDir *plugintest.WorkingDir, providers *providerFactories, resourceName string, step TestStep, priorIdentityValues map[string]any) error { +func testImportBlock(ctx context.Context, t hack.BaseT, workingDir *plugintest.WorkingDir, providers *providerFactories, resourceName string, step TestStep, priorIdentityValues map[string]any) error { kind := step.ImportStateKind err := runProviderCommandCreatePlan(ctx, t, workingDir, providers) @@ -242,7 +242,7 @@ func testImportBlock(ctx context.Context, t testing.T, workingDir *plugintest.Wo return nil } -func testImportCommand(ctx context.Context, t testing.T, workingDir *plugintest.WorkingDir, providers *providerFactories, resourceName string, importId string, step TestStep, state *terraform.State) error { +func testImportCommand(ctx context.Context, t hack.BaseT, workingDir *plugintest.WorkingDir, providers *providerFactories, resourceName string, importId string, step TestStep, state *terraform.State) error { err := runProviderCommand(ctx, t, workingDir, providers, func() error { return workingDir.Import(ctx, resourceName, importId) }) @@ -463,7 +463,7 @@ func appendImportBlockWithIdentity(config teststep.Config, resourceName string, return config.Append(configBuilder.String()) } -func importStatePreconditions(t testing.T, helper *plugintest.Helper, step TestStep) error { +func importStatePreconditions(t hack.BaseT, helper *plugintest.Helper, step TestStep) error { t.Helper() kind := step.ImportStateKind @@ -526,7 +526,7 @@ func identityValuesFromStateValues(stateValues *tfjson.StateValues, resourceName return resource.IdentityValues } -func runImportStateCheckFunction(ctx context.Context, t testing.T, importState *terraform.State, step TestStep) { +func runImportStateCheckFunction(ctx context.Context, t hack.BaseT, importState *terraform.State, step TestStep) { t.Helper() var states []*terraform.InstanceState @@ -553,7 +553,7 @@ func runImportStateCheckFunction(ctx context.Context, t testing.T, importState * logging.HelperResourceTrace(ctx, "Called TestStep ImportStateCheck") } -func savedPlanRawStdout(ctx context.Context, t testing.T, wd *plugintest.WorkingDir, providers *providerFactories) string { +func savedPlanRawStdout(ctx context.Context, t hack.BaseT, wd *plugintest.WorkingDir, providers *providerFactories) string { t.Helper() var stdout string diff --git a/helper/resource/testing_new_query.go b/helper/resource/testing_new_query.go index c8961f943..29e17ef87 100644 --- a/helper/resource/testing_new_query.go +++ b/helper/resource/testing_new_query.go @@ -8,14 +8,14 @@ import ( "fmt" tfjson "github.com/hashicorp/terraform-json" - "github.com/mitchellh/go-testing-interface" "github.com/hashicorp/terraform-plugin-testing/helper/resource/query" "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" + "github.com/hashicorp/terraform-plugin-testing/internal/testing/hack" "github.com/hashicorp/terraform-plugin-testing/internal/teststep" ) -func testStepNewQuery(ctx context.Context, t testing.T, wd *plugintest.WorkingDir, step TestStep, providers *providerFactories) error { +func testStepNewQuery(ctx context.Context, t hack.BaseT, wd *plugintest.WorkingDir, step TestStep, providers *providerFactories) error { t.Helper() queryConfigRequest := teststep.ConfigurationRequest{ diff --git a/helper/resource/testing_new_refresh_state.go b/helper/resource/testing_new_refresh_state.go index b1971a289..a131b21db 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/testing/hack" ) -func testStepNewRefreshState(ctx context.Context, t testing.T, wd *plugintest.WorkingDir, step TestStep, providers *providerFactories) error { +func testStepNewRefreshState(ctx context.Context, t hack.BaseT, wd *plugintest.WorkingDir, step TestStep, providers *providerFactories) error { t.Helper() var err error diff --git a/helper/resource/testing_test.go b/helper/resource/testing_test.go index cfd8afcff..32d54dcd2 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/testing/hack" "github.com/hashicorp/terraform-plugin-testing/terraform" ) @@ -133,7 +133,7 @@ func TestComposeTestCheckFunc(t *testing.T) { // mockT implements TestT for testing type mockT struct { - testinginterface.RuntimeT + hack.MetaT ParallelCalled bool } diff --git a/helper/resource/tfversion_checks.go b/helper/resource/tfversion_checks.go index 1bec0abd6..9c5b59931 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/testing/hack" "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 hack.BaseT, terraformVersion *version.Version, terraformVersionChecks []tfversion.TerraformVersionCheck) { t.Helper() for _, tfVersionCheck := range terraformVersionChecks { diff --git a/helper/resource/tfversion_checks_test.go b/helper/resource/tfversion_checks_test.go index 6410bc732..6834de78a 100644 --- a/helper/resource/tfversion_checks_test.go +++ b/helper/resource/tfversion_checks_test.go @@ -10,9 +10,8 @@ import ( "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" + "github.com/hashicorp/terraform-plugin-testing/internal/testing/hack" "github.com/hashicorp/terraform-plugin-testing/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func TestRunTFVersionChecks(t *testing.T) { @@ -53,7 +52,7 @@ func TestRunTFVersionChecks(t *testing.T) { if test.expectError { plugintest.TestExpectTFatal(t, func() { - runTFVersionChecks(context.Background(), &testinginterface.RuntimeT{}, test.tfVersion, test.versionChecks) + runTFVersionChecks(context.Background(), &hack.MetaT{}, test.tfVersion, test.versionChecks) }) } else { runTFVersionChecks(context.Background(), t, test.tfVersion, test.versionChecks) diff --git a/internal/logging/context.go b/internal/logging/context.go index 5a3108451..a84d646ff 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/testing/hack" ) // InitTestContext registers the terraform-plugin-log/tfsdklog test sink, @@ -18,10 +18,10 @@ import ( // 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 hack.BaseT) context.Context { helperlogging.SetOutput(t) - ctx = tfsdklog.RegisterTestSink(ctx, t) + ctx = tfsdklog.ContextWithTestLogging(ctx, t.Name()) ctx = tfsdklog.NewRootSDKLogger(ctx, tfsdklog.WithLevelFromEnv(EnvTfLogSdk)) ctx = tfsdklog.NewSubsystem(ctx, SubsystemHelperResource, // All calls are through the HelperResource* helper functions diff --git a/internal/testing/hack/t.go b/internal/testing/hack/t.go new file mode 100644 index 000000000..d41213fdd --- /dev/null +++ b/internal/testing/hack/t.go @@ -0,0 +1,205 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package hack + +import ( + "context" + "fmt" + "io" + "testing" + "time" +) + +// BaseT is a replacement for github.com/mitchellh/go-testing-interface.T. +// +// RuntimeT and StandardT are two implementations of BaseT. MetaT can be used +// to test a testing.T-based test framework without the side effects of +// stopping goroutine execution. StandardT can be used as an adapter around a +// standard testing.T. +// +// Precedent for StandardT: the unexported tshim type in +// github.com/rogpeppe/go-internal/testscript. +type BaseT interface { + Cleanup(func()) + Error(args ...interface{}) + Errorf(format string, args ...interface{}) + Fail() + FailNow() + Failed() bool + Fatal(args ...interface{}) + Fatalf(format string, args ...interface{}) + Helper() + Log(args ...interface{}) + Logf(format string, args ...interface{}) + Name() string + Parallel() + Skip(args ...interface{}) + SkipNow() + Skipf(format string, args ...interface{}) + Skipped() bool + + // Not in mitchellh/go-testing-interface + Attr(key, value string) + Chdir(dir string) + Context() context.Context + Deadline() (deadline time.Time, ok bool) + Output() io.Writer + Setenv(key, value string) + TempDir() string +} + +var _ BaseT = MetaT{} + +type MetaT struct { + fail bool + skip bool +} + +// Attr satisfies [BaseT] and does nothing. +func (t MetaT) Attr(key string, value string) { +} + +// Chdir satisfies [BaseT] and does nothing. +func (r MetaT) Chdir(dir string) { +} + +// Cleanup satisfies [BaseT] and does nothing. +func (r MetaT) Cleanup(_ func()) { +} + +// Context satisfies [BaseT] and returns context.TODO() +func (r MetaT) Context() context.Context { + return context.TODO() +} + +// Deadline satisfies [BaseT] and returns zero-values. +func (r MetaT) Deadline() (deadline time.Time, ok bool) { + return time.Time{}, false +} + +// Error is equivalent to Log followed by Fail. +func (t MetaT) Error(args ...interface{}) { + t.Log(args) + t.Fail() +} + +// Errorf is equivalent to Logf followed by Fail. +func (t MetaT) Errorf(format string, args ...interface{}) { + t.Logf(format, args...) + t.Fail() +} + +// Fail marks the function as having failed but continues execution. +func (t MetaT) Fail() { + t.fail = true +} + +// Failed reports whether the function has failed. +func (t MetaT) Failed() bool { + return t.fail +} + +// FailNow marks the function as having failed and stops its execution by +// calling panic(). +// +// For compatibility, it mimics the string argument from +// mitchellg/go-testing-interface. +func (t MetaT) FailNow() { + panic("testing.T failed, see logs for output") +} + +// Fatal is equivalent to Log followed by FailNow. +func (t MetaT) Fatal(args ...interface{}) { + t.Log(args) + t.FailNow() +} + +// Fatalf is equivalent to Logf followed by FailNow. +func (t MetaT) Fatalf(format string, args ...interface{}) { + t.Logf(format, args...) + t.FailNow() +} + +// Log formats its arguments using default formatting, analogous to +// fmt.Println,, and records the text to standard output. +func (t MetaT) Log(args ...interface{}) { + fmt.Println(fmt.Sprintf("%v", args)) +} + +// Logf formats its arguments according to the format, analogous to fmt.Printf, +// and records the text to standard output. +func (t MetaT) Logf(format string, args ...interface{}) { + fmt.Println(fmt.Sprintf(format, args...)) +} + +// Helper satisfies [BaseT] and does nothing. +func (r MetaT) Helper() { +} + +// Name satisfies [BaseT] and returns an empty string. +func (r MetaT) Name() string { + return "" +} + +// Output satisfied [BaseT] and returns io.Discard. +func (r MetaT) Output() io.Writer { + return io.Discard +} + +// Parallel satisfies [BaseT] and does nothing. +func (r MetaT) Parallel() { + panic("parallel not implemented") // TODO: Implement +} + +// Setenv satisfies [BaseT] and does nothing. +func (r MetaT) Setenv(key string, value string) { +} + +// SkipNow marks the test as having been skipped. +// +// As a practical consideration, this does not stop execution in the way that +// [testing.T.SkipNow] does -- RuntimeT.Run does not run its function in a +// separate goroutine. +func (t MetaT) SkipNow() { + t.Skip() +} + +// Skipf is equivalent to Logf followed by SkipNow. +func (t MetaT) Skipf(format string, args ...interface{}) { + t.Logf(format, args...) + t.Skip() +} + +// TempDir satisfies [BaseT] and returns "/dev/null". +func (r MetaT) TempDir() string { + return "/dev/null" +} + +// Skip is equivalent to Log followed by SkipNow. +func (t MetaT) Skip(args ...interface{}) { + t.Log(args) + t.skip = true +} + +// Skipped reports whether the test was skipped. +func (t MetaT) Skipped() bool { + return t.skip +} + +var _ BaseT = StandardT{} + +// StandardT embeds a [testing.T] and satisfies [BaseT]. +type StandardT struct { + *testing.T +} + +// Run runs f as a subtest of t. +// +// As practical consideration, this does nsot run its function in a separate +// goroutine and the name is not used. +func (t StandardT) Run(name string, f func(BaseT)) bool { + return t.T.Run(name, func(t *testing.T) { + f(StandardT{t}) + }) +} diff --git a/tfversion/all_test.go b/tfversion/all_test.go index aa326d6bf..6f77814b3 100644 --- a/tfversion/all_test.go +++ b/tfversion/all_test.go @@ -8,10 +8,10 @@ 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/hack" "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/tfversion" @@ -81,7 +81,7 @@ func Test_All_Error(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, 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..1e55205f5 100644 --- a/tfversion/any_test.go +++ b/tfversion/any_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-go/tfprotov6" - testinginterface "github.com/mitchellh/go-testing-interface" + "github.com/hashicorp/terraform-plugin-testing/internal/testing/hack" r "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/internal/plugintest" @@ -46,27 +46,33 @@ 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 + var innerTest *testing.T + t.Run("a test that should be skipped", func(tt *testing.T) { + innerTest = tt + r.UnitTest(tt, 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 - ), - }, - Steps: []r.TestStep{ - { - Config: `variable "a" { + 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" { nullable = true default = "hello" }`, + }, }, - }, + }) }) + + mustSkip(innerTest) } func Test_Any_Error(t *testing.T) { //nolint:paralleltest @@ -74,7 +80,7 @@ func Test_Any_Error(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -95,3 +101,15 @@ func Test_Any_Error(t *testing.T) { //nolint:paralleltest }) }) } + +func mustSkip(t *testing.T) { + if !t.Skipped() { + t.Fatal("expected test to be skipped; it was not skipped") + } +} + +func mustNotSkip(t *testing.T) { + if t.Skipped() { + t.Fatal("expected test not to be skipped; it was skipped") + } +} diff --git a/tfversion/require_above_test.go b/tfversion/require_above_test.go index 8e8c3ea8e..d5f89f8da 100644 --- a/tfversion/require_above_test.go +++ b/tfversion/require_above_test.go @@ -11,11 +11,10 @@ import ( 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/hack" "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/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_RequireAbove_Equal(t *testing.T) { //nolint:paralleltest @@ -69,7 +68,7 @@ func Test_RequireAbove_Lower(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.0.7") plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -140,7 +139,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. plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -163,7 +162,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. plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, 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..ca29c82d5 100644 --- a/tfversion/require_below_test.go +++ b/tfversion/require_below_test.go @@ -11,11 +11,10 @@ import ( 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/hack" "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/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_RequireBelow_Equal(t *testing.T) { //nolint:paralleltest @@ -23,7 +22,7 @@ func Test_RequireBelow_Equal(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.7.0") plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -70,7 +69,7 @@ func Test_RequireBelow_Higher(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.4.0") plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -99,7 +98,7 @@ func Test_RequireBelow_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:para // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -166,7 +165,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. plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -189,7 +188,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. plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, 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..5980c9efd 100644 --- a/tfversion/require_between_test.go +++ b/tfversion/require_between_test.go @@ -11,11 +11,10 @@ import ( 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/hack" "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/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_RequireBetween(t *testing.T) { //nolint:paralleltest @@ -61,7 +60,7 @@ func Test_RequireBetween_Error_BelowMin(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -83,7 +82,7 @@ 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{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -112,7 +111,7 @@ func Test_RequireBetween_Prerelease_MaxEqualCoreVersion(t *testing.T) { //nolint // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -185,7 +184,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. plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -229,7 +228,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. plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -252,7 +251,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. plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -296,7 +295,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. plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, 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..66b195eee 100644 --- a/tfversion/require_not_test.go +++ b/tfversion/require_not_test.go @@ -11,11 +11,10 @@ import ( 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/hack" "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/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_RequireNot(t *testing.T) { //nolint:paralleltest @@ -42,7 +41,7 @@ func Test_RequireNot_Error(t *testing.T) { //nolint:paralleltest t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.1.0") plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature return nil, nil @@ -71,7 +70,7 @@ func Test_RequireNot_Prerelease_EqualCoreVersion(t *testing.T) { //nolint:parall // // Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/303 plugintest.TestExpectTFatal(t, func() { - r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ + r.UnitTest(&hack.MetaT{}, 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 35ced5279..b351c90ba 100644 --- a/tfversion/skip_between_test.go +++ b/tfversion/skip_between_test.go @@ -10,11 +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/testing/hack" "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/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_SkipBetween_SkipTest(t *testing.T) { //nolint:paralleltest @@ -59,7 +58,7 @@ 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{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -78,7 +77,7 @@ 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{ + r.UnitTest(&hack.MetaT{}, 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 f778968a9..bda0981a9 100644 --- a/tfversion/skip_if_not_alpha_test.go +++ b/tfversion/skip_if_not_alpha_test.go @@ -9,11 +9,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/testing/hack" "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/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_SkipIfNotAlpha_SkipTest_Stable(t *testing.T) { //nolint:paralleltest @@ -78,7 +77,7 @@ 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{ + r.UnitTest(&hack.MetaT{}, 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 545017ed0..52ea70f16 100644 --- a/tfversion/skip_if_not_prerelease_test.go +++ b/tfversion/skip_if_not_prerelease_test.go @@ -9,11 +9,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/testing/hack" "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/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_SkipIfNotPrerelease_SkipTest_Stable(t *testing.T) { //nolint:paralleltest @@ -41,7 +40,7 @@ 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{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -60,7 +59,7 @@ 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{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), }, @@ -78,7 +77,7 @@ 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{ + r.UnitTest(&hack.MetaT{}, 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 5b645b954..f875bb920 100644 --- a/tfversion/skip_if_test.go +++ b/tfversion/skip_if_test.go @@ -10,11 +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/testing/hack" "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/tfversion" - - testinginterface "github.com/mitchellh/go-testing-interface" ) func Test_SkipIf_SkipTest(t *testing.T) { //nolint:paralleltest @@ -42,7 +41,7 @@ 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{ + r.UnitTest(&hack.MetaT{}, r.TestCase{ ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ "test": providerserver.NewProviderServer(testprovider.Provider{}), },