Skip to content

Commit

Permalink
update assert param(expect, actual) position (gin-gonic#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkerou authored and appleboy committed Nov 21, 2017
1 parent 7e5aff8 commit eeb5784
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 271 deletions.
286 changes: 143 additions & 143 deletions context_test.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions gin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ func TestCreateEngine(t *testing.T) {
// router.LoadHTMLGlob("*.testtmpl")
// r := router.HTMLRender.(render.HTMLDebug)
// assert.Empty(t, r.Files)
// assert.Equal(t, r.Glob, "*.testtmpl")
// assert.Equal(t, "*.testtmpl", r.Glob)
//
// router.LoadHTMLFiles("index.html.testtmpl", "login.html.testtmpl")
// r = router.HTMLRender.(render.HTMLDebug)
// assert.Empty(t, r.Glob)
// assert.Equal(t, r.Files, []string{"index.html", "login.html"})
// assert.Equal(t, []string{"index.html", "login.html"}, r.Files)
// SetMode(TestMode)
// }

Expand Down
24 changes: 12 additions & 12 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ func TestLogger(t *testing.T) {
}

func TestColorForMethod(t *testing.T) {
assert.Equal(t, colorForMethod("GET"), string([]byte{27, 91, 57, 55, 59, 52, 52, 109}), "get should be blue")
assert.Equal(t, colorForMethod("POST"), string([]byte{27, 91, 57, 55, 59, 52, 54, 109}), "post should be cyan")
assert.Equal(t, colorForMethod("PUT"), string([]byte{27, 91, 57, 55, 59, 52, 51, 109}), "put should be yellow")
assert.Equal(t, colorForMethod("DELETE"), string([]byte{27, 91, 57, 55, 59, 52, 49, 109}), "delete should be red")
assert.Equal(t, colorForMethod("PATCH"), string([]byte{27, 91, 57, 55, 59, 52, 50, 109}), "patch should be green")
assert.Equal(t, colorForMethod("HEAD"), string([]byte{27, 91, 57, 55, 59, 52, 53, 109}), "head should be magenta")
assert.Equal(t, colorForMethod("OPTIONS"), string([]byte{27, 91, 57, 48, 59, 52, 55, 109}), "options should be white")
assert.Equal(t, colorForMethod("TRACE"), string([]byte{27, 91, 48, 109}), "trace is not defined and should be the reset color")
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 52, 109}), colorForMethod("GET"), "get should be blue")
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 54, 109}), colorForMethod("POST"), "post should be cyan")
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 51, 109}), colorForMethod("PUT"), "put should be yellow")
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 49, 109}), colorForMethod("DELETE"), "delete should be red")
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 50, 109}), colorForMethod("PATCH"), "patch should be green")
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 53, 109}), colorForMethod("HEAD"), "head should be magenta")
assert.Equal(t, string([]byte{27, 91, 57, 48, 59, 52, 55, 109}), colorForMethod("OPTIONS"), "options should be white")
assert.Equal(t, string([]byte{27, 91, 48, 109}), colorForMethod("TRACE"), "trace is not defined and should be the reset color")
}

func TestColorForStatus(t *testing.T) {
assert.Equal(t, colorForStatus(200), string([]byte{27, 91, 57, 55, 59, 52, 50, 109}), "2xx should be green")
assert.Equal(t, colorForStatus(301), string([]byte{27, 91, 57, 48, 59, 52, 55, 109}), "3xx should be white")
assert.Equal(t, colorForStatus(404), string([]byte{27, 91, 57, 55, 59, 52, 51, 109}), "4xx should be yellow")
assert.Equal(t, colorForStatus(2), string([]byte{27, 91, 57, 55, 59, 52, 49, 109}), "other things should be red")
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 50, 109}), colorForStatus(200), "2xx should be green")
assert.Equal(t, string([]byte{27, 91, 57, 48, 59, 52, 55, 109}), colorForStatus(301), "3xx should be white")
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 51, 109}), colorForStatus(404), "4xx should be yellow")
assert.Equal(t, string([]byte{27, 91, 57, 55, 59, 52, 49, 109}), colorForStatus(2), "other things should be red")
}

func TestErrorLogger(t *testing.T) {
Expand Down
16 changes: 8 additions & 8 deletions mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ func init() {
}

func TestSetMode(t *testing.T) {
assert.Equal(t, ginMode, testCode)
assert.Equal(t, Mode(), TestMode)
assert.Equal(t, testCode, ginMode)
assert.Equal(t, TestMode, Mode())
os.Unsetenv(ENV_GIN_MODE)

SetMode(DebugMode)
assert.Equal(t, ginMode, debugCode)
assert.Equal(t, Mode(), DebugMode)
assert.Equal(t, debugCode, ginMode)
assert.Equal(t, DebugMode, Mode())

SetMode(ReleaseMode)
assert.Equal(t, ginMode, releaseCode)
assert.Equal(t, Mode(), ReleaseMode)
assert.Equal(t, releaseCode, ginMode)
assert.Equal(t, ReleaseMode, Mode())

SetMode(TestMode)
assert.Equal(t, ginMode, testCode)
assert.Equal(t, Mode(), TestMode)
assert.Equal(t, testCode, ginMode)
assert.Equal(t, TestMode, Mode())

assert.Panics(t, func() { SetMode("unknown") })
}
Expand Down
4 changes: 2 additions & 2 deletions path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ var cleanTests = []struct {

func TestPathClean(t *testing.T) {
for _, test := range cleanTests {
assert.Equal(t, cleanPath(test.path), test.result)
assert.Equal(t, cleanPath(test.result), test.result)
assert.Equal(t, test.result, cleanPath(test.path))
assert.Equal(t, test.result, cleanPath(test.result))
}
}

Expand Down
4 changes: 2 additions & 2 deletions recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestPanicInHandler(t *testing.T) {
// RUN
w := performRequest(router, "GET", "/recovery")
// TEST
assert.Equal(t, w.Code, 500)
assert.Equal(t, 500, w.Code)
assert.Contains(t, buffer.String(), "GET /recovery")
assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem")
assert.Contains(t, buffer.String(), "TestPanicInHandler")
Expand All @@ -39,5 +39,5 @@ func TestPanicWithAbort(t *testing.T) {
// RUN
w := performRequest(router, "GET", "/recovery")
// TEST
assert.Equal(t, w.Code, 400)
assert.Equal(t, 400, w.Code)
}
20 changes: 10 additions & 10 deletions routergroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ func TestRouterGroupBasic(t *testing.T) {
group.Use(func(c *Context) {})

assert.Len(t, group.Handlers, 2)
assert.Equal(t, group.BasePath(), "/hola")
assert.Equal(t, group.engine, router)
assert.Equal(t, "/hola", group.BasePath())
assert.Equal(t, router, group.engine)

group2 := group.Group("manu")
group2.Use(func(c *Context) {}, func(c *Context) {})

assert.Len(t, group2.Handlers, 4)
assert.Equal(t, group2.BasePath(), "/hola/manu")
assert.Equal(t, group2.engine, router)
assert.Equal(t, "/hola/manu", group2.BasePath())
assert.Equal(t, router, group2.engine)
}

func TestRouterGroupBasicHandle(t *testing.T) {
Expand All @@ -44,10 +44,10 @@ func TestRouterGroupBasicHandle(t *testing.T) {
func performRequestInGroup(t *testing.T, method string) {
router := New()
v1 := router.Group("v1", func(c *Context) {})
assert.Equal(t, v1.BasePath(), "/v1")
assert.Equal(t, "/v1", v1.BasePath())

login := v1.Group("/login/", func(c *Context) {}, func(c *Context) {})
assert.Equal(t, login.BasePath(), "/v1/login/")
assert.Equal(t, "/v1/login/", login.BasePath())

handler := func(c *Context) {
c.String(400, "the method was %s and index %d", c.Request.Method, c.index)
Expand Down Expand Up @@ -80,12 +80,12 @@ func performRequestInGroup(t *testing.T, method string) {
}

w := performRequest(router, method, "/v1/login/test")
assert.Equal(t, w.Code, 400)
assert.Equal(t, w.Body.String(), "the method was "+method+" and index 3")
assert.Equal(t, 400, w.Code)
assert.Equal(t, "the method was "+method+" and index 3", w.Body.String())

w = performRequest(router, method, "/v1/test")
assert.Equal(t, w.Code, 400)
assert.Equal(t, w.Body.String(), "the method was "+method+" and index 1")
assert.Equal(t, 400, w.Code)
assert.Equal(t, "the method was "+method+" and index 1", w.Body.String())
}

func TestRouterGroupInvalidStatic(t *testing.T) {
Expand Down
Loading

0 comments on commit eeb5784

Please sign in to comment.