Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testingiface redux #403

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions helper/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions helper/resource/plan_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions helper/resource/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions helper/resource/state_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions helper/resource/testcase_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"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"
)

Expand Down Expand Up @@ -344,8 +344,8 @@
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{

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.1.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.5.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.3.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.2.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.4.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.12.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.2.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.12.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.13.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.1.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.6.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.13.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.3.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.10.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.9.0-alpha20240501)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.8.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.15.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.14.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.8.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.0.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.10.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.9.0-alpha20240501)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.14.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.6.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.7.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.0.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.5.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.4.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.15.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.9.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.9.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 348 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.7.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(tfversion.Version0_13_0), // ExternalProvider.Source
},
Expand All @@ -366,7 +366,7 @@
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{}),
},
Expand All @@ -381,8 +381,8 @@
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{

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.1.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.5.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.3.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.2.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.4.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.12.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.2.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.12.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.13.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.1.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.6.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.13.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.3.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.10.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.9.0-alpha20240501)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.8.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.15.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.14.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.8.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.0.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.10.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.9.0-alpha20240501)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.14.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.6.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.7.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.0.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.5.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.4.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.15.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.9.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.9.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 385 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.7.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test
ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){
"test": func() (tfprotov5.ProviderServer, error) { //nolint:unparam // required signature
return nil, fmt.Errorf("test")
Expand All @@ -400,7 +400,7 @@
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{}),
},
Expand All @@ -415,8 +415,8 @@
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{

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.1.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.5.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.3.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.2.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.4.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.12.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.2.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.12.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.13.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.1.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.6.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.13.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.3.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.10.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.9.0-alpha20240501)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.8.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.15.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.14.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.8.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.0.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.10.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.9.0-alpha20240501)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.14.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.6.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.7.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.0.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.5.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.4.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.15.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.9.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.9.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 419 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.7.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
"test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature
return nil, fmt.Errorf("test")
Expand All @@ -434,7 +434,7 @@
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
Expand All @@ -451,8 +451,8 @@
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{

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.1.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.5.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.3.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.2.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.4.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.12.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.2.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.12.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.13.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.1.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.6.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.13.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.3.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.10.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.9.0-alpha20240501)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.8.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.15.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 0.14.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.8.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.0.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.10.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.9.0-alpha20240501)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.14.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.6.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.7.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.0.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.5.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.4.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 0.15.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.22 / TF 1.9.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.9.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test

Check failure on line 455 in helper/resource/testcase_providers_test.go

View workflow job for this annotation

GitHub Actions / test (Go 1.23 / TF 1.7.*)

cannot use mockT (variable of type *testingiface.MockT) as *"testing".T value in argument to Test
ProviderFactories: map[string]func() (*schema.Provider, error){
"test": func() (*schema.Provider, error) { //nolint:unparam // required signature
return nil, fmt.Errorf("test")
Expand All @@ -470,7 +470,7 @@
func TestTest_TestCase_Providers(t *testing.T) {
t.Parallel()

Test(&mockT{}, TestCase{
Test(t, TestCase{
Providers: map[string]*schema.Provider{
"test": {},
},
Expand Down
5 changes: 2 additions & 3 deletions helper/resource/testcase_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
46 changes: 34 additions & 12 deletions helper/resource/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import (
"regexp"
"strconv"
"strings"
"testing"
"time"

"github.com/mitchellh/go-testing-interface"

"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"

Expand All @@ -31,6 +30,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
Expand Down Expand Up @@ -812,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 testing.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.
Expand Down Expand Up @@ -849,7 +853,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 TestT(t testingiface.T, c TestCase) {
t.Helper()

ctx := context.Background()
Expand Down Expand Up @@ -916,28 +920,46 @@ func Test(t testing.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)

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 testing.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) {
Expand Down
Loading
Loading