Beispiel #1
0
func main() {
	port := os.Getenv("PORT")
	if port == "" {
		port = "3000"
	}
	host := os.Getenv("HOST")

	templates.Init("templates")
	models.InitDb(os.Getenv("DATABASE_URL"))
	addon.Init(os.Getenv("HEROKU_ID"), os.Getenv("HEROKU_API_PASSWORD"), os.Getenv("HEROKU_SSO_SALT"))

	rand.Seed(time.Now().UTC().UnixNano())

	r := mux.NewRouter()
	r.SkipClean(true) // have to use whatupdave/mux until Gorilla supports this

	new(controllers.AccountsController).Init(r)
	new(controllers.HerokuResourcesController).Init(r)
	new(controllers.HomeController).Init(r)
	new(controllers.ImagesController).Init(r)
	new(controllers.RegistrationsController).Init(r)
	new(controllers.SessionsController).Init(r)
	new(controllers.SsoSessionsController).Init(r)

	r.PathPrefix("/").Handler(http.FileServer(http.Dir("static")))

	n := negroni.Classic()
	n.UseHandler(r)
	n.Run(host + ":" + port)
}
func TestRecordingImageRequests(t *testing.T) {
	models.InitDb("postgres://localhost/firesize_test?sslmode=disable")
	defer models.Dbm.TruncateTables()

	router := mux.NewRouter()
	router.SkipClean(true)
	new(ImagesController).Init(router)

	recorder := httptest.NewRecorder()

	account := models.Account{
		CreatedAt: time.Now(),
		Email:     "*****@*****.**",
		Subdomain: "testing",
	}

	err := models.Insert(&account)
	if err != nil {
		t.Fatal(err.Error())
	}

	request, err := http.NewRequest("GET", "http://testing.firesize.dev/500x300/g_center/http://placekitten.com/g/800/600", nil)
	if err != nil {
		t.Fatal("Failed to GET http://testing.firesize.dev/500x300/g_center/http://placekitten.com/g/800/600")
	}

	router.ServeHTTP(recorder, request)

	if recorder.Code != http.StatusOK {
		t.Fatal("Incorrect response code returned. Expected: ", http.StatusOK, ", Received: ", recorder.Code)
	}

	count := models.FindImageRequestCountForAccount(&account)
	if count != 1 {
		t.Fatal("Incorrect image request count. Expected: 1, Received: ", count)
	}
}