// Helper function to handle all the weird work of creating a test server.
func startServer() (*httptest.Server, AcceptanceTestEnvVars) {
	// Load the environment variables to conduct the tests.
	testEnvVars := AcceptanceTestEnvVars{}
	testEnvVars.LoadTestEnvVars()

	var err error
	// Attempt to initial routers
	app, settings, err := controllers.InitApp(testEnvVars.EnvVars)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	// Since we are running in a separate folder from the main package, we need to change the location of the static folder.
	app.Middleware(web.StaticMiddleware("../static", web.StaticOption{IndexFile: "index.html"}))

	// Create the httptest server
	server := httptest.NewUnstartedServer(app)
	server.Start()

	// Change config values to fit the URL of the httptest server that is created on a random port.
	testEnvVars.Hostname = server.URL
	settings.OAuthConfig.RedirectURL = server.URL + "/oauth2callback"

	return server, testEnvVars
}
Example #2
0
func TestPing(t *testing.T) {
	response, request := NewTestRequest("GET", "/ping", nil)
	router, _, _ := controllers.InitApp(MockCompleteEnvVars)
	router.ServeHTTP(response, request)
	if response.Body.String() != "{\"status\": \"alive\", \"build-info\": \"developer-build\"}" {
		t.Errorf("Expected alive. Found %s\n", response.Body.String())
	}
}
Example #3
0
func TestInitApp(t *testing.T) {
	for _, test := range initAppTests {
		router, settings, err := controllers.InitApp(test.envVars)
		if (router == nil) != test.returnRouterNil {
			t.Errorf("Test %s did not return correct router value. Expected %t, Actual %t", test.testName, test.returnRouterNil, (router == nil))
		} else if (settings == nil) != test.returnSettingsNil {
			t.Errorf("Test %s did not return correct settings value. Expected %t, Actual %t", test.testName, test.returnSettingsNil, (settings == nil))
		} else if (err == nil) != test.returnErrorNil {
			t.Errorf("Test %s did not return correct error value. Expected %t, Actual %t", test.testName, test.returnErrorNil, (err == nil))
		}
	}
}
Example #4
0
func startApp(port string) {
	// Load environment variables
	envVars := loadEnvVars()

	app, _, err := controllers.InitApp(envVars)
	if err != nil {
		// Print the error.
		fmt.Println(err.Error())
		// Terminate the program with a non-zero value number.
		// Need this for testing purposes.
		os.Exit(1)
	}

	http.ListenAndServe(":"+port, app)
}
Example #5
0
func startApp(port string) {
	// Load environment variables
	envVars := loadEnvVars()

	app, _, err := controllers.InitApp(envVars)
	if err != nil {
		// Print the error.
		fmt.Println(err.Error())
		// Terminate the program with a non-zero value number.
		// Need this for testing purposes.
		os.Exit(1)
	}

	// TODO add better timeout message. By default it will just say "Timeout"
	http.ListenAndServe(":"+port, http.TimeoutHandler(context.ClearHandler(app), time.Second*5, ""))
}