Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bbasata committed Dec 19, 2024
1 parent a19f315 commit 36b802f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 49 deletions.
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
40 changes: 0 additions & 40 deletions internal/plugintest/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"path"
"path/filepath"
"strings"
"testing"
)

func symlinkFile(src string, dest string) error {
Expand Down Expand Up @@ -145,42 +144,3 @@ func CopyDir(src, dest, baseDirName string) error {

return nil
}

// TestExpectTFatal provides a wrapper for logic which should call
// (*testing.T).Fatal() or (*testing.T).Fatalf().
//
// Since we do not want the wrapping test to fail when an expected test error
// occurs, it is required that the testLogic passed in uses
// github.com/mitchellh/go-testing-interface.RuntimeT instead of the real **
// *testing.T.
//
// If Fatal() or Fatalf() is not called in the logic, the real (*testing.T).Fatal() will
// be called to fail the test.
func TestExpectTFatal(t *testing.T, testLogic func()) {
t.Helper()

var recoverIface interface{}

func() {
defer func() {
recoverIface = recover()
}()

testLogic()
}()

if recoverIface == nil {
t.Fatalf("expected t.Fatal(), got none")
}

recoverStr, ok := recoverIface.(string)

if !ok {
t.Fatalf("expected string from recover(), got: %v (%T)", recoverIface, recoverIface)
}

// this string is hardcoded in github.com/mitchellh/go-testing-interface
if !strings.HasPrefix(recoverStr, "testing.T failed, see logs for output") {
t.Fatalf("expected t.Fatal(), got: %s", recoverStr)
}
}

0 comments on commit 36b802f

Please sign in to comment.