qa

package
v1.28.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HTTPFailures = []HTTPFixture{
	{
		MatchAny:     true,
		ReuseRequest: true,
		Status:       418,
		Response: apierr.APIError{
			ErrorCode:  "NONSENSE",
			StatusCode: 418,
			Message:    "I'm a teapot",
		},
	},
}

Functions

func AssertErrorStartsWith

func AssertErrorStartsWith(t *testing.T, err error, message string) bool

AssertErrorStartsWith ..

func FirstKeyValue

func FirstKeyValue(t *testing.T, str, key string) string

FirstKeyValue gets it from HCL string

func GetEnvOrSkipTest

func GetEnvOrSkipTest(t *testing.T, name string) string

GetEnvOrSkipTest proceeds with test only with that env variable

func HTTPFixturesApply

func HTTPFixturesApply(t *testing.T, fixtures []HTTPFixture, callback func(ctx context.Context, client *common.DatabricksClient))

HTTPFixturesApply is a helper method

func HttpFixtureClient

func HttpFixtureClient(t *testing.T, fixtures []HTTPFixture) (client *common.DatabricksClient, server *httptest.Server, err error)

HttpFixtureClient creates client for emulated HTTP server

func HttpFixtureClientWithToken

func HttpFixtureClientWithToken(t *testing.T, fixtures []HTTPFixture, token string) (*common.DatabricksClient, *httptest.Server, error)

HttpFixtureClientWithToken creates client for emulated HTTP server

func RandomEmail

func RandomEmail() string

RandomEmail generates random email

func RandomLongName

func RandomLongName() string

RandomLongName ...

func RandomName

func RandomName(prefix ...string) string

RandomName gives random name with optional prefix. e.g. qa.RandomName("tf-")

func RequireAnyCloudEnv added in v1.2.0

func RequireAnyCloudEnv(t *testing.T)

func RequireCloudEnv added in v1.2.0

func RequireCloudEnv(t *testing.T, cloudEnv string)

func ResourceCornerCases

func ResourceCornerCases(t *testing.T, resource *schema.Resource, cc ...CornerCase)

ResourceCornerCases checks for corner cases of error handling. Optional field name used to create error

Types

type CornerCase

type CornerCase struct {
	// contains filtered or unexported fields
}

func CornerCaseAccountID added in v1.2.0

func CornerCaseAccountID(id string) CornerCase

func CornerCaseExpectError

func CornerCaseExpectError(msg string) CornerCase

func CornerCaseID

func CornerCaseID(id string) CornerCase

func CornerCaseSkipCRUD

func CornerCaseSkipCRUD(method string) CornerCase

type HTTPFixture

type HTTPFixture struct {
	Method          string
	Resource        string
	Response        any
	Status          int
	ExpectedRequest any
	ReuseRequest    bool
	MatchAny        bool
}

HTTPFixture defines request structure for test

func UnionFixturesLists

func UnionFixturesLists(fixturesLists ...[]HTTPFixture) (fixtureList []HTTPFixture)

UnionFixturesLists merges two HTTP fixture lists together

type ResourceFixture

type ResourceFixture struct {
	// A list of HTTP fixtures representing requests and their corresponding
	// responses. These are loaded into the mock Databricks server.
	Fixtures []HTTPFixture

	// The resource the unit test is testing.
	Resource *schema.Resource

	// Set to true if the diff generated in the test will force a recreation
	// of the resource.
	RequiresNew bool

	// Existing state of the resource, equivalent to the state stored in a terraform
	// state file.
	InstanceState map[string]string

	// Configuration for the resource, equivalent to the configuration a user
	// defines in a .tf file. Only use one of HCL or State.
	State map[string]any

	// Alternative to State. Allows defining the resource configuration in HCL
	// which is decoded into a map. Only use one of HCL or State.
	HCL string

	// Mocks the Databricks Command Execution API. This mock is loaded at the client
	// level so any command execution API requests are not sent to the server.
	CommandMock common.CommandMock

	// Set one of them to true to test the corresponding CRUD function for the
	// terraform resource.
	Create bool
	Read   bool
	Update bool
	Delete bool

	Removed     bool
	ID          string
	NonWritable bool
	Azure       bool
	AzureSPN    bool
	Gcp         bool
	AccountID   string
	Token       string
	// new resource
	New bool
}

ResourceFixture is a helper to unit test terraform resources. It does this by creating a mock Databricks server and client.

func (ResourceFixture) Apply

Apply runs tests from fixture

func (ResourceFixture) ApplyAndExpectData

func (f ResourceFixture) ApplyAndExpectData(t *testing.T, data map[string]any)

ApplyAndExpectData is a convenience method for tests that doesn't expect error, but want to check data

func (ResourceFixture) ApplyNoError

func (f ResourceFixture) ApplyNoError(t *testing.T)

ApplyNoError is a convenience method for no-data tests

func (ResourceFixture) ExpectError

func (f ResourceFixture) ExpectError(t *testing.T, msg string)

ExpectError passes if there's an error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL