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.
Manage release files from the CLI and browser
c51874492382d08085b6388cea898d0d60ab9375 · Keenan Nemetz · 17d ago · parent 214e7ea6
Manage release files from the CLI and browser Move the attach form to its own page, add move/remove operations to the CLI and browser, and simplify the release detail page to notes, files, and source links.
metadata/releases_test.go +111
| @@ -171,6 +171,117 @@ func TestWriteReleasePointersValidates(t *testing.T) { | |||
| 171 | 171 | } | |
| 172 | 172 | } | |
| 173 | 173 | ||
| 174 | func TestMoveReleasePointer(t *testing.T) { | ||
| 175 | t.Parallel() | ||
| 176 | g := writeRepo(t) | ||
| 177 | putReleasePointer(t, g, "releases/v1/tool", 10) | ||
| 178 | putReleasePointer(t, g, "releases/v1/apt/Packages", 20) | ||
| 179 | |||
| 180 | if err := MoveReleasePointer(g, Ref, "v1", "tool", "bin/tool", "move", "keenan"); err != nil { | ||
| 181 | t.Fatal(err) | ||
| 182 | } | ||
| 183 | list, err := ListReleaseArtifacts(g, "v1") | ||
| 184 | if err != nil { | ||
| 185 | t.Fatal(err) | ||
| 186 | } | ||
| 187 | if len(list) != 2 || list[0].Name != "apt/Packages" || list[1].Name != "bin/tool" { | ||
| 188 | t.Fatalf("artifacts after move = %+v", list) | ||
| 189 | } | ||
| 190 | if list[1].OID != testOID || list[1].Size != 10 { | ||
| 191 | t.Fatalf("the pointer changed during the move: %+v", list[1]) | ||
| 192 | } | ||
| 193 | if _, err := ListReleaseArtifacts(g, "missing"); err != nil { | ||
| 194 | t.Fatal(err) | ||
| 195 | } | ||
| 196 | } | ||
| 197 | |||
| 198 | func TestMoveReleasePointerRefuses(t *testing.T) { | ||
| 199 | t.Parallel() | ||
| 200 | g := writeRepo(t) | ||
| 201 | putReleasePointer(t, g, "releases/v1/tool", 10) | ||
| 202 | putReleasePointer(t, g, "releases/v1/other", 20) | ||
| 203 | putReleasePointer(t, g, "releases/v1/apt/Packages", 30) | ||
| 204 | |||
| 205 | for _, tc := range []struct { | ||
| 206 | name string | ||
| 207 | from, to string | ||
| 208 | want string | ||
| 209 | }{ | ||
| 210 | {"missing source", "absent", "bin/absent", "not an attached file"}, | ||
| 211 | {"existing target", "tool", "other", "already attached"}, | ||
| 212 | {"target is a directory", "tool", "apt", "directory on this release"}, | ||
| 213 | {"target under a file", "tool", "other/bin", "is a file on this release"}, | ||
| 214 | {"same path", "tool", "tool", "already the path"}, | ||
| 215 | {"invalid target", "tool", "../escape", "must not contain"}, | ||
| 216 | } { | ||
| 217 | if err := MoveReleasePointer(g, Ref, "v1", tc.from, tc.to, "move", "keenan"); err == nil || !strings.Contains(err.Error(), tc.want) { | ||
| 218 | t.Errorf("%s: MoveReleasePointer = %v, want it to mention %q", tc.name, err, tc.want) | ||
| 219 | } | ||
| 220 | } | ||
| 221 | |||
| 222 | // A refusal changes nothing. | ||
| 223 | list, err := ListReleaseArtifacts(g, "v1") | ||
| 224 | if err != nil { | ||
| 225 | t.Fatal(err) | ||
| 226 | } | ||
| 227 | if len(list) != 3 { | ||
| 228 | t.Fatalf("a refused move changed the tree: %+v", list) | ||
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 232 | func TestRemoveReleasePointers(t *testing.T) { | ||
| 233 | t.Parallel() | ||
| 234 | g := writeRepo(t) | ||
| 235 | putReleasePointer(t, g, "releases/v1/tool", 10) | ||
| 236 | putReleasePointer(t, g, "releases/v1/apt/Packages", 20) | ||
| 237 | putReleaseBlob(t, g, "releases/v1/apt/README", []byte("a note, not an artifact\n")) | ||
| 238 | |||
| 239 | if err := RemoveReleasePointers(g, Ref, "v1", []string{"tool", "apt/Packages", "tool"}, "remove", "keenan"); err != nil { | ||
| 240 | t.Fatal(err) | ||
| 241 | } | ||
| 242 | list, err := ListReleaseArtifacts(g, "v1") | ||
| 243 | if err != nil { | ||
| 244 | t.Fatal(err) | ||
| 245 | } | ||
| 246 | if len(list) != 0 { | ||
| 247 | t.Fatalf("artifacts after removal = %+v", list) | ||
| 248 | } | ||
| 249 | if _, err := g.BlobAt(Ref, "releases/v1/apt/README"); err != nil { | ||
| 250 | t.Fatalf("removing artifacts also removed a hand-written note: %v", err) | ||
| 251 | } | ||
| 252 | } | ||
| 253 | |||
| 254 | func TestRemoveReleasePointersRefuses(t *testing.T) { | ||
| 255 | t.Parallel() | ||
| 256 | g := writeRepo(t) | ||
| 257 | putReleasePointer(t, g, "releases/v1/tool", 10) | ||
| 258 | putReleaseBlob(t, g, "releases/v1/README", []byte("not a pointer\n")) | ||
| 259 | |||
| 260 | for _, tc := range []struct { | ||
| 261 | name string | ||
| 262 | path string | ||
| 263 | want string | ||
| 264 | }{ | ||
| 265 | {"missing", "absent", "not an attached file"}, | ||
| 266 | {"not a pointer", "README", "not an attached file"}, | ||
| 267 | {"invalid", "../escape", "must not contain"}, | ||
| 268 | } { | ||
| 269 | if err := RemoveReleasePointers(g, Ref, "v1", []string{tc.path}, "remove", "keenan"); err == nil || !strings.Contains(err.Error(), tc.want) { | ||
| 270 | t.Errorf("%s: RemoveReleasePointers = %v, want it to mention %q", tc.name, err, tc.want) | ||
| 271 | } | ||
| 272 | } | ||
| 273 | if err := RemoveReleasePointers(g, Ref, "v1", nil, "remove", "keenan"); err == nil { | ||
| 274 | t.Fatal("an empty removal was accepted") | ||
| 275 | } | ||
| 276 | list, err := ListReleaseArtifacts(g, "v1") | ||
| 277 | if err != nil { | ||
| 278 | t.Fatal(err) | ||
| 279 | } | ||
| 280 | if len(list) != 1 || list[0].Name != "tool" { | ||
| 281 | t.Fatalf("a refused removal changed the tree: %+v", list) | ||
| 282 | } | ||
| 283 | } | ||
| 284 | |||
| 174 | 285 | func TestLoadArtifactsAtIgnoresMalformedPaths(t *testing.T) { | |
| 175 | 286 | t.Parallel() | |
| 176 | 287 | g := writeRepo(t) | |