testutils

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: Apache-2.0 Imports: 21 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 REALM_NO_SKIP_TEST is set, indicating that skipping is not permitted.

func NewEmptyStorage

func NewEmptyStorage() *storage.Storage

NewEmptyStorage creates a new empty MemoryStrategy

func NewPopulatedDeprecatedStorage

func NewPopulatedDeprecatedStorage(username, apiKey string) *storage.Storage

NewPopulatedDeprecatedStorage creates a new MemoryStrategy populated with data in the old deprecated format

func NewPopulatedStorage

func NewPopulatedStorage(privateAPIKey, 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 MockRealmClient

type MockRealmClient struct {
	CreateEmptyAppFn                  func(groupID, appName, locationName, deploymentModelName string) (*models.App, error)
	FetchAppByGroupIDAndClientAppIDFn func(groupID, clientAppID string) (*models.App, error)
	FetchAppByClientAppIDFn           func(clientAppID string) (*models.App, error)
	FetchAppsByGroupIDFn              func(groupID string) ([]*models.App, error)
	ListAssetsForAppIDFn              func(groupID, appID string) ([]string, []hosting.AssetDescription, error)
	UploadAssetFn                     func(groupID, appID, path, hash string, size int64, body io.Reader, attributes ...hosting.AssetAttribute) error
	CopyAssetFn                       func(groupID, appID, fromPath, toPath string) error
	MoveAssetFn                       func(groupID, appID, fromPath, toPath string) error
	DeleteAssetFn                     func(groupID, appID, path string) error
	SetAssetAttributesFn              func(groupID, appID, path string, attributes ...hosting.AssetAttribute) error
	ExportFn                          func(groupID, appID string, strategy api.ExportStrategy) (string, io.ReadCloser, error)
	ExportDependencyFn                func(groupID, appID string) (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)
	InvalidateCacheFn                 func(groupID, appID, path string) error
	ListSecretsFn                     func(groupID, appID string) ([]secrets.Secret, error)
	AddSecretFn                       func(groupID, appID string, secret secrets.Secret) error
	UpdateSecretByIDFn                func(groupID, appID, secretID, secretValue string) error
	UpdateSecretByNameFn              func(groupID, appID, secretName, secretValue string) error
	RemoveSecretByIDFn                func(groupID, appID, secretID string) error
	RemoveSecretByNameFn              func(groupID, appID, secretName string) error
	UploadDependenciesFn              func(groupID, appID, fullPath string) error
}

MockRealmClient satisfies an api.RealmClient

func (*MockRealmClient) AddSecret

func (msc *MockRealmClient) AddSecret(groupID, appID string, secret secrets.Secret) error

AddSecret adds a secret to the app

func (*MockRealmClient) Authenticate

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

Authenticate will authenticate a user given an auth.AuthenticationProvider

func (*MockRealmClient) CopyAsset

func (msc *MockRealmClient) CopyAsset(groupID, appID, fromPath, toPath string) error

CopyAsset copies an asset

func (*MockRealmClient) CreateDraft

func (msc *MockRealmClient) CreateDraft(groupID, appID string) (*models.AppDraft, error)

CreateDraft returns a mock AppDraft

func (*MockRealmClient) CreateEmptyApp

func (msc *MockRealmClient) CreateEmptyApp(groupID, appName, locationName, deploymentModelName string) (*models.App, error)

CreateEmptyApp does nothing

func (*MockRealmClient) DeleteAsset

func (msc *MockRealmClient) DeleteAsset(groupID, appID, path string) error

DeleteAsset deletes an asset

func (*MockRealmClient) DeployDraft

func (msc *MockRealmClient) DeployDraft(groupID, appID, draftID string) (*models.Deployment, error)

DeployDraft returns a mock Deployment

func (*MockRealmClient) Diff

func (msc *MockRealmClient) 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 (*MockRealmClient) DiscardDraft

func (msc *MockRealmClient) DiscardDraft(groupID, appID, draftID string) error

DiscardDraft does nothing

func (*MockRealmClient) DraftDiff

func (msc *MockRealmClient) DraftDiff(groupID, appID, draftID string) (*models.DraftDiff, error)

DraftDiff returns an empty DraftDiff

func (*MockRealmClient) Export

func (msc *MockRealmClient) Export(groupID, appID string, strategy api.ExportStrategy) (string, io.ReadCloser, error)

Export will download a Realm app as a .zip

func (*MockRealmClient) ExportDependencies

func (msc *MockRealmClient) ExportDependencies(groupID, appID string) (string, io.ReadCloser, error)

Export will download a Realm app's dependencies

func (*MockRealmClient) FetchAppByClientAppID

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

FetchAppByClientAppID fetches a Realm app given a clientAppID

func (*MockRealmClient) FetchAppByGroupIDAndClientAppID

func (msc *MockRealmClient) FetchAppByGroupIDAndClientAppID(groupID, clientAppID string) (*models.App, error)

FetchAppByGroupIDAndClientAppID fetches a Realm app given a groupID and clientAppID

func (*MockRealmClient) FetchAppsByGroupID

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

FetchAppsByGroupID does nothing

func (*MockRealmClient) GetDeployment

func (msc *MockRealmClient) GetDeployment(groupID, appID, deploymentID string) (*models.Deployment, error)

GetDeployment returns a mock Deployment

func (*MockRealmClient) GetDrafts

func (msc *MockRealmClient) GetDrafts(groupID, appID string) ([]models.AppDraft, error)

GetDrafts returns an empty list of AppDrafts

func (*MockRealmClient) Import

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

Import will push a local Realm app to the server

func (*MockRealmClient) InvalidateCache

func (msc *MockRealmClient) InvalidateCache(groupID, appID, path string) error

InvalidateCache requests cache invalidation for the asset at the argued path

func (*MockRealmClient) ListAssetsForAppID

func (msc *MockRealmClient) ListAssetsForAppID(groupID, appID string) ([]hosting.AssetMetadata, error)

ListAssetsForAppID fetches a Realm app given a clientAppID

func (*MockRealmClient) ListSecrets

func (msc *MockRealmClient) ListSecrets(groupID, appID string) ([]secrets.Secret, error)

ListSecrets lists the secrets of an app

func (*MockRealmClient) MoveAsset

func (msc *MockRealmClient) MoveAsset(groupID, appID, fromPath, toPath string) error

MoveAsset moves an asset

func (*MockRealmClient) RemoveSecretByID

func (msc *MockRealmClient) RemoveSecretByID(groupID, appID, secretID string) error

RemoveSecretByID removes a secret from the app

func (*MockRealmClient) RemoveSecretByName

func (msc *MockRealmClient) RemoveSecretByName(groupID, appID, secretName string) error

RemoveSecretByName removes a secret from the app

func (*MockRealmClient) SetAssetAttributes

func (msc *MockRealmClient) SetAssetAttributes(groupID, appID, path string, attributes ...hosting.AssetAttribute) error

SetAssetAttributes sets an asset's attributes

func (*MockRealmClient) UpdateSecretByID

func (msc *MockRealmClient) UpdateSecretByID(groupID, appID, secretID, secretValue string) error

UpdateSecretByID updates a secret from the app

func (*MockRealmClient) UpdateSecretByName

func (msc *MockRealmClient) UpdateSecretByName(groupID, appID, secretName, secretValue string) error

UpdateSecretByName updates a secret from the app

func (*MockRealmClient) UploadAsset

func (msc *MockRealmClient) UploadAsset(groupID, appID, path, hash string, size int64, body io.Reader, attributes ...hosting.AssetAttribute) error

UploadAsset uploads an asset

func (*MockRealmClient) UploadDependencies

func (msc *MockRealmClient) UploadDependencies(groupID, appID, fullPath string) error

type MongoDBCloudEnv

type MongoDBCloudEnv struct {
	CloudAPIBaseURL    string
	RealmServerBaseURL string
	APIKey             string
	Username           string
	AdminUsername      string
	AdminAPIKey        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