MCPcopy Create free account
hub / github.com/cli/cli / Test_Download

Function Test_Download

pkg/cmd/run/download/http_test.go:63–158  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func 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 }

Callers

nothing calls this directly

Calls 15

VerifyMethod · 0.95
RegisterMethod · 0.95
DownloadMethod · 0.95
RESTFunction · 0.92
BinaryResponseFunction · 0.92
NewFunction · 0.92
NewImmutableSafeURLFunction · 0.92
OpenRootFunction · 0.92
testArtifactZipFunction · 0.85
IsDirMethod · 0.80
ModeMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected