Documentation ¶
Index ¶
- Variables
- func CreateExternalServer(t *testing.T, test *BasicProxyTest) *httptest.Server
- func NewTestRequest(method, path string, body []byte) (*httptest.ResponseRecorder, *http.Request)
- func PrepareExternalServerCall(t *testing.T, c *controllers.SecureContext, testServer *httptest.Server, ...) (*httptest.ResponseRecorder, *http.Request, *web.Router)
- func VerifyExternalCallResponse(t *testing.T, response *httptest.ResponseRecorder, test *BasicProxyTest)
- type BasicConsoleUnitTest
- type BasicProxyTest
- type BasicSecureTest
- type MockSessionStore
- func (store MockSessionStore) Get(r *http.Request, name string) (*sessions.Session, error)
- func (store MockSessionStore) New(r *http.Request, name string) (*sessions.Session, error)
- func (store *MockSessionStore) ResetSessionData(data map[string]interface{}, sessionName string)
- func (store MockSessionStore) Save(r *http.Request, w http.ResponseWriter, s *sessions.Session) error
Constants ¶
This section is empty.
Variables ¶
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.
var MockCompleteEnvVars = helpers.EnvVars{ ClientID: "ID", ClientSecret: "Secret", Hostname: "hostname", LoginURL: "loginurl", UAAURL: "uaaurl", APIURL: "apiurl", LogURL: "logurl", PProfEnabled: "true", SessionKey: "lalala", BasePath: os.Getenv(helpers.BasePathEnvVar), }
MockCompleteEnvVars is just a commonly used env vars object that contains non-empty values for all the fields of the EnvVars struct.
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 ¶
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 ExpectedLocation 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 ¶
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 ¶
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 ¶
func (store MockSessionStore) Save(r *http.Request, w http.ResponseWriter, s *sessions.Session) error
Save returns nil error. We save session data by using ResetSessionData