(t *testing.T)
| 61 | } |
| 62 | |
| 63 | func Test_Download(t *testing.T) { |
| 64 | tests := []struct { |
| 65 | name string |
| 66 | setup func(t *testing.T, destDir, outside string) |
| 67 | wantErr string |
| 68 | verify func(t *testing.T, tmpDir, outside string) |
| 69 | }{ |
| 70 | { |
| 71 | name: "extracts artifact", |
| 72 | verify: func(t *testing.T, tmpDir, _ string) { |
| 73 | t.Helper() |
| 74 | var paths []string |
| 75 | parentPrefix := tmpDir + string(filepath.Separator) |
| 76 | err := filepath.Walk(tmpDir, func(p string, info os.FileInfo, err error) error { |
| 77 | if err != nil { |
| 78 | return err |
| 79 | } |
| 80 | if p == tmpDir { |
| 81 | return nil |
| 82 | } |
| 83 | entry := strings.TrimPrefix(p, parentPrefix) |
| 84 | if info.IsDir() { |
| 85 | entry += "/" |
| 86 | } else if info.Mode()&0o111 != 0 { |
| 87 | entry += "(X)" |
| 88 | } |
| 89 | paths = append(paths, entry) |
| 90 | return nil |
| 91 | }) |
| 92 | require.NoError(t, err) |
| 93 | |
| 94 | sort.Strings(paths) |
| 95 | assert.Equal(t, []string{ |
| 96 | "artifact/", |
| 97 | filepath.Join("artifact", "bin") + "/", |
| 98 | filepath.Join("artifact", "bin", "myexe"), |
| 99 | filepath.Join("artifact", "empty") + "/", |
| 100 | filepath.Join("artifact", "readme.md"), |
| 101 | filepath.Join("artifact", "src") + "/", |
| 102 | filepath.Join("artifact", "src", "main.go"), |
| 103 | filepath.Join("artifact", "src", "util.go"), |
| 104 | }, paths) |
| 105 | }, |
| 106 | }, |
| 107 | { |
| 108 | name: "rejects artifact ancestor symlink", |
| 109 | setup: func(t *testing.T, destDir, outside string) { |
| 110 | t.Helper() |
| 111 | require.NoError(t, os.Symlink(outside, filepath.Join(destDir, "src"))) |
| 112 | }, |
| 113 | wantErr: "symbolic link", |
| 114 | verify: func(t *testing.T, _, outside string) { |
| 115 | t.Helper() |
| 116 | assert.NoFileExists(t, filepath.Join(outside, "main.go")) |
| 117 | assert.NoFileExists(t, filepath.Join(outside, "util.go")) |
| 118 | }, |
| 119 | }, |
| 120 | } |
nothing calls this directly
no test coverage detected