Skip to content

Commit

Permalink
Added test case for name taken response on add
Browse files Browse the repository at this point in the history
  • Loading branch information
dgmorales committed May 27, 2022
1 parent 252c68b commit 853637b
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ func TestRepositoryServiceGet(t *testing.T) {
name: "unexpected",
code: http.StatusUseProxy,
repo: nil,
err: ErrUnexpectedStatusCode,
err: ErrUnexpectedStatusCode{
StatusCode: http.StatusUseProxy,
ErrorBody: "null",
},
},
}

Expand Down Expand Up @@ -128,6 +131,36 @@ func TestRepositoryServiceAdd(t *testing.T) {
assert.Equal(t, repositoryConfig, result)
}

func TestRepositoryServiceAddDuplicateError(t *testing.T) {
repositoryConfig := &RepositoryConfig{
Service: "github",
Name: "user/fake-duplicate-repo",
}
fakeUrl := "https://coveralls.io/api/repos"
httpmock.RegisterResponder("POST", fakeUrl, func(req *http.Request) (*http.Response, error) {
errorNameTaken := map[string]map[string]string{
"errors": {
"name": "has already been taken",
},
}

resp, err := httpmock.NewJsonResponse(422, errorNameTaken)
if err != nil {
return httpmock.NewStringResponse(500, ""), nil
}
return resp, nil
})

client := NewClient("fake token")
httpmock.ActivateNonDefault(client.client.GetClient())
defer httpmock.DeactivateAndReset()

result, err := client.Repositories.Add(context.Background(), repositoryConfig)

assert.Equal(t, err, ErrNameIsTaken)
assert.Nil(t, result)
}

func TestRepositoryConfigMarshall(t *testing.T) {
var testCases = []struct {
name string
Expand Down

0 comments on commit 853637b

Please sign in to comment.