本文整理汇总了Golang中github.com/unrolled/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:unrolled,项目名称:tango,代码行数:33,代码来源:handler_test.go
示例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)
}
开发者ID:unrolled,项目名称:tango,代码行数:7,代码来源:response_test.go
示例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)
}
开发者ID:unrolled,项目名称:tango,代码行数:8,代码来源:response_test.go
示例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))
}
开发者ID:unrolled,项目名称:tango,代码行数:9,代码来源:response_test.go
示例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))
}
开发者ID:unrolled,项目名称:tango,代码行数:9,代码来源:response_test.go
示例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())
}
开发者ID:unrolled,项目名称:tango,代码行数:9,代码来源:request_test.go
示例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"))
}
开发者ID:unrolled,项目名称:tango,代码行数:10,代码来源:settings_test.go
示例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)
}
开发者ID:unrolled,项目名称:tango,代码行数:11,代码来源:request_test.go
示例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
}
开发者ID:unrolled,项目名称:tango,代码行数:11,代码来源:server_test.go
示例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)
}
开发者ID:unrolled,项目名称:tango,代码行数:12,代码来源:handler_test.go
示例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())
}
开发者ID:unrolled,项目名称:tango,代码行数:13,代码来源:middleware_test.go
示例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"))
}
开发者ID:unrolled,项目名称:tango,代码行数:13,代码来源:middleware_test.go
示例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())
}
开发者ID:unrolled,项目名称:tango,代码行数:14,代码来源:request_test.go
示例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)
}
开发者ID:unrolled,项目名称:tango,代码行数:14,代码来源:settings_test.go
示例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"))
}
开发者ID:unrolled,项目名称:tango,代码行数:16,代码来源:settings_test.go
示例16: TestFinishMiddleware
func TestFinishMiddleware(t *testing.T) {
defer func() { Mux = &PatternServeMux{} }()
defer func() { middlewares = []MiddlewareInterface{} }()
Pattern("/", &MiddleHandler{})
// Finish should not allow Firstware to be called.
Middleware(&Finishware{})
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, "FIRST", rec.Header().Get("X-post"))
}
开发者ID:unrolled,项目名称:tango,代码行数:17,代码来源:middleware_test.go
示例17: TestDictObjArray
func TestDictObjArray(t *testing.T) {
tmp := make(map[string]interface{})
err := json.Unmarshal([]byte(`{"first":["one", "two", "three"], "second":["1", "2"]}`), &tmp)
if err != nil {
t.Errorf("Json unmarshal error: %q", err)
}
dictObj := NewDictObj()
dictObj.Set("a", tmp["first"])
assert.Equal(t, tmp["first"].([]interface{}), dictObj.Array("a"))
assert.Equal(t, tmp["second"].([]interface{}), dictObj.Array("b", tmp["second"].([]interface{})))
assert.Panic(t, "Array received too many args: [2]", func() {
dictObj.Array("z", nil, nil)
})
}
开发者ID:unrolled,项目名称:tango,代码行数:18,代码来源:settings_test.go
示例18: TestDictObjString
func TestDictObjString(t *testing.T) {
dictObj := NewDictObj()
dictObj.Set("a", "AAA")
dictObj.Set("b", "BBB")
assert.Equal(t, "AAA", dictObj.String("a"))
assert.Equal(t, "BBB", dictObj.String("b"))
dictObj.Set("a", "not AAA")
assert.Equal(t, "not AAA", dictObj.String("a"))
assert.Equal(t, "CCC", dictObj.String("c", "CCC"))
assert.Panic(t, "String received too many args: [2]", func() {
dictObj.String("z", "default", "bad")
})
}
开发者ID:unrolled,项目名称:tango,代码行数:18,代码来源:settings_test.go
示例19: TestDictObjBool
func TestDictObjBool(t *testing.T) {
dictObj := NewDictObj()
dictObj.Set("a", true)
dictObj.Set("b", false)
assert.Equal(t, true, dictObj.Bool("a"))
assert.Equal(t, false, dictObj.Bool("b"))
assert.Equal(t, true, dictObj.Bool("c", true))
assert.Equal(t, false, dictObj.Bool("d", false))
dictObj.Set("a", false)
assert.Equal(t, false, dictObj.Bool("a"))
assert.Panic(t, "Bool received too many args: [3]", func() {
dictObj.Bool("z", true, false, true)
})
}
开发者ID:unrolled,项目名称:tango,代码行数:18,代码来源:settings_test.go
示例20: TestDictObjInt
func TestDictObjInt(t *testing.T) {
dictObj := NewDictObj()
dictObj.Set("a", 1)
dictObj.Set("b", 12345678901234)
assert.Equal(t, 1, dictObj.Int("a"))
assert.Equal(t, 12345678901234, dictObj.Int("b"))
dictObj.Set("a", 2)
assert.Equal(t, 2, dictObj.Int("a"))
assert.Equal(t, 55, dictObj.Int("c", 55))
assert.Panic(t, "Int received too many args: [2]", func() {
dictObj.Int("z", 12, 34)
})
}
开发者ID:unrolled,项目名称:tango,代码行数:18,代码来源:settings_test.go
注:本文中的github.com/unrolled/assert.Equal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论