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")) }
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) }
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"])) }
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()) }
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) }
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) }
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)) }
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) }
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()) }
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)) }
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"])) }
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) }
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"])) }
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)) }
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]) }
func TestPublicPath(t *testing.T) { InitSettings() assert.Equal(t, DefaultPublicPath, PublicPath()) os.Setenv("PUBLIC_PATH", "./foo") InitSettings() assert.Equal(t, "./foo", PublicPath()) }
func TestPort(t *testing.T) { InitSettings() assert.Equal(t, DefaultPort, Port()) os.Setenv("PORT", "12345") InitSettings() assert.Equal(t, "12345", Port()) }
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) }
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)) }
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")) }
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) }
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())) }
func TestNew(t *testing.T) { c := New(&Environment{ SearchApiKey: "foo", DisplayApiKey: "bar", }) assert.Equal(t, "foo", c.searchApiKey) assert.Equal(t, "bar", c.displayApiKey) }
func TestRootPath(t *testing.T) { resetGlobalEnv() assert.Equal(t, ".", RootPath()) SetVar("root", "foo") assert.Equal(t, "foo", RootPath()) resetGlobalEnv() }
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()) }
func TestEnv(t *testing.T) { resetGlobalEnv() assert.Equal(t, EnvDevelopment, Env()) SetVar("env", "production") assert.Equal(t, "production", Env()) resetGlobalEnv() }
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)) }
func TestGetStringVar(t *testing.T) { resetGlobalEnv() assert.Equal(t, "", getStringVar("foo")) SetVar("foo", "bar") assert.Equal(t, "bar", getStringVar("foo")) resetGlobalEnv() }
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")) }
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) }