예제 #1
0
파일: server_test.go 프로젝트: vsco/dcdr
func TestHTTPCaching(t *testing.T) {
	srv := mockServer()
	ts := time.Now().Unix()
	fm := models.EmptyFeatureMap()
	fm.Dcdr.Info.CurrentSHA = "current-sha"
	fm.Dcdr.Info.LastModifiedDate = ts
	srv.Client.SetFeatureMap(fm)

	resp := builder.WithMux(srv).
		Get(srv.config.Server.Endpoint).
		Header(middleware.IfNoneMatchHeader, fm.Dcdr.Info.CurrentSHA).Do()

	http_assert.Response(t, resp.Response).
		HasStatusCode(http.StatusNotModified).
		ContainsHeaderValue(middleware.EtagHeader, fm.Dcdr.CurrentSHA()).
		ContainsHeaderValue(middleware.LastModifiedHeader, time.Unix(ts, 0).Format(time.RFC1123)).
		ContainsHeaderValue(middleware.CacheControlHeader, middleware.CacheControl).
		ContainsHeaderValue(middleware.PragmaHeader, middleware.Pragma).
		ContainsHeaderValue(middleware.ExpiresHeader, middleware.Expires)

	resp = builder.WithMux(srv).
		Get(srv.config.Server.Endpoint).
		Header(middleware.IfNoneMatchHeader, "").Do()

	http_assert.Response(t, resp.Response).
		HasStatusCode(http.StatusOK).
		ContainsHeaderValue(middleware.EtagHeader, fm.Dcdr.CurrentSHA()).
		ContainsHeaderValue(middleware.CacheControlHeader, middleware.CacheControl).
		ContainsHeaderValue(middleware.PragmaHeader, middleware.Pragma).
		ContainsHeaderValue(middleware.ExpiresHeader, middleware.Expires)
}
예제 #2
0
func TestJSONCases(t *testing.T) {
	s := server()
	bldr := WithMux(s)

	hsh := map[string]string{
		"foo": "bar",
		"a":   "b",
		"b":   "c",
	}
	resp := bldr.Post("/json").JSON(hsh).Do()
	assert.Response(t, resp.Response).ContainsJSON(hsh)

	ar := [3]string{"a", "b", "c"}
	resp = bldr.Post("/json").JSON(ar).Do()
	assert.Response(t, resp.Response).ContainsJSON(ar)
}
예제 #3
0
func TestHeaders(t *testing.T) {
	s := server()

	resp := WithMux(s).Get("/get").Do()

	assert.Response(t, resp.Response).ContainsHeaderValue("Etag", "abcde")
}
예제 #4
0
func TestMethods(t *testing.T) {
	s := server()

	bldr := WithMux(s)

	resp := bldr.Post("/post").Do()
	assert.Response(t, resp.Response).Contains("POST").IsOK()

	resp = bldr.Get("/get").Param("name", "foo").Do()
	assert.Response(t, resp.Response).Contains("GET").IsOK()

	resp = bldr.Put("/put").Do()
	assert.Response(t, resp.Response).Contains("PUT").IsOK()

	resp = bldr.Delete("/delete").Do()
	assert.Response(t, resp.Response).Contains("DELETE").IsOK()

	resp = bldr.Head("/head").Do()
	assert.Response(t, resp.Response).IsOK()

	resp = bldr.Options("/options").Do()
	assert.Response(t, resp.Response).Contains("OPTIONS").IsOK()

	resp = bldr.Patch("/patch").Do()
	assert.Response(t, resp.Response).Contains("PATCH").IsOK()
}
예제 #5
0
func TestJSON(t *testing.T) {
	s := server()

	js := &jsonResponse{
		Foo: "bar",
	}

	resp := WithMux(s).Post("/json").JSON(js).Do()

	assert.Response(t, resp.Response).ContainsJSON(js)
}
예제 #6
0
파일: server_test.go 프로젝트: vsco/dcdr
func TestGetFeatures(t *testing.T) {
	srv := mockServer()
	resp := builder.WithMux(srv).Get(srv.config.Server.Endpoint).Do()
	http_assert.Response(t, resp.Response).
		IsOK().
		IsJSON()

	var m models.FeatureMap
	err := resp.Response.UnmarshalBody(&m)

	assert.NoError(t, err)
	assert.Equal(t, cl.ScopedMap(), &m)
}
예제 #7
0
파일: server_test.go 프로젝트: vsco/dcdr
func TestScopeHeader(t *testing.T) {
	srv := mockServer()
	resp := builder.WithMux(srv).
		Get(srv.config.Server.Endpoint).
		Header(handlers.DcdrScopesHeader, "scope, scope2").Do()

	http_assert.Response(t, resp.Response).
		IsOK().
		IsJSON().
		ContainsHeaderValue(handlers.DcdrScopesHeader, "scope, scope2")

	var m models.FeatureMap
	err := resp.Response.UnmarshalBody(&m)

	assert.NoError(t, err)
	assert.Equal(t, cl.WithScopes("scope").ScopedMap(), &m)
}