testutils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SkipUnlessMongoDBCloudRunning = func() func(t *testing.T) {
	return func(t *testing.T) {
		cloudEnv := ENV()

		if mongoDBCloudNotRunning {
			MustSkipf(t, "MongoDB Cloud not running at %s", cloudEnv.CloudAPIBaseURL)
			return
		}
		req, err := http.NewRequest(http.MethodGet, cloudEnv.CloudAPIBaseURL, nil)
		if err != nil {
			panic(err)
		}
		resp, err := http.DefaultClient.Do(req)
		if err != nil || resp.StatusCode != http.StatusOK {
			MustSkipf(t, "MongoDB Cloud not running at %s", cloudEnv.CloudAPIBaseURL)
			return
		}
	}
}()

SkipUnlessMongoDBCloudRunning skips tests if there is no cloud instance running at the chosen base URL

Functions

func GenerateValidAccessToken

func GenerateValidAccessToken() string

GenerateValidAccessToken generates and returns a valid access token *from the future*

func MustSkipf

func MustSkipf(t *testing.T, format string, args ...interface{})

MustSkipf skips a test suite, but panics if STITCH_NO_SKIP_TEST is set, indicating that skipping is not permitted.

func NewEmptyStorage

func NewEmptyStorage() *storage.Storage

NewEmptyStorage creates a new empty MemoryStrategy

func NewPopulatedStorage

func NewPopulatedStorage(apiKey, refreshToken, accessToken string) *storage.Storage

NewPopulatedStorage creates a new MemoryStrategy populated with data

func So

func So(t *testing.T, actual interface{}, assert Assertion, expected ...interface{})

So runs an assertion and fails the test if necessary

Types

type Assertion

type Assertion func(actual interface{}, expected ...interface{}) string

Assertion is a func that checks some condition for use in a test

type MemoryStrategy

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

MemoryStrategy is a storage.Strategy that stores data in memory

func NewMemoryStrategy

func NewMemoryStrategy(data []byte) *MemoryStrategy

NewMemoryStrategy returns a new MemoryStrategy

func (*MemoryStrategy) Read

func (ms *MemoryStrategy) Read() ([]byte, error)

Read reads the data currently stored in memory storage

func (*MemoryStrategy) Write

func (ms *MemoryStrategy) Write(data []byte) error

Write records the provided data to memory storage

type MockClient

type MockClient struct {
	RequestData []RequestData
	Responses   []*http.Response
	// contains filtered or unexported fields
}

A MockClient is a new api.Client that can be used to mock out HTTP requests and return responses

func NewMockClient

func NewMockClient(responses []*http.Response) *MockClient

NewMockClient returns a new MockClient

func (*MockClient) ExecuteRequest

func (mc *MockClient) ExecuteRequest(method, path string, options api.RequestOptions) (*http.Response, error)

ExecuteRequest satisfies the api.Client interface, records request data, and returns the provided responses in order

type MockMDBClient

type MockMDBClient struct {
	WithAuthFn           func(username, apiKey string) mdbcloud.Client
	GroupsFn             func() ([]mdbcloud.Group, error)
	GroupByNameFn        func(string) (*mdbcloud.Group, error)
	DeleteDatabaseUserFn func(groupId, username string) error
}

MockMDBClient satisfies a mdbcloud.Client

func (*MockMDBClient) DeleteDatabaseUser

func (mmc *MockMDBClient) DeleteDatabaseUser(groupID, username string) error

DeleteDatabaseUser does nothing

func (*MockMDBClient) GroupByName

func (mmc *MockMDBClient) GroupByName(groupName string) (*mdbcloud.Group, error)

GroupByName will look up the Group given a name

func (*MockMDBClient) Groups

func (mmc *MockMDBClient) Groups() ([]mdbcloud.Group, error)

Groups will return a list of groups available

func (MockMDBClient) WithAuth

func (mmc MockMDBClient) WithAuth(username, apiKey string) mdbcloud.Client

WithAuth will authenticate a user given username and apiKey

type MockStitchClient

type MockStitchClient struct {
	CreateEmptyAppFn        func(groupID, appName string) (*models.App, error)
	FetchAppByClientAppIDFn func(clientAppID string) (*models.App, error)
	FetchAppsByGroupIDFn    func(groupID string) ([]*models.App, error)

	ExportFn      func(groupID, appID string, isTemplated bool) (string, io.ReadCloser, error)
	ExportFnCalls [][]string

	ImportFn      func(groupID, appID string, appData []byte, strategy string) error
	ImportFnCalls [][]string

	DiffFn func(groupID, appID string, appData []byte, strategy string) ([]string, error)
}

MockStitchClient satisfies an api.StitchClient

func (*MockStitchClient) Authenticate

func (msc *MockStitchClient) Authenticate(authProvider auth.AuthenticationProvider) (*auth.Response, error)

Authenticate will authenticate a user given an auth.AuthenticationProvider

func (*MockStitchClient) CreateEmptyApp

func (msc *MockStitchClient) CreateEmptyApp(groupID, appName string) (*models.App, error)

CreateEmptyApp does nothing

func (*MockStitchClient) Diff

func (msc *MockStitchClient) Diff(groupID, appID string, appData []byte, strategy string) ([]string, error)

Diff will execute a dry-run of an import, returning a diff of proposed changes

func (*MockStitchClient) Export

func (msc *MockStitchClient) Export(groupID, appID string, isTemplated bool) (string, io.ReadCloser, error)

Export will download a Stitch app as a .zip

func (*MockStitchClient) FetchAppByClientAppID

func (msc *MockStitchClient) FetchAppByClientAppID(clientAppID string) (*models.App, error)

FetchAppByClientAppID fetches a Stitch app given a clientAppID

func (*MockStitchClient) FetchAppsByGroupID

func (msc *MockStitchClient) FetchAppsByGroupID(groupID string) ([]*models.App, error)

FetchAppsByGroupID does nothing

func (*MockStitchClient) Import

func (msc *MockStitchClient) Import(groupID, appID string, appData []byte, strategy string) error

Import will push a local Stitch app to the server

type MongoDBCloudEnv

type MongoDBCloudEnv struct {
	CloudAPIBaseURL     string
	StitchServerBaseURL string
	APIKey              string
	Username            string
	GroupID             string
}

MongoDBCloudEnv represents ENV variables required for running tests against cloud

func ENV

func ENV() MongoDBCloudEnv

ENV returns the current MongoDBCloudEnv configuration

type RequestData

type RequestData struct {
	Method  string
	Path    string
	Options api.RequestOptions
}

RequestData represents a given request made to the MockClient

type ResponseBody

type ResponseBody struct {
	*bytes.Buffer
}

ResponseBody is a io.ReadCloser that can be used as a net/http.Body

func NewAuthResponseBody

func NewAuthResponseBody(data auth.Response) *ResponseBody

NewAuthResponseBody returns a new ResponseBody populated with auth.Response data

func NewResponseBody

func NewResponseBody(data io.Reader) *ResponseBody

NewResponseBody returns a new ResponseBody

func (*ResponseBody) Close

func (ar *ResponseBody) Close() error

Close satisfies the io.ReadCloser interface

Jump to

Keyboard shortcuts

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