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