(t *testing.T)
| 88 | } |
| 89 | |
| 90 | func TestHasScript(t *testing.T) { |
| 91 | repo := ghrepo.New("OWNER", "REPO") |
| 92 | |
| 93 | t.Run("success", func(t *testing.T) { |
| 94 | client := extensionHTTPClient(t, "repos/OWNER/REPO/contents/REPO", http.StatusOK, `{"type":"file"}`) |
| 95 | |
| 96 | hasScript, err := hasScript(client, repo) |
| 97 | |
| 98 | require.NoError(t, err) |
| 99 | assert.True(t, hasScript) |
| 100 | }) |
| 101 | |
| 102 | // The contents endpoint returns an array when the requested path is a directory, and |
| 103 | // objects with a non-file type for symlinks and submodules. None of these are treated as |
| 104 | // a missing script, so they must not surface a decoding error. |
| 105 | t.Run("success for non-file content", func(t *testing.T) { |
| 106 | for name, body := range map[string]string{ |
| 107 | "directory listing": `[{"type":"file","name":"REPO"}]`, |
| 108 | "directory": `{"type":"dir"}`, |
| 109 | "symlink": `{"type":"symlink"}`, |
| 110 | "submodule": `{"type":"submodule"}`, |
| 111 | } { |
| 112 | t.Run(name, func(t *testing.T) { |
| 113 | client := extensionHTTPClient(t, "repos/OWNER/REPO/contents/REPO", http.StatusOK, body) |
| 114 | |
| 115 | hasScript, err := hasScript(client, repo) |
| 116 | |
| 117 | require.NoError(t, err) |
| 118 | assert.True(t, hasScript) |
| 119 | }) |
| 120 | } |
| 121 | }) |
| 122 | |
| 123 | t.Run("not found", func(t *testing.T) { |
| 124 | client := extensionHTTPClient(t, "repos/OWNER/REPO/contents/REPO", http.StatusNotFound, `{"message":"Not Found"}`) |
| 125 | |
| 126 | hasScript, err := hasScript(client, repo) |
| 127 | |
| 128 | require.NoError(t, err) |
| 129 | assert.False(t, hasScript) |
| 130 | }) |
| 131 | |
| 132 | t.Run("server error", func(t *testing.T) { |
| 133 | client := extensionHTTPClient(t, "repos/OWNER/REPO/contents/REPO", http.StatusInternalServerError, `{"message":"Internal Server Error"}`) |
| 134 | |
| 135 | hasScript, err := hasScript(client, repo) |
| 136 | |
| 137 | assert.False(t, hasScript) |
| 138 | requireExtensionHTTPError(t, err, http.StatusInternalServerError) |
| 139 | }) |
| 140 | } |
| 141 | |
| 142 | func TestFetchLatestRelease(t *testing.T) { |
| 143 | repo := ghrepo.New("OWNER", "REPO") |
nothing calls this directly
no test coverage detected