Ejemplo n.º 1
0
func TestRequest_Param(t *testing.T) {
	r, _ := http.NewRequest("GET", "http:///example.com?f=foo&b=bar", nil)
	request := newRequest(r)

	assert.Equal(t, "foo", request.Param("f"))
	assert.Equal(t, "bar", request.Param("b"))
}
Ejemplo n.º 2
0
func TestRecordingsHandler_WithReleaseIdNotFound(t *testing.T) {
	recorder := newTestRequest("GET", "/releases/00000000-0000-0000-0000-000000000000/recordings.json")

	body := string(recorder.Body.Bytes())
	assert.Equal(t, `{"error":"release not found"}`+"\n", body)
	assert.Equal(t, 404, recorder.Code)
}
Ejemplo n.º 3
0
func TestRouter_Add(t *testing.T) {
	router := New()
	assert.Equal(t, 0, len(router.routes["GET"]))
	route := router.Add(HttpMethod("GET"), "/", httpHandlerExample)
	assert.Type(t, "*traffic.Route", route)
	assert.Equal(t, 1, len(router.routes["GET"]))
}
Ejemplo n.º 4
0
func TestEnvironment_Url(t *testing.T) {
	e := &Environment{Live: false}
	assert.Equal(t, "http://test.lyricfind.com/api_service", e.Url().String())

	e = &Environment{Live: true}
	assert.Equal(t, "http://api.lyricfind.com", e.Url().String())
}
Ejemplo n.º 5
0
func TestRecordingsHandler_WithExistingdIdAndNonExsistingArtistId(t *testing.T) {
	recorder := newTestRequest("GET", "/artists/00000000-0000-0000-0000-000000000000/releases/79215cdf-4764-4dee-b0b9-fec1643df7c5/recordings.json")

	body := string(recorder.Body.Bytes())
	assert.Equal(t, `{"error":"artist not found"}`+"\n", body)
	assert.Equal(t, 404, recorder.Code)
}
Ejemplo n.º 6
0
func TestArtistHandler_WithIdNotFound(t *testing.T) {
	recorder := newTestRequest("GET", "/artists/00000000-0000-0000-0000-000000000000.json")

	body := string(recorder.Body.Bytes())
	assert.Equal(t, `{"error":"artist not found"}`+"\n", body)
	assert.Equal(t, 404, recorder.Code)
}
Ejemplo n.º 7
0
func TestNewData(t *testing.T) {
	data := NewData()

	assert.Equal(t, VERSION, data.Version)
	assert.Equal(t, []string{"log", "backtrace", "type"}, data.Columns)
	assert.Equal(t, 0, len(data.Rows))
}
Ejemplo n.º 8
0
func TestArtistHandler_WithInvalidUUID(t *testing.T) {
	recorder := newTestRequest("GET", "/artists/bad-uuid.json")

	body := string(recorder.Body.Bytes())
	assert.Equal(t, "", body)
	assert.Equal(t, 400, recorder.Code)
}
Ejemplo n.º 9
0
func TestGeometry_String(t *testing.T) {
	g := Geometry{200, 300}
	assert.Equal(t, "200x300", g.String())

	g = Geometry{200, 0}
	assert.Equal(t, "200x", g.String())
}
Ejemplo n.º 10
0
func TestEncode(t *testing.T) {
	assert.Equal(t, "0", Encode(0))
	assert.Equal(t, "1b", Encode(99))
	assert.Equal(t, "QNZ", Encode(101405))
	assert.Equal(t, "15y79wVi9XQ", Encode(920110421043409228))

}
Ejemplo n.º 11
0
func TestRouter_Delete(t *testing.T) {
	router := New()
	assert.Equal(t, 0, len(router.routes["DELETE"]))
	route := router.Delete("/", httpHandlerExample)
	assert.Type(t, "*traffic.Route", route)
	assert.Equal(t, 1, len(router.routes["DELETE"]))
}
Ejemplo n.º 12
0
func TestRecordingsHandler_WithInvalidReleaseId(t *testing.T) {
	recorder := newTestRequest("GET", "/releases/bad-uuid/recordings.json")

	body := string(recorder.Body.Bytes())
	assert.Equal(t, "", body)
	assert.Equal(t, 400, recorder.Code)
}
Ejemplo n.º 13
0
func TestRouter_Patch(t *testing.T) {
	router := New()
	assert.Equal(t, 0, len(router.routes["PATCH"]))
	route := router.Patch("/", httpHandlerExample)
	assert.Type(t, "*traffic.Route", route)
	assert.Equal(t, 1, len(router.routes["PATCH"]))
}
Ejemplo n.º 14
0
func TestLogData_Add(t *testing.T) {
	logData := make(LogData, 0)

	assert.Equal(t, 0, len(logData))

	logData.Add(1)
	assert.Equal(t, 1, len(logData))
}
Ejemplo n.º 15
0
func TestNewLogRow(t *testing.T) {
	logData := make(LogData, 0)
	row := NewLogRow(&logData, "foo.go:100", "log")

	assert.Equal(t, &logData, (*row)[0])
	assert.Equal(t, "foo.go:100", (*row)[1])
	assert.Equal(t, "log", (*row)[2])
}
Ejemplo n.º 16
0
func TestPublicPath(t *testing.T) {
	InitSettings()
	assert.Equal(t, DefaultPublicPath, PublicPath())

	os.Setenv("PUBLIC_PATH", "./foo")
	InitSettings()
	assert.Equal(t, "./foo", PublicPath())
}
Ejemplo n.º 17
0
func TestPort(t *testing.T) {
	InitSettings()
	assert.Equal(t, DefaultPort, Port())

	os.Setenv("PORT", "12345")
	InitSettings()
	assert.Equal(t, "12345", Port())
}
Ejemplo n.º 18
0
func TestRootHandler(t *testing.T) {
	recorder := newTestRequest("GET", "/")
	expectedBody := fmt.Sprintf(`{"version":"%s"}`, VERSION) + "\n"

	assert.Equal(t, []string{"application/json"}, recorder.HeaderMap["Content-Type"])
	assert.Equal(t, expectedBody, string(recorder.Body.Bytes()))
	assert.Equal(t, 200, recorder.Code)
}
Ejemplo n.º 19
0
func TestLogger_Add(t *testing.T) {
	logger := newLogger()

	assert.Equal(t, 0, len(logger.data.Rows))

	logger.add("foo", "log")
	assert.Equal(t, 1, len(logger.data.Rows))
}
Ejemplo n.º 20
0
func TestRouter_GetVar(t *testing.T) {
	defer resetGlobalEnv()
	router := New()
	env["global-foo"] = "global-foo"
	assert.Equal(t, "global-foo", router.GetVar("global-foo"))
	router.env["global-foo"] = "router-foo"
	assert.Equal(t, "router-foo", router.GetVar("global-foo"))
}
Ejemplo n.º 21
0
func TestRecordingsHandler_WithExistingdIdAndWrongArtistId(t *testing.T) {
	// Artist is Guns'n'Roses but release is "Random Access Memories" by Daft Punk
	recorder := newTestRequest("GET", "/artists/eeb1195b-f213-4ce1-b28c-8565211f8e43/releases/79215cdf-4764-4dee-b0b9-fec1643df7c5/recordings.json")

	body := string(recorder.Body.Bytes())
	assert.Equal(t, `{"error":"release not found"}`+"\n", body)
	assert.Equal(t, 404, recorder.Code)
}
Ejemplo n.º 22
0
func TestNotFound(t *testing.T) {
	recorder := newTestRequest("GET", "/foo/bar")

	assert.Equal(t, http.StatusNotFound, recorder.Code)
	assert.Equal(t, "text/html", recorder.HeaderMap.Get("Content-Type"))
	expectedBody := "404 page not found"
	assert.Equal(t, expectedBody, string(recorder.Body.Bytes()))
}
Ejemplo n.º 23
0
func TestNew(t *testing.T) {
	c := New(&Environment{
		SearchApiKey:  "foo",
		DisplayApiKey: "bar",
	})
	assert.Equal(t, "foo", c.searchApiKey)
	assert.Equal(t, "bar", c.displayApiKey)
}
Ejemplo n.º 24
0
func TestRootPath(t *testing.T) {
	resetGlobalEnv()
	assert.Equal(t, ".", RootPath())

	SetVar("root", "foo")
	assert.Equal(t, "foo", RootPath())
	resetGlobalEnv()
}
Ejemplo n.º 25
0
func TestHost(t *testing.T) {
	InitSettings()
	assert.Equal(t, DefaultHost, Host())

	os.Setenv("HOST", "1.2.3.4")
	InitSettings()
	assert.Equal(t, "1.2.3.4", Host())
}
Ejemplo n.º 26
0
func TestEnv(t *testing.T) {
	resetGlobalEnv()
	assert.Equal(t, EnvDevelopment, Env())

	SetVar("env", "production")
	assert.Equal(t, "production", Env())
	resetGlobalEnv()
}
Ejemplo n.º 27
0
func TestResponseWriter(t *testing.T) {
	routerEnv := make(map[string]interface{})
	rw := newTestResponseWriter(&routerEnv)
	assert.Equal(t, http.StatusOK, rw.statusCode)
	assert.Equal(t, 0, len(rw.env))
	assert.Equal(t, &routerEnv, rw.routerEnv)
	assert.Equal(t, 0, len(rw.beforeWriteHandlers))
}
Ejemplo n.º 28
0
func TestGetStringVar(t *testing.T) {
	resetGlobalEnv()

	assert.Equal(t, "", getStringVar("foo"))
	SetVar("foo", "bar")
	assert.Equal(t, "bar", getStringVar("foo"))

	resetGlobalEnv()
}
Ejemplo n.º 29
0
func TestTranslation_Translate(t *testing.T) {
	var tr *Translation

	tr = NewTranslation("greeting", "hello")
	assert.Equal(t, "hello", tr.Format())

	tr = NewTranslation("greeting", "hello %s")
	assert.Equal(t, "hello world", tr.Format("world"))
}
Ejemplo n.º 30
0
func TestReleaseGroupHandler_WithExistingReleaseGroupId(t *testing.T) {
	recorder := newTestRequest("GET", "/release-groups/aa997ea0-2936-40bd-884d-3af8a0e064dc.json")

	body := string(recorder.Body.Bytes())
	expectedBody := `{"id":"aa997ea0-2936-40bd-884d-3af8a0e064dc","name":"Random Access Memories","comment":"","firstReleaseDate":"2013-05-17","type":"Album","artists":[{"id":"056e4f3e-d505-4dad-8ec1-d04f521cbb56","name":"Daft Punk"}]}` + "\n"

	assert.Equal(t, expectedBody, body)
	assert.Equal(t, 200, recorder.Code)
}