Documentation
¶
Overview ¶
Package testutils gathers reusable pieces useful for testing
Index ¶
- Constants
- func LoadFixtureBytes(t *testing.T, path string) []byte
- func LoadFixtureString(t *testing.T, path string) string
- func LoadFixtureStringf(t *testing.T, format string, args ...interface{}) string
- func NewProtoV6ProviderFactory(subproviders ...subprovider.Subprovider) map[string]func() (tfprotov6.ProviderServer, error)
- func NewTestProtoV6ProviderFactory(client edgegrid.Client, subproviders ...subprovider.Subprovider) map[string]func() (tfprotov6.ProviderServer, error)
- func NewTestProtoV6SDKProviderFactory(client edgegrid.Client, subproviders ...subprovider.Subprovider) map[string]func() (tfprotov6.ProviderServer, error)
- func TFTestSetup() error
- func TFTestTeardown() error
- func TestRunner(m *testing.M)
- func TestStepDestroyFailed(config string, expectedError *regexp.Regexp) resource.TestStep
- type MockCalls
- type TattleT
Constants ¶
const ( //Once is used as clear representation, when mock is called 1 times Once = 1 //Twice is used as clear representation, when mock is called 2 times Twice = 2 //ThreeTimes is used as clear representation, when mock is called 3 times ThreeTimes = 3 //FourTimes is used as clear representation, when mock is called 4 times FourTimes = 4 //FiveTimes is used as clear representation, when mock is called 5 times FiveTimes = 5 )
const MockContext = mock.Anything
MockContext is used to mock any context in requests as they are not needed for testing purposes
Variables ¶
This section is empty.
Functions ¶
func LoadFixtureBytes ¶
LoadFixtureBytes returns the entire contents of the given file as a byte slice
func LoadFixtureString ¶
LoadFixtureString returns the entire contents of the given file as a string
func LoadFixtureStringf ¶
LoadFixtureStringf returns the entire contents of the given file as a string
func NewProtoV6ProviderFactory ¶
func NewProtoV6ProviderFactory(subproviders ...subprovider.Subprovider) map[string]func() (tfprotov6.ProviderServer, error)
NewProtoV6ProviderFactory uses provided subprovider to create provider factory for test purposes
func NewTestProtoV6ProviderFactory ¶
func NewTestProtoV6ProviderFactory(client edgegrid.Client, subproviders ...subprovider.Subprovider) map[string]func() (tfprotov6.ProviderServer, error)
NewTestProtoV6ProviderFactory uses provided subproviders and client to create provider factory for test purposes
func NewTestProtoV6SDKProviderFactory ¶
func NewTestProtoV6SDKProviderFactory(client edgegrid.Client, subproviders ...subprovider.Subprovider) map[string]func() (tfprotov6.ProviderServer, error)
NewTestProtoV6SDKProviderFactory uses provided subproviders and client to create SDK provider factory for test purposes
func TFTestSetup ¶
func TFTestSetup() error
TFTestSetup contains common setup for tests in all subproviders
func TFTestTeardown ¶
func TFTestTeardown() error
TFTestTeardown contains common teardown for tests in all subproviders
func TestRunner ¶
TestRunner executes common test setup and teardown in all subproviders
func TestStepDestroyFailed ¶
TestStepDestroyFailed creates a terraform test step, to work around an issue of verifying error if resource destroy failed correctly. Problem: When throwing an error from destroy terraform units produce “Error running post-test destroy, there may be dangling resources" because Terraform requires that destroy is successful to clean up the resources. Adding this step to the end will cause destroy to be triggered twice: First one will test the erroneous behaviour, the second one will be successful (to fulfil Terraform units requirement). Usage: add returned test step as the last step with the same config file as in previous step and expected error message.
Types ¶
type MockCalls ¶
MockCalls is a wrapper around []*mock.Call
type TattleT ¶
TattleT wraps a *testing.T to intercept a Testify mock's call of t.FailNow(). When testing.t.FailNow() is called from any goroutine other than the one on which a test was created, it causes the test to hang. Testify's mocks fail to inform the user which test failed. Use this struct to wrap a *testing.TattleT when you call `mock.Test(TattleT{t})` and the mock's failure message will include the failling test's name. Such failures are usually caused by unexpected method calls on a mock.
NB: You would only need to use this where Testify mocks are used in tests that spawn goroutines, such as those run by the Terraform test driver.