vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Simplify release file management
fdd0b3e8373da4c684c73d88f997c3917966ac50 · Keenan Nemetz · 17d ago · parent c5187449
Simplify release file management Drop rename and move from the CLI and browser, outline the files table instead of wrapping it in a card, and label the release-page action Manage files.
server/release_attach_web_test.go +24−49
| @@ -96,18 +96,18 @@ func TestAttachFromTheBrowser(t *testing.T) { | |||
| 96 | 96 | } | |
| 97 | 97 | sess, cookie := f.browserSession(t, f.ownerID) | |
| 98 | 98 | ||
| 99 | // The release page links to the attach page to a maintainer, and to nobody | ||
| 100 | // else; the multipart form itself lives on its own page. | ||
| 99 | // The release page links to the manage-files page to a maintainer, and to | ||
| 100 | // nobody else; the multipart form itself lives on its own page. | ||
| 101 | 101 | _, page := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0", cookie) | |
| 102 | 102 | if strings.Contains(page, `enctype="multipart/form-data"`) { | |
| 103 | 103 | t.Fatalf("release page still embeds the attach form:\n%s", page) | |
| 104 | 104 | } | |
| 105 | if !strings.Contains(page, "/releases/v1.0.0/attach") || !strings.Contains(page, "Attach files") { | ||
| 106 | t.Fatalf("release page has no attach link:\n%s", page) | ||
| 105 | if !strings.Contains(page, "/releases/v1.0.0/attach") || !strings.Contains(page, "Manage files") { | ||
| 106 | t.Fatalf("release page has no manage-files link:\n%s", page) | ||
| 107 | 107 | } | |
| 108 | 108 | resp, page := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0/attach", cookie) | |
| 109 | 109 | if resp.StatusCode != http.StatusOK || !strings.Contains(page, `enctype="multipart/form-data"`) || !strings.Contains(page, "Attach files") { | |
| 110 | t.Fatalf("attach page = %d:\n%s", resp.StatusCode, page) | ||
| 110 | t.Fatalf("manage files page = %d:\n%s", resp.StatusCode, page) | ||
| 111 | 111 | } | |
| 112 | 112 | ||
| 113 | 113 | // A flat file keeps its base name. | |
| @@ -138,7 +138,8 @@ func TestAttachFromTheBrowser(t *testing.T) { | |||
| 138 | 138 | } | |
| 139 | 139 | ||
| 140 | 140 | page = waitForPage(t, f, cookie, "/"+f.repo+"/releases/v1.0.0", "/artifacts/tool") | |
| 141 | for _, want := range []string{"/artifacts/apt/Packages", "Attach files"} { | ||
| 141 | for _, want := range []string{"/artifacts/apt/Packages", "Manage files", `class="release-files"`, | ||
| 142 | `action="/` + f.repo + `/releases/v1.0.0/files/delete"`} { | ||
| 142 | 143 | if !strings.Contains(page, want) { | |
| 143 | 144 | t.Fatalf("release page does not show %q:\n%s", want, page) | |
| 144 | 145 | } | |
| @@ -149,52 +150,32 @@ func TestAttachFromTheBrowser(t *testing.T) { | |||
| 149 | 150 | } | |
| 150 | 151 | } | |
| 151 | 152 | ||
| 152 | func TestMoveAndDeleteFilesFromTheBrowser(t *testing.T) { | ||
| 153 | func TestDeleteFilesFromTheBrowser(t *testing.T) { | ||
| 153 | 154 | t.Parallel() | |
| 154 | 155 | f := releaseFixture(t) | |
| 155 | 156 | attachArtifact(t, f, "v1.0.0", "tool", []byte("the released bytes")) | |
| 156 | 157 | attachArtifact(t, f, "v1.0.0", "apt/Packages", []byte("Package: vole\n")) | |
| 157 | 158 | sess, cookie := f.browserSession(t, f.ownerID) | |
| 158 | 159 | ||
| 159 | // The release page links each attached file to the edit page. | ||
| 160 | // The release page lists each file with a remove action. | ||
| 160 | 161 | _, page := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0", cookie) | |
| 161 | for _, want := range []string{"/files/edit?path=tool", "/files/edit?path=apt%2FPackages"} { | ||
| 162 | for _, want := range []string{"/artifacts/tool", "/artifacts/apt/Packages", | ||
| 163 | `action="/` + f.repo + `/releases/v1.0.0/files/delete"`} { | ||
| 162 | 164 | if !strings.Contains(page, want) { | |
| 163 | t.Fatalf("release page has no edit link %q:\n%s", want, page) | ||
| 165 | t.Fatalf("release page has no remove action %q:\n%s", want, page) | ||
| 164 | 166 | } | |
| 165 | 167 | } | |
| 166 | resp, page := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0/files/edit?path=tool", cookie) | ||
| 167 | if resp.StatusCode != http.StatusOK || !strings.Contains(page, `name="newpath" value="tool"`) { | ||
| 168 | t.Fatalf("file edit page = %d:\n%s", resp.StatusCode, page) | ||
| 169 | } | ||
| 170 | |||
| 171 | // Rename and move are the same write: the path changes, the pointer does not. | ||
| 172 | form := url.Values{"csrf": {sess.CSRF}, "path": {"tool"}, "newpath": {"bin/tool"}} | ||
| 173 | resp, body := f.browserPost(t, "/"+f.repo+"/releases/v1.0.0/files/edit", cookie, form) | ||
| 174 | if resp.StatusCode != http.StatusSeeOther { | ||
| 175 | t.Fatalf("move file = %d:\n%s", resp.StatusCode, body) | ||
| 176 | } | ||
| 177 | m := mustRepo(t, f) | ||
| 178 | arts, err := metadata.ListReleaseArtifacts(m.Git(), "v1.0.0") | ||
| 179 | if err != nil { | ||
| 180 | t.Fatal(err) | ||
| 181 | } | ||
| 182 | if len(arts) != 2 || arts[0].Name != "apt/Packages" || arts[1].Name != "bin/tool" { | ||
| 183 | t.Fatalf("artifacts after move = %+v", arts) | ||
| 184 | } | ||
| 185 | |||
| 186 | // A destination that is already attached is refused, and the tree is untouched. | ||
| 187 | form = url.Values{"csrf": {sess.CSRF}, "path": {"bin/tool"}, "newpath": {"apt/Packages"}} | ||
| 188 | if resp, body := f.browserPost(t, "/"+f.repo+"/releases/v1.0.0/files/edit", cookie, form); resp.StatusCode != http.StatusBadRequest || !strings.Contains(body, "already attached") { | ||
| 189 | t.Fatalf("move onto an existing file = %d:\n%s", resp.StatusCode, body) | ||
| 168 | if strings.Contains(page, "/files/edit") { | ||
| 169 | t.Fatalf("release page still offers a rename/move form:\n%s", page) | ||
| 190 | 170 | } | |
| 191 | 171 | ||
| 192 | 172 | // Delete removes the pointer, not the other file. | |
| 193 | form = url.Values{"csrf": {sess.CSRF}, "path": {"bin/tool"}} | ||
| 194 | resp, body = f.browserPost(t, "/"+f.repo+"/releases/v1.0.0/files/delete", cookie, form) | ||
| 173 | form := url.Values{"csrf": {sess.CSRF}, "path": {"tool"}} | ||
| 174 | resp, body := f.browserPost(t, "/"+f.repo+"/releases/v1.0.0/files/delete", cookie, form) | ||
| 195 | 175 | if resp.StatusCode != http.StatusSeeOther { | |
| 196 | 176 | t.Fatalf("delete file = %d:\n%s", resp.StatusCode, body) | |
| 197 | 177 | } | |
| 178 | m := mustRepo(t, f) | ||
| 198 | 179 | if arts, err := metadata.ListReleaseArtifacts(m.Git(), "v1.0.0"); err != nil || len(arts) != 1 || arts[0].Name != "apt/Packages" { | |
| 199 | 180 | t.Fatalf("artifacts after delete = %+v %v", arts, err) | |
| 200 | 181 | } | |
| @@ -202,10 +183,10 @@ func TestMoveAndDeleteFilesFromTheBrowser(t *testing.T) { | |||
| 202 | 183 | // The file is gone from the page and the download, and a second delete is | |
| 203 | 184 | // refused rather than silently doing nothing. | |
| 204 | 185 | page = waitForPage(t, f, cookie, "/"+f.repo+"/releases/v1.0.0", "apt/Packages") | |
| 205 | if strings.Contains(page, "/artifacts/bin/tool") { | ||
| 186 | if strings.Contains(page, "/artifacts/tool") { | ||
| 206 | 187 | t.Fatalf("release page still names the deleted file:\n%s", page) | |
| 207 | 188 | } | |
| 208 | if resp, _ := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0/artifacts/bin/tool", cookie); resp.StatusCode != http.StatusNotFound { | ||
| 189 | if resp, _ := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0/artifacts/tool", cookie); resp.StatusCode != http.StatusNotFound { | ||
| 209 | 190 | t.Fatalf("deleted download = %d, want 404", resp.StatusCode) | |
| 210 | 191 | } | |
| 211 | 192 | if resp, body := f.browserPost(t, "/"+f.repo+"/releases/v1.0.0/files/delete", cookie, form); resp.StatusCode != http.StatusBadRequest || !strings.Contains(body, "no longer attached") { | |
| @@ -308,27 +289,21 @@ func TestChanneledReleaseIsLockedInTheBrowser(t *testing.T) { | |||
| 308 | 289 | t.Fatalf("release page does not explain the lock:\n%s", page) | |
| 309 | 290 | } | |
| 310 | 291 | for _, unwanted := range []string{"Edit release", `enctype="multipart/form-data"`, | |
| 311 | "/releases/v1.0.0/attach", "/releases/v1.0.0/files/edit"} { | ||
| 292 | "/releases/v1.0.0/attach", "/files/delete"} { | ||
| 312 | 293 | if strings.Contains(page, unwanted) { | |
| 313 | 294 | t.Fatalf("release page still offers %q:\n%s", unwanted, page) | |
| 314 | 295 | } | |
| 315 | 296 | } | |
| 316 | for _, path := range []string{"/releases/v1.0.0/attach", "/releases/v1.0.0/files/edit?path=tool"} { | ||
| 317 | resp, body := f.browserGet(t, "/"+f.repo+path, cookie) | ||
| 318 | if resp.StatusCode != http.StatusConflict || !strings.Contains(body, "Channel stable targets this release") { | ||
| 319 | t.Fatalf("channeled %s = %d:\n%s", path, resp.StatusCode, body) | ||
| 320 | } | ||
| 321 | } | ||
| 322 | move := url.Values{"csrf": {sess.CSRF}, "path": {"tool"}, "newpath": {"bin/tool"}} | ||
| 323 | if resp, body := f.browserPost(t, "/"+f.repo+"/releases/v1.0.0/files/edit", cookie, move); resp.StatusCode != http.StatusConflict || !strings.Contains(body, "Channel stable") { | ||
| 324 | t.Fatalf("moving a file of a channeled release = %d:\n%s", resp.StatusCode, body) | ||
| 297 | resp, body := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0/attach", cookie) | ||
| 298 | if resp.StatusCode != http.StatusConflict || !strings.Contains(body, "Channel stable targets this release") { | ||
| 299 | t.Fatalf("channeled attach page = %d:\n%s", resp.StatusCode, body) | ||
| 325 | 300 | } | |
| 326 | 301 | remove := url.Values{"csrf": {sess.CSRF}, "path": {"tool"}} | |
| 327 | 302 | if resp, body := f.browserPost(t, "/"+f.repo+"/releases/v1.0.0/files/delete", cookie, remove); resp.StatusCode != http.StatusConflict || !strings.Contains(body, "Channel stable") { | |
| 328 | 303 | t.Fatalf("removing a file of a channeled release = %d:\n%s", resp.StatusCode, body) | |
| 329 | 304 | } | |
| 330 | 305 | ||
| 331 | resp, page := f.browserGet(t, "/"+f.repo+"/releases/edit?tag=v1.0.0", cookie) | ||
| 306 | resp, page = f.browserGet(t, "/"+f.repo+"/releases/edit?tag=v1.0.0", cookie) | ||
| 332 | 307 | if resp.StatusCode != http.StatusOK || !strings.Contains(page, "Channel stable targets this release") { | |
| 333 | 308 | t.Fatalf("edit page = %d:\n%s", resp.StatusCode, page) | |
| 334 | 309 | } | |