本文整理汇总了Golang中github.com/insionng/vodka/libraries/stretchr/testify/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestRouterMatchAny
func TestRouterMatchAny(t *testing.T) {
e := New()
r := e.router
// Routes
r.Add(GET, "/", func(*Context) error {
return nil
}, e)
r.Add(GET, "/*", func(*Context) error {
return nil
}, e)
r.Add(GET, "/users/*", func(*Context) error {
return nil
}, e)
c := NewContext(nil, nil, e)
h, _ := r.Find(GET, "/", c)
if assert.NotNil(t, h) {
assert.Equal(t, "", c.P(0))
}
h, _ = r.Find(GET, "/download", c)
if assert.NotNil(t, h) {
assert.Equal(t, "download", c.P(0))
}
h, _ = r.Find(GET, "/users/joe", c)
if assert.NotNil(t, h) {
assert.Equal(t, "joe", c.P(0))
}
}
开发者ID:hiproz,项目名称:vodka,代码行数:31,代码来源:router_test.go
示例2: TestGzip
func TestGzip(t *testing.T) {
req, _ := http.NewRequest(vodka.GET, "/", nil)
rec := httptest.NewRecorder()
c := vodka.NewContext(req, vodka.NewResponse(rec), vodka.New())
h := func(c *vodka.Context) error {
c.Response().Write([]byte("test")) // For Content-Type sniffing
return nil
}
// Skip if no Accept-Encoding header
Gzip()(h)(c)
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, "test", rec.Body.String())
req, _ = http.NewRequest(vodka.GET, "/", nil)
req.Header.Set(vodka.AcceptEncoding, "gzip")
rec = httptest.NewRecorder()
c = vodka.NewContext(req, vodka.NewResponse(rec), vodka.New())
// Gzip
Gzip()(h)(c)
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, "gzip", rec.Header().Get(vodka.ContentEncoding))
assert.Contains(t, rec.Header().Get(vodka.ContentType), vodka.TextPlain)
r, err := gzip.NewReader(rec.Body)
defer r.Close()
if assert.NoError(t, err) {
buf := new(bytes.Buffer)
buf.ReadFrom(r)
assert.Equal(t, "test", buf.String())
}
}
开发者ID:hiproz,项目名称:vodka,代码行数:32,代码来源:compress_test.go
示例3: TestVodkaHandler
func TestVodkaHandler(t *testing.T) {
e := New()
// HandlerFunc
e.Get("/1", HandlerFunc(func(c *Context) error {
return c.String(http.StatusOK, "1")
}))
// func(*vodka.Context) error
e.Get("/2", func(c *Context) error {
return c.String(http.StatusOK, "2")
})
// http.Handler/http.HandlerFunc
e.Get("/3", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("3"))
}))
// func(http.ResponseWriter, *http.Request)
e.Get("/4", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("4"))
})
for _, p := range []string{"1", "2", "3", "4"} {
c, b := request(GET, "/"+p, e)
assert.Equal(t, http.StatusOK, c)
assert.Equal(t, p, b)
}
// Unknown
assert.Panics(t, func() {
e.Get("/5", nil)
})
}
开发者ID:hiproz,项目名称:vodka,代码行数:34,代码来源:vodka_test.go
示例4: TestResponse
func TestResponse(t *testing.T) {
w := httptest.NewRecorder()
r := NewResponse(w)
// SetWriter
r.SetWriter(w)
// Writer
assert.Equal(t, w, r.Writer())
// Header
assert.NotNil(t, r.Header())
// WriteHeader
r.WriteHeader(http.StatusOK)
assert.Equal(t, http.StatusOK, r.status)
// Committed
assert.True(t, r.committed)
// Already committed
r.WriteHeader(http.StatusTeapot)
assert.NotEqual(t, http.StatusTeapot, r.Status())
// Status
r.status = http.StatusOK
assert.Equal(t, http.StatusOK, r.Status())
// Write
s := "vodka"
_, err := r.Write([]byte(s))
assert.NoError(t, err)
// Flush
r.Flush()
// Size
assert.EqualValues(t, len(s), r.Size())
// Committed
assert.Equal(t, true, r.Committed())
// Hijack
assert.Panics(t, func() {
r.Hijack()
})
// CloseNotify
assert.Panics(t, func() {
r.CloseNotify()
})
// reset
r.reset(httptest.NewRecorder())
}
开发者ID:hiproz,项目名称:vodka,代码行数:55,代码来源:response_test.go
示例5: testBind
func testBind(t *testing.T, c *Context, ct string) {
c.request.Header.Set(ContentType, ct)
u := new(user)
err := c.Bind(u)
if ct == "" {
assert.Error(t, UnsupportedMediaType)
} else if assert.NoError(t, err) {
assert.Equal(t, "1", u.ID)
assert.Equal(t, "Joe", u.Name)
}
}
开发者ID:hiproz,项目名称:vodka,代码行数:11,代码来源:context_test.go
示例6: TestVodkaGroup
func TestVodkaGroup(t *testing.T) {
e := New()
buf := new(bytes.Buffer)
e.Use(func(*Context) error {
buf.WriteString("0")
return nil
})
h := func(*Context) error { return nil }
//--------
// Routes
//--------
e.Get("/users", h)
// Group
g1 := e.Group("/group1")
g1.Use(func(*Context) error {
buf.WriteString("1")
return nil
})
g1.Get("/", h)
// Group with no parent middleware
g2 := e.Group("/group2", func(*Context) error {
buf.WriteString("2")
return nil
})
g2.Get("/", h)
// Nested groups
g3 := e.Group("/group3")
g4 := g3.Group("/group4")
g4.Get("/", func(c *Context) error {
return c.Status(http.StatusOK)
})
request(GET, "/users", e)
// println(len(e.middleware))
assert.Equal(t, "0", buf.String())
buf.Reset()
request(GET, "/group1/", e)
// println(len(g1.vodka.middleware))
assert.Equal(t, "01", buf.String())
buf.Reset()
request(GET, "/group2/", e)
assert.Equal(t, "2", buf.String())
buf.Reset()
c, _ := request(GET, "/group3/group4/", e)
assert.Equal(t, http.StatusOK, c)
}
开发者ID:hiproz,项目名称:vodka,代码行数:54,代码来源:vodka_test.go
示例7: TestContextForm
func TestContextForm(t *testing.T) {
f := make(url.Values)
f.Set("name", "joe")
f.Set("email", "[email protected]")
req, err := http.NewRequest(POST, "/", strings.NewReader(f.Encode()))
assert.NoError(t, err)
req.Header.Add(ContentType, ApplicationForm)
c := NewContext(req, nil, New())
assert.Equal(t, "joe", c.Form("name"))
assert.Equal(t, "[email protected]", c.Form("email"))
}
开发者ID:hiproz,项目名称:vodka,代码行数:13,代码来源:context_test.go
示例8: TestContextQuery
func TestContextQuery(t *testing.T) {
q := make(url.Values)
q.Set("name", "joe")
q.Set("email", "[email protected]")
req, err := http.NewRequest(GET, "/", nil)
assert.NoError(t, err)
req.URL.RawQuery = q.Encode()
c := NewContext(req, nil, New())
assert.Equal(t, "joe", c.Query("name"))
assert.Equal(t, "[email protected]", c.Query("email"))
}
开发者ID:hiproz,项目名称:vodka,代码行数:14,代码来源:context_test.go
示例9: TestRouterTwoParam
func TestRouterTwoParam(t *testing.T) {
e := New()
r := e.router
r.Add(GET, "/users/:uid/files/:fid", func(*Context) error {
return nil
}, e)
c := NewContext(nil, nil, e)
h, _ := r.Find(GET, "/users/1/files/1", c)
if assert.NotNil(t, h) {
assert.Equal(t, "1", c.P(0))
assert.Equal(t, "1", c.P(1))
}
}
开发者ID:hiproz,项目名称:vodka,代码行数:14,代码来源:router_test.go
示例10: TestRouterMicroParam
func TestRouterMicroParam(t *testing.T) {
e := New()
r := e.router
r.Add(GET, "/:a/:b/:c", func(c *Context) error {
return nil
}, e)
c := NewContext(nil, nil, e)
h, _ := r.Find(GET, "/1/2/3", c)
if assert.NotNil(t, h) {
assert.Equal(t, "1", c.P(0))
assert.Equal(t, "2", c.P(1))
assert.Equal(t, "3", c.P(2))
}
}
开发者ID:hiproz,项目名称:vodka,代码行数:14,代码来源:router_test.go
示例11: TestVodkaFavicon
func TestVodkaFavicon(t *testing.T) {
e := New()
e.Favicon("examples/website/public/favicon.ico")
c, b := request(GET, "/favicon.ico", e)
assert.Equal(t, http.StatusOK, c)
assert.NotEmpty(t, b)
}
开发者ID:hiproz,项目名称:vodka,代码行数:7,代码来源:vodka_test.go
示例12: TestVodkaIndex
func TestVodkaIndex(t *testing.T) {
e := New()
e.Index("examples/website/public/index.html")
c, b := request(GET, "/", e)
assert.Equal(t, http.StatusOK, c)
assert.NotEmpty(t, b)
}
开发者ID:hiproz,项目名称:vodka,代码行数:7,代码来源:vodka_test.go
示例13: TestVodkaBadRequest
func TestVodkaBadRequest(t *testing.T) {
e := New()
r, _ := http.NewRequest("INVALID", "/files", nil)
w := httptest.NewRecorder()
e.ServeHTTP(w, r)
assert.Equal(t, http.StatusBadRequest, w.Code)
}
开发者ID:hiproz,项目名称:vodka,代码行数:7,代码来源:vodka_test.go
示例14: TestVodkaNotFound
func TestVodkaNotFound(t *testing.T) {
e := New()
r, _ := http.NewRequest(GET, "/files", nil)
w := httptest.NewRecorder()
e.ServeHTTP(w, r)
assert.Equal(t, http.StatusNotFound, w.Code)
}
开发者ID:hiproz,项目名称:vodka,代码行数:7,代码来源:vodka_test.go
示例15: TestVodkaWebSocket
func TestVodkaWebSocket(t *testing.T) {
fmt.Println("TestVodkaWebSocket start")
e := New()
e.WebSocket("/ws", func(c *Context) error {
fmt.Println("Got WebSocket Request!")
c.socket.Write([]byte("test"))
return nil
})
srv := httptest.NewServer(e)
defer srv.Close()
addr := srv.Listener.Addr().String()
origin := "http://localhost"
url := fmt.Sprintf("ws://%s/ws", addr)
ws, err := websocket.Dial(url, "", origin)
if assert.NoError(t, err) {
ws.Write([]byte("test"))
defer ws.Close()
buf := new(bytes.Buffer)
buf.ReadFrom(ws)
assert.Equal(t, "test", buf.String())
fmt.Println("Return buf.String():", buf.String())
}
fmt.Println("TestVodkaWebSocket end")
}
开发者ID:hiproz,项目名称:vodka,代码行数:26,代码来源:vodka_test.go
示例16: TestRouterAPI
func TestRouterAPI(t *testing.T) {
e := New()
r := e.router
for _, route := range api {
r.Add(route.Method, route.Path, func(c *Context) error {
return nil
}, e)
}
response := NewResponse(httptest.NewRecorder())
c := NewContext(nil, response, e)
for _, route := range api {
h, _ := r.Find(route.Method, route.Path, c)
if assert.NotNil(t, h) {
for i, n := range c.pnames {
if assert.NotEmpty(t, n) {
assert.Equal(t, ":"+n, c.P(i))
}
}
h(c)
}
}
}
开发者ID:hiproz,项目名称:vodka,代码行数:25,代码来源:router_test.go
示例17: TestStripTrailingSlash
func TestStripTrailingSlash(t *testing.T) {
e := New()
e.StripTrailingSlash()
r, _ := http.NewRequest(GET, "/users/", nil)
w := httptest.NewRecorder()
e.ServeHTTP(w, r)
assert.Equal(t, http.StatusNotFound, w.Code)
}
开发者ID:hiproz,项目名称:vodka,代码行数:8,代码来源:vodka_test.go
示例18: TestVodkaStatic
func TestVodkaStatic(t *testing.T) {
e := New()
// OK
e.Static("/scripts", "examples/website/public/scripts")
c, b := request(GET, "/scripts/main.js", e)
assert.Equal(t, http.StatusOK, c)
assert.NotEmpty(t, b)
// No file
e.Static("/scripts", "examples/website/public/scripts")
c, _ = request(GET, "/scripts/index.js", e)
assert.Equal(t, http.StatusNotFound, c)
// Directory
e.Static("/scripts", "examples/website/public/scripts")
c, _ = request(GET, "/scripts", e)
assert.Equal(t, http.StatusForbidden, c)
// Directory with index.html
e.Static("/", "examples/website/public")
c, r := request(GET, "/", e)
assert.Equal(t, http.StatusOK, c)
assert.Equal(t, true, strings.HasPrefix(r, "<!doctype html>"))
// Sub-directory with index.html
c, r = request(GET, "/folder", e)
assert.Equal(t, http.StatusOK, c)
assert.Equal(t, "sub directory", r)
}
开发者ID:hiproz,项目名称:vodka,代码行数:30,代码来源:vodka_test.go
示例19: TestVodkaRoutes
func TestVodkaRoutes(t *testing.T) {
e := New()
h := func(*Context) error { return nil }
routes := []Route{
{GET, "/users/:user/events", h},
{GET, "/users/:user/events/public", h},
{POST, "/repos/:owner/:repo/git/refs", h},
{POST, "/repos/:owner/:repo/git/tags", h},
}
for _, r := range routes {
e.add(r.Method, r.Path, h)
}
for i, r := range e.Routes() {
assert.Equal(t, routes[i].Method, r.Method)
assert.Equal(t, routes[i].Path, r.Path)
}
}
开发者ID:hiproz,项目名称:vodka,代码行数:18,代码来源:vodka_test.go
示例20: TestVodkaURL
func TestVodkaURL(t *testing.T) {
e := New()
static := func(*Context) error { return nil }
getUser := func(*Context) error { return nil }
getFile := func(*Context) error { return nil }
e.Get("/static/file", static)
e.Get("/users/:id", getUser)
g := e.Group("/group")
g.Get("/users/:uid/files/:fid", getFile)
assert.Equal(t, "/static/file", e.URL(static))
assert.Equal(t, "/users/:id", e.URL(getUser))
assert.Equal(t, "/users/1", e.URL(getUser, "1"))
assert.Equal(t, "/group/users/1/files/:fid", e.URL(getFile, "1"))
assert.Equal(t, "/group/users/1/files/1", e.URL(getFile, "1", "1"))
}
开发者ID:hiproz,项目名称:vodka,代码行数:18,代码来源:vodka_test.go
注:本文中的github.com/insionng/vodka/libraries/stretchr/testify/assert.Equal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论