Created
April 24, 2016 22:18
-
-
Save kpurdon/ead53e2fdec60d9766ba9c9da753b5fa to your computer and use it in GitHub Desktop.
Revisions
-
kpurdon revised this gist
Apr 24, 2016 . 1 changed file with 1 addition and 1 deletion.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 @@ -28,7 +28,7 @@ func TestGet(t *testing.T) { expectedRepos: []Repo(nil), expectedError: errors.New("github api: no results found"), }, // not all cases are tested, but this is enough of a sample } for _, tc := range tests { -
kpurdon created this gist
Apr 24, 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,44 @@ var c = ReposClient{} func TestGet(t *testing.T) { assert := assert.New(t) httpmock.Activate() defer httpmock.DeactivateAndReset() tests := []struct { description string responder httpmock.Responder expectedRepos []Repo expectedError error }{ { description: "github api success", responder: httpmock.NewStringResponder(200, `[{"name": "test", "description": "a test"}]`), expectedRepos: []Repo{Repo{Name: "test", Description: "a test"}}, expectedError: nil, }, { description: "github api success, no repos", responder: httpmock.NewStringResponder(200, `[]`), expectedRepos: []Repo{}, expectedError: nil, }, { description: "github api failure, not found", responder: httpmock.NewStringResponder(404, `{"message": "not found"}`), expectedRepos: []Repo(nil), expectedError: errors.New("github api: no results found"), }, // TODO: not all cases are tested, but this is enough of a sample } for _, tc := range tests { httpmock.RegisterResponder("GET", "https://api.github.com/users/fake/repos", tc.responder) r, err := c.Get("fake") assert.Equal(r, tc.expectedRepos, tc.description) assert.Equal(err, tc.expectedError, tc.description) httpmock.Reset() } }