Beispiel #1
0
func TestPing(t *testing.T) {
	response, request := testhelpers.NewTestRequest("GET", "/ping")
	router := InitRouter(nil)
	router.ServeHTTP(response, request)
	if response.Body.String() != "alive" {
		t.Errorf("Expected alive. Found %s\n", response.Body.String())
	}
}
Beispiel #2
0
func TestOAuth(t *testing.T) {
	mockSettings := helpers.Settings{}
	for _, test := range oauthTests {
		// Initialize a new session store.
		store := testhelpers.MockSessionStore{}
		store.ResetSessionData(test.sessionData, "")
		mockSettings.Sessions = store

		// Setup a test route on the API router (which is guarded by OAuth)
		response, request := testhelpers.NewTestRequest("GET", "/v2/test")
		router := InitRouter(&mockSettings)
		apiRouter := router.Subrouter(APIContext{}, "/v2")
		apiRouter.Middleware((*APIContext).OAuth)
		apiRouter.Get("/test", (*APIContext).Test)

		// Make the request and check.
		router.ServeHTTP(response, request)
		if strings.TrimSpace(response.Body.String()) != test.expectedText {
			t.Errorf("Test %s did not meet expected value. Expected %s. Found %s.\n", test.testName, test.expectedText, response.Body.String())
		}
	}
}