GeezerVison is showing github.com — chore: use http.Status* instead of hard code (#1482) · NodejsMAS/gin@f45c928
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: auth_test.go +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,15 +93,15 @@ func TestBasicAuthSucceed(t *testing.T) { | 93 | 93 | router := New() | 94 | 94 | router.Use(BasicAuth(accounts)) | 95 | 95 | router.GET("/login", func(c *Context) { | 96 | | - c.String(200, c.MustGet(AuthUserKey).(string)) | | 96 | + c.String(http.StatusOK, c.MustGet(AuthUserKey).(string)) | 97 | 97 | }) | 98 | 98 |
| 99 | 99 | w := httptest.NewRecorder() | 100 | 100 | req, _ := http.NewRequest("GET", "/login", nil) | 101 | 101 | req.Header.Set("Authorization", authorizationHeader("admin", "password")) | 102 | 102 | router.ServeHTTP(w, req) | 103 | 103 |
| 104 | | - assert.Equal(t, 200, w.Code) | | 104 | + assert.Equal(t, http.StatusOK, w.Code) | 105 | 105 | assert.Equal(t, "admin", w.Body.String()) | 106 | 106 | } | 107 | 107 |
| @@ -112,7 +112,7 @@ func TestBasicAuth401(t *testing.T) { | 112 | 112 | router.Use(BasicAuth(accounts)) | 113 | 113 | router.GET("/login", func(c *Context) { | 114 | 114 | called = true | 115 | | - c.String(200, c.MustGet(AuthUserKey).(string)) | | 115 | + c.String(http.StatusOK, c.MustGet(AuthUserKey).(string)) | 116 | 116 | }) | 117 | 117 |
| 118 | 118 | w := httptest.NewRecorder() | @@ -121,7 +121,7 @@ func TestBasicAuth401(t *testing.T) { | 121 | 121 | router.ServeHTTP(w, req) | 122 | 122 |
| 123 | 123 | assert.False(t, called) | 124 | | - assert.Equal(t, 401, w.Code) | | 124 | + assert.Equal(t, http.StatusUnauthorized, w.Code) | 125 | 125 | assert.Equal(t, "Basic realm=\"Authorization Required\"", w.HeaderMap.Get("WWW-Authenticate")) | 126 | 126 | } | 127 | 127 |
| @@ -132,7 +132,7 @@ func TestBasicAuth401WithCustomRealm(t *testing.T) { | 132 | 132 | router.Use(BasicAuthForRealm(accounts, "My Custom \"Realm\"")) | 133 | 133 | router.GET("/login", func(c *Context) { | 134 | 134 | called = true | 135 | | - c.String(200, c.MustGet(AuthUserKey).(string)) | | 135 | + c.String(http.StatusOK, c.MustGet(AuthUserKey).(string)) | 136 | 136 | }) | 137 | 137 |
| 138 | 138 | w := httptest.NewRecorder() | @@ -141,6 +141,6 @@ func TestBasicAuth401WithCustomRealm(t *testing.T) { | 141 | 141 | router.ServeHTTP(w, req) | 142 | 142 |
| 143 | 143 | assert.False(t, called) | 144 | | - assert.Equal(t, 401, w.Code) | | 144 | + assert.Equal(t, http.StatusUnauthorized, w.Code) | 145 | 145 | assert.Equal(t, "Basic realm=\"My Custom \\\"Realm\\\"\"", w.HeaderMap.Get("WWW-Authenticate")) | 146 | 146 | } |
Collapse file Copy file name to clipboardExpand all lines: benchmarks_test.go +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -54,7 +54,7 @@ func BenchmarkOneRouteJSON(B *testing.B) { | 54 | 54 | Status string `json:"status"` | 55 | 55 | }{"ok"} | 56 | 56 | router.GET("/json", func(c *Context) { | 57 | | - c.JSON(200, data) | | 57 | + c.JSON(http.StatusOK, data) | 58 | 58 | }) | 59 | 59 | runRequest(B, router, "GET", "/json") | 60 | 60 | } | @@ -66,7 +66,7 @@ func BenchmarkOneRouteHTML(B *testing.B) { | 66 | 66 | router.SetHTMLTemplate(t) | 67 | 67 |
| 68 | 68 | router.GET("/html", func(c *Context) { | 69 | | - c.HTML(200, "index", "hola") | | 69 | + c.HTML(http.StatusOK, "index", "hola") | 70 | 70 | }) | 71 | 71 | runRequest(B, router, "GET", "/html") | 72 | 72 | } | @@ -82,7 +82,7 @@ func BenchmarkOneRouteSet(B *testing.B) { | 82 | 82 | func BenchmarkOneRouteString(B *testing.B) { | 83 | 83 | router := New() | 84 | 84 | router.GET("/text", func(c *Context) { | 85 | | - c.String(200, "this is a plain text") | | 85 | + c.String(http.StatusOK, "this is a plain text") | 86 | 86 | }) | 87 | 87 | runRequest(B, router, "GET", "/text") | 88 | 88 | } | |
|