(t *testing.T)
| 39 | } |
| 40 | |
| 41 | func TestRepoExists(t *testing.T) { |
| 42 | repo := ghrepo.New("OWNER", "REPO") |
| 43 | |
| 44 | for name, body := range map[string]string{ |
| 45 | "JSON body": `{}`, |
| 46 | "empty body": "", |
| 47 | "non-JSON body": "repository", |
| 48 | } { |
| 49 | t.Run("success with "+name, func(t *testing.T) { |
| 50 | client := extensionHTTPClient(t, "repos/OWNER/REPO", http.StatusOK, body) |
| 51 | |
| 52 | exists, err := repoExists(client, repo) |
| 53 | |
| 54 | require.NoError(t, err) |
| 55 | assert.True(t, exists) |
| 56 | }) |
| 57 | } |
| 58 | |
| 59 | t.Run("not found", func(t *testing.T) { |
| 60 | client := extensionHTTPClient(t, "repos/OWNER/REPO", http.StatusNotFound, `{"message":"Not Found"}`) |
| 61 | |
| 62 | exists, err := repoExists(client, repo) |
| 63 | |
| 64 | require.NoError(t, err) |
| 65 | assert.False(t, exists) |
| 66 | }) |
| 67 | |
| 68 | t.Run("server error", func(t *testing.T) { |
| 69 | client := extensionHTTPClient(t, "repos/OWNER/REPO", http.StatusInternalServerError, `{"message":"Internal Server Error"}`) |
| 70 | |
| 71 | exists, err := repoExists(client, repo) |
| 72 | |
| 73 | assert.False(t, exists) |
| 74 | requireExtensionHTTPError(t, err, http.StatusInternalServerError) |
| 75 | }) |
| 76 | |
| 77 | for _, status := range []int{http.StatusCreated, http.StatusNoContent} { |
| 78 | t.Run("unexpected "+http.StatusText(status), func(t *testing.T) { |
| 79 | client := extensionHTTPClient(t, "repos/OWNER/REPO", status, `{"message":"Unexpected status"}`) |
| 80 | |
| 81 | exists, err := repoExists(client, repo) |
| 82 | |
| 83 | assert.False(t, exists) |
| 84 | require.Error(t, err) |
| 85 | assert.Contains(t, err.Error(), fmt.Sprintf("unexpected HTTP %d", status)) |
| 86 | }) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | func TestHasScript(t *testing.T) { |
| 91 | repo := ghrepo.New("OWNER", "REPO") |
nothing calls this directly
no test coverage detected