Last active
June 13, 2016 02:03
-
-
Save kpurdon/403eb0483ba8e41fbbf6cca6a45f3ec0 to your computer and use it in GitHub Desktop.
Revisions
-
kpurdon revised this gist
Jun 13, 2016 . 1 changed file with 1 addition and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,12 +27,7 @@ func TestAuth(t *testing.T) { url: "/ping?user=test&password=badpassword", expectedBody: "NOT_AUTHORIZED\n", expectedCode: 403, }, } ts := httptest.NewServer(Auth(GetTestHandler())) -
kpurdon created this gist
May 15, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ func TestAuth(t *testing.T) { assert := assert.New(t) tests := []struct { description string url string expectedBody string expectedCode int }{ { description: "missing arg user", url: "/ping", expectedBody: "MISSING_ARG_USER\n", expectedCode: 400, }, { description: "bad user", url: "/ping?user=baduser", expectedBody: "NOT_AUTHORIZED\n", expectedCode: 403, }, { description: "missing arg password", url: "/ping?user=test", expectedBody: "MISSING_ARG_PASSWORD\n", expectedCode: 400, }, { description: "bad password", url: "/ping?user=test&password=badpassword", expectedBody: "NOT_AUTHORIZED\n", expectedCode: 403, }, // { // description: "success", // url: "/ping?user=test&password=abc123", // expectedBody: "OK\n", // expectedCode: 200, // }, } ts := httptest.NewServer(Auth(GetTestHandler())) defer ts.Close() for _, tc := range tests { var u bytes.Buffer u.WriteString(string(ts.URL)) u.WriteString(tc.url) res, err := http.Get(u.String()) assert.NoError(err) if res != nil { defer res.Body.Close() } b, err := ioutil.ReadAll(res.Body) assert.NoError(err) assert.Equal(tc.expectedCode, res.StatusCode, tc.description) assert.Equal(tc.expectedBody, string(b), tc.description) } }