vole
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software:2222/vole.git
A free and open-source forge that lives in your Git repo.
| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func siteWithFiles(t *testing.T, files map[string]string) string { |
| 11 | t.Helper() |
| 12 | root := t.TempDir() |
| 13 | for name, content := range files { |
| 14 | p := filepath.Join(root, filepath.FromSlash(name)) |
| 15 | if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | if err := os.WriteFile(p, []byte(content), 0o644); err != nil { |
| 19 | t.Fatal(err) |
| 20 | } |
| 21 | } |
| 22 | return root |
| 23 | } |
| 24 | |
| 25 | // TestCollectArtifactFiles covers the expansion a job's declaration goes through in |
| 26 | // the checkout: one segment at a time, .git excluded, and a pattern that matches |
| 27 | // nothing is an error rather than an empty artifact list. |
| 28 | func TestCollectArtifactFiles(t *testing.T) { |
| 29 | root := siteWithFiles(t, map[string]string{ |
| 30 | "dist/tool-linux": "binary\n", |
| 31 | "dist/NOTES.txt": "notes\n", |
| 32 | "dist/sub/deep.md": "deep\n", |
| 33 | "other/tool-linux": "a different binary\n", |
| 34 | ".git/config": "[core]\n", |
| 35 | }) |
| 36 | |
| 37 | files, err := collectArtifactFiles(root, []string{"dist/*"}) |
| 38 | if err != nil { |
| 39 | t.Fatalf("dist/*: %v", err) |
| 40 | } |
| 41 | // One segment: dist/sub is a directory, so it is not published as a file. |
| 42 | if len(files) != 2 || files[0].Name != "NOTES.txt" || files[1].Name != "tool-linux" { |
| 43 | t.Fatalf("dist/* matched %+v", files) |
| 44 | } |
| 45 | if files[1].Path != "dist/tool-linux" { |
| 46 | t.Fatalf("path = %q, want dist/tool-linux", files[1].Path) |
| 47 | } |
| 48 | |
| 49 | // A pattern that matches nothing is the failure a declaration exists to catch. |
| 50 | if _, err := collectArtifactFiles(root, []string{"build/*"}); err == nil { |
| 51 | t.Fatal("a pattern matching nothing was accepted") |
| 52 | } else if !strings.Contains(err.Error(), "build/*") { |
| 53 | t.Fatalf("the error does not name the pattern: %v", err) |
| 54 | } |
| 55 | |
| 56 | // The checkout's own repository is not an output. |
| 57 | if _, err := collectArtifactFiles(root, []string{".git/*"}); err == nil { |
| 58 | t.Fatal(".git was treated as an artifact directory") |
| 59 | } |
| 60 | |
| 61 | // Two files with one base name would collide as downloads; say so instead of |
| 62 | // publishing whichever the walk reached first. |
| 63 | if _, err := collectArtifactFiles(root, []string{"dist/tool-linux", "other/tool-linux"}); err == nil { |
| 64 | t.Fatal("two files were published under one name") |
| 65 | } else if !strings.Contains(err.Error(), "tool-linux") { |
| 66 | t.Fatalf("the error does not name the collision: %v", err) |
| 67 | } |
| 68 | } |
| 69 |