當前位置: 首頁>>代碼示例>>Golang>>正文


Golang assert.Equal函數代碼示例

本文整理匯總了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)
}
開發者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


注:本文中的github.com/unrolled/assert.Equal函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。