2023-03-02 15:37:05 -05:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-10 18:53:29 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-02 15:37:05 -05:00
|
|
|
|
2021-04-07 05:33:22 -04:00
|
|
|
package acctest
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
testTesting = true
|
|
|
|
|
|
|
|
|
|
if err := os.Setenv(TestEnvVar, "1"); err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTest_noEnv(t *testing.T) {
|
|
|
|
|
// Unset the variable
|
2022-08-13 14:58:33 -04:00
|
|
|
t.Setenv(TestEnvVar, "")
|
2021-04-07 05:33:22 -04:00
|
|
|
|
|
|
|
|
mt := new(mockT)
|
|
|
|
|
Test(mt, TestCase{})
|
|
|
|
|
|
|
|
|
|
if !mt.SkipCalled {
|
|
|
|
|
t.Fatal("skip not called")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTest_preCheck(t *testing.T) {
|
|
|
|
|
called := false
|
|
|
|
|
|
|
|
|
|
mt := new(mockT)
|
|
|
|
|
Test(mt, TestCase{
|
|
|
|
|
PreCheck: func() { called = true },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if !called {
|
|
|
|
|
t.Fatal("precheck should be called")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// mockT implements TestT for testing
|
|
|
|
|
type mockT struct {
|
|
|
|
|
ErrorCalled bool
|
|
|
|
|
ErrorArgs []interface{}
|
|
|
|
|
FatalCalled bool
|
|
|
|
|
FatalArgs []interface{}
|
|
|
|
|
SkipCalled bool
|
|
|
|
|
SkipArgs []interface{}
|
|
|
|
|
|
|
|
|
|
f bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *mockT) Error(args ...interface{}) {
|
|
|
|
|
t.ErrorCalled = true
|
|
|
|
|
t.ErrorArgs = args
|
|
|
|
|
t.f = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *mockT) Fatal(args ...interface{}) {
|
|
|
|
|
t.FatalCalled = true
|
|
|
|
|
t.FatalArgs = args
|
|
|
|
|
t.f = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *mockT) Skip(args ...interface{}) {
|
|
|
|
|
t.SkipCalled = true
|
|
|
|
|
t.SkipArgs = args
|
|
|
|
|
t.f = true
|
|
|
|
|
}
|