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