本文整理汇总了Golang中github.com/insionng/vodka/libraries/stretchr/testify/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
}
}
示例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())
}
}
示例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)
})
}
示例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())
}
示例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)
}
}
示例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)
}
示例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"))
}
示例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"))
}
示例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))
}
}
示例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))
}
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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")
}