コード例 #1
0
ファイル: server.go プロジェクト: EricSchles/cf-console
func main() {
	// Load environment variables
	envVars := loadEnvVars()
	// Initialize the settings.
	settings := helpers.Settings{}
	if err := settings.InitSettings(envVars); err != nil {
		fmt.Println(err.Error())
		return
	}

	// Initialize the router
	router := controllers.InitRouter(&settings)

	// Start the server up.
	var port string
	if port = os.Getenv("PORT"); len(port) == 0 {
		port = "9999"
	}
	http.ListenAndServe(":"+port, router)
}
コード例 #2
0
ファイル: api_test.go プロジェクト: EricSchles/cf-console
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())
		}
	}
}