From 853637bbfa9301e823b04282b6ccc6f900f86d24 Mon Sep 17 00:00:00 2001 From: Diego Morales Date: Fri, 27 May 2022 19:31:08 -0300 Subject: [PATCH] Added test case for name taken response on add --- repositories_test.go | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/repositories_test.go b/repositories_test.go index d20d4bf..3b1b34e 100644 --- a/repositories_test.go +++ b/repositories_test.go @@ -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", + }, }, } @@ -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