本文整理汇总了Golang中github.com/unrolled/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestHandlerAppendSlash
func TestHandlerAppendSlash(t *testing.T) {
oldAppendSetting := Settings.Bool("append_slash", false)
oldAppendRedirectSetting := Settings.Bool("append_slash_should_redirect", true)
Settings.Set("append_slash", false)
Pattern("/hello", &AppendSlashBaseHandler{})
r, _ := http.NewRequest("GET", "/hello/", nil)
rec := httptest.NewRecorder()
Mux.ServeHTTP(rec, r)
assert.Equal(t, http.StatusNotFound, rec.Code)
Mux = &PatternServeMux{}
Settings.Set("append_slash", true)
Pattern("/hello", &AppendSlashBaseHandler{})
r, _ = http.NewRequest("GET", "/hello/", nil)
rec = httptest.NewRecorder()
Mux.ServeHTTP(rec, r)
assert.Equal(t, http.StatusOK, rec.Code)
Mux = &PatternServeMux{}
Settings.Set("append_slash", true)
Settings.Set("append_slash_should_redirect", true)
Pattern("/hello", &AppendSlashBaseHandler{})
r, _ = http.NewRequest("GET", "/hello/", nil)
rec = httptest.NewRecorder()
Mux.ServeHTTP(rec, r)
assert.Equal(t, http.StatusMovedPermanently, rec.Code)
Mux = &PatternServeMux{}
// Set it back to what it was.
Settings.Set("append_slash", oldAppendSetting)
Settings.Set("append_slash_should_redirect", oldAppendRedirectSetting)
}
示例2: TestResponseNewSlice
func TestResponseNewSlice(t *testing.T) {
resp := NewHttpResponse([]string{"hellowww", "aaaaa"})
assert.Equal(t, `["hellowww","aaaaa"]`, resp.Content)
assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, "application/json; charset=utf-8", resp.ContentType)
}
示例3: TestResponseNewMap
func TestResponseNewMap(t *testing.T) {
v := map[string]interface{}{"k": "value"}
resp := NewHttpResponse(v)
assert.Equal(t, `{"k":"value"}`, resp.Content)
assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, "application/json; charset=utf-8", resp.ContentType)
}
示例4: TestResponseNewNoParams
func TestResponseNewNoParams(t *testing.T) {
resp := NewHttpResponse()
assert.Equal(t, "", resp.Content)
assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, "text/html; charset=utf-8", resp.ContentType)
assert.Equal(t, 0, len(resp.Header))
assert.Equal(t, 0, len(resp.Context))
}
示例5: TestResponseNewThreeParams
func TestResponseNewThreeParams(t *testing.T) {
resp := NewHttpResponse("My Content", 202, "text/plain; charset=latin1")
assert.Equal(t, "My Content", resp.Content)
assert.Equal(t, 202, resp.StatusCode)
assert.Equal(t, "text/plain; charset=latin1", resp.ContentType)
assert.Equal(t, 0, len(resp.Header))
assert.Equal(t, 0, len(resp.Context))
}
示例6: TestRequestFragementValue
func TestRequestFragementValue(t *testing.T) {
in, _ := http.NewRequest("GET", "example.com?foo=bar#batman", nil)
req := NewHttpRequest(in, make(url.Values))
assert.Equal(t, "batman", req.FragmentValue())
in, _ = http.NewRequest("GET", "example.com?foo=bar", nil)
req = NewHttpRequest(in, make(url.Values))
assert.Equal(t, "", req.FragmentValue())
}
示例7: TestDictObjExists
func TestDictObjExists(t *testing.T) {
dictObj := NewDictObj()
dictObj.Set("a", "AAA")
dictObj.Set("b", "BBB")
assert.Equal(t, true, dictObj.Exists("a"))
assert.Equal(t, true, dictObj.Exists("b"))
assert.Equal(t, false, dictObj.Exists("c"))
}
示例8: TestRequestNew
func TestRequestNew(t *testing.T) {
b := bytes.NewBufferString("sample body here")
in, _ := http.NewRequest("GET", "http://example.com", b)
req := NewHttpRequest(in, make(url.Values))
assert.Equal(t, "sample body here", req.BodyString)
assert.Equal(t, 0, len(req.PathArgs))
assert.Equal(t, 0, len(req.Registry))
assert.Equal(t, "example.com", req.URL.Host)
assert.Equal(t, "GET", req.Method)
}
示例9: TestServerVersionMap
func TestServerVersionMap(t *testing.T) {
oldVer := Version
Version = "2.5.11"
vmap := VersionMap()
assert.Equal(t, 2, vmap[0])
assert.Equal(t, 5, vmap[1])
assert.Equal(t, 11, vmap[2])
Version = oldVer
}
示例10: TestHandlerPrepareFinish
func TestHandlerPrepareFinish(t *testing.T) {
defer func() { Mux = &PatternServeMux{} }()
Pattern("/", &PrepFinHandler{})
r, _ := http.NewRequest("GET", "/", nil)
rec := httptest.NewRecorder()
Mux.ServeHTTP(rec, r)
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, "NEW-PRE", rec.Body.String())
assert.Equal(t, "NEW-PRE-FIN", OneOffPreFinTestObj)
}
示例11: TestEarlyResponseMiddleware
//---
func TestEarlyResponseMiddleware(t *testing.T) {
defer func() { Mux = &PatternServeMux{} }()
defer func() { middlewares = []MiddlewareInterface{} }()
Pattern("/", &MiddleHandler{})
Middleware(&Finishware{})
r, _ := http.NewRequest("GET", "/", nil)
rec := httptest.NewRecorder()
Mux.ServeHTTP(rec, r)
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, "Ending request early.", rec.Body.String())
}
示例12: TestBasicMiddleware
func TestBasicMiddleware(t *testing.T) {
defer func() { Mux = &PatternServeMux{} }()
defer func() { middlewares = []MiddlewareInterface{} }()
Pattern("/", &MiddleHandler{})
Middleware(&Firstware{})
r, _ := http.NewRequest("GET", "/", nil)
rec := httptest.NewRecorder()
Mux.ServeHTTP(rec, r)
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, "bar", rec.Body.String())
assert.Equal(t, "superman", rec.Header().Get("X-post"))
}
示例13: TestRequestIsSecure
func TestRequestIsSecure(t *testing.T) {
in, _ := http.NewRequest("GET", "http://example.com", nil)
req := NewHttpRequest(in, make(url.Values))
assert.Equal(t, false, req.IsSecure())
in, _ = http.NewRequest("GET", "https://secure-example.com", nil)
req = NewHttpRequest(in, make(url.Values))
assert.Equal(t, true, req.IsSecure())
in, _ = http.NewRequest("GET", "example.com", nil)
in.Header.Add("X-Forwarded-Proto", "httPS")
req = NewHttpRequest(in, make(url.Values))
assert.Equal(t, true, req.IsSecure())
}
示例14: TestSettingsSetDebug
func TestSettingsSetDebug(t *testing.T) {
assert.Equal(t, false, Debug)
dictObj := NewDictObj()
dictObj.Set("debug", true)
assert.Equal(t, true, Debug)
dictObj.Set("debugggger", false)
assert.Equal(t, true, Debug)
dictObj.Set("debug", false)
assert.Equal(t, false, Debug)
}
示例15: TestDictObjJsonData
func TestDictObjJsonData(t *testing.T) {
tmp := make(map[string]interface{})
err := json.Unmarshal([]byte(`{"intOne":1,"intTwo":23456789}`), &tmp)
if err != nil {
t.Errorf("Json unmarshal error: %q", err)
}
dictObj := NewDictObj()
dictObj.Set("a", tmp["intOne"])
dictObj.Set("b", tmp["intTwo"])
assert.Equal(t, 1, dictObj.Int("a"))
assert.Equal(t, 23456789, dictObj.Int("b"))
}