testhelpers

package
v0.0.0-...-068e466 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2015 License: CC0-1.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InvalidTokenData = map[string]interface{}{
	"token": oauth2.Token{Expiry: (time.Now()).Add(-1 * time.Minute), AccessToken: "invalidsampletoken"},
}

InvalidTokenData is a dataset which represents an invalid token. Useful for unit tests.

View Source
var MockCompleteEnvVars = helpers.EnvVars{
	ClientID:     "ID",
	ClientSecret: "Secret",
	Hostname:     "hostname",
	LoginURL:     "loginurl",
	UAAURL:       "uaaurl",
	APIURL:       "apiurl",
	LogURL:       "logurl",
	PProfEnabled: "true",
}

MockCompleteEnvVars is just a commonly used env vars object that contains non-empty values for all the fields of the EnvVars struct.

View Source
var ValidTokenData = map[string]interface{}{
	"token": oauth2.Token{Expiry: time.Time{}, AccessToken: "sampletoken"},
}

ValidTokenData is a dataset which represents a valid token. Useful for unit tests.

Functions

func CreateExternalServer

func CreateExternalServer(t *testing.T, test *BasicProxyTest) *httptest.Server

CreateExternalServer creates a test server that should reply with the given parameters assuming that the incoming request matches what we want.

func NewTestRequest

func NewTestRequest(method, path string, body []byte) (*httptest.ResponseRecorder, *http.Request)

NewTestRequest is a helper function that creates a sample request with the given input parameters.

func PrepareExternalServerCall

func PrepareExternalServerCall(t *testing.T, c *controllers.SecureContext, testServer *httptest.Server, fullURL string, test BasicProxyTest) (*httptest.ResponseRecorder, *http.Request, *web.Router)

PrepareExternalServerCall creates all the things that we will use when we send the request to the external server. This includes setting up the routes, create a test response recorder and a test request.

func VerifyExternalCallResponse

func VerifyExternalCallResponse(t *testing.T, response *httptest.ResponseRecorder, test *BasicProxyTest)

VerifyExternalCallResponse will verify the test response with what was expected by the test.

Types

type BasicConsoleUnitTest

type BasicConsoleUnitTest struct {
	// Name of the tests
	TestName string
	// Set of env vars to set up the settings.
	EnvVars helpers.EnvVars
	// Ending location of request.
	Location    string
	Code        int
	SessionData map[string]interface{}
}

BasicConsoleUnitTest is Basic Unit Test Information.

type BasicProxyTest

type BasicProxyTest struct {
	BasicSecureTest
	// RequestMethod is the type of method that our test client should send.
	RequestMethod string
	// RequestPath is the path that our test client should send.
	RequestPath string
	// RequestBody is the body that our test client should send.
	RequestBody []byte
	// ExpectedPath is the path that the test 'external' cloud foundry server we setup should receive.
	// This is useful as we translate our endpoints to conform with the cloud foundry APIs.
	// e.g. our endpoint: /uaa/userinfo & cloud foundry endpoint: /userinfo
	ExpectedPath string
	// The response the test 'external' cloud foundry server should send back.
	Response string
	// The code the test 'external' cloud foundry server should send back.
	ResponseCode int
}

BasicProxyTest contains information for what our test 'external' server should do when the proxy methods contact it.

type BasicSecureTest

type BasicSecureTest struct {
	BasicConsoleUnitTest
	ExpectedCode     int
	ExpectedResponse string
}

BasicSecureTest contains info like BasicConsoleUnitTest. TODO consolidate BasicConsoleUnitTest and BasicSecureTest

type MockSessionStore

type MockSessionStore struct {
	Session *sessions.Session

	Options *sessions.Options
	// contains filtered or unexported fields
}

MockSessionStore represents an easily fillable session store that implements gorilla's session store interface.

func CreateRouterWithMockSession

func CreateRouterWithMockSession(sessionData map[string]interface{}, envVars helpers.EnvVars) (*web.Router, *MockSessionStore)

CreateRouterWithMockSession will create a settings with the appropriate envVars and load the mock session with the session data.

func (MockSessionStore) Get

func (store MockSessionStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get simply returns the session that has pre populated beforehand with ResetSessionData or will return nil if the session name that is given is 'nilSession'

func (MockSessionStore) New

func (store MockSessionStore) New(r *http.Request, name string) (*sessions.Session, error)

New returns the current session. Does not create a new one. Not needed for mock sessions.

func (*MockSessionStore) ResetSessionData

func (store *MockSessionStore) ResetSessionData(data map[string]interface{}, sessionName string)

ResetSessionData zero initializes the MockSessionStore and then will copy the input session data into it.

func (MockSessionStore) Save

Save returns nil error. We save session data by using ResetSessionData

Jump to

Keyboard shortcuts

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