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

Function Test_Download

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

Source from the content-addressed store, hash-verified

59}
60
61func Test_Download(t *testing.T) {
62 tmpDir := t.TempDir()
63 destDir, err := safepaths.ParseAbsolute(filepath.Join(tmpDir, "artifact"))
64 require.NoError(t, err)
65
66 reg := &httpmock.Registry{}
67 defer reg.Verify(t)
68
69 reg.Register(
70 httpmock.REST("GET", "repos/OWNER/REPO/actions/artifacts/12345/zip"),
71 httpmock.FileResponse("./fixtures/myproject.zip"))
72
73 api := &apiPlatform{
74 client: &http.Client{Transport: reg},
75 }
76 require.NoError(t, api.Download(safeurl.NewImmutableSafeURL("https://api.github.com/repos/OWNER/REPO/actions/artifacts/12345/zip"), destDir))
77
78 var paths []string
79 parentPrefix := tmpDir + string(filepath.Separator)
80 err = filepath.Walk(tmpDir, func(p string, info os.FileInfo, err error) error {
81 if err != nil {
82 return err
83 }
84 if p == tmpDir {
85 return nil
86 }
87 entry := strings.TrimPrefix(p, parentPrefix)
88 if info.IsDir() {
89 entry += "/"
90 } else if info.Mode()&0111 != 0 {
91 entry += "(X)"
92 }
93 paths = append(paths, entry)
94 return nil
95 })
96 require.NoError(t, err)
97
98 sort.Strings(paths)
99 assert.Equal(t, []string{
100 "artifact/",
101 filepath.Join("artifact", "bin") + "/",
102 filepath.Join("artifact", "bin", "myexe"),
103 filepath.Join("artifact", "readme.md"),
104 filepath.Join("artifact", "src") + "/",
105 filepath.Join("artifact", "src", "main.go"),
106 filepath.Join("artifact", "src", "util.go"),
107 }, paths)
108}

Callers

nothing calls this directly

Calls 9

VerifyMethod · 0.95
RegisterMethod · 0.95
DownloadMethod · 0.95
ParseAbsoluteFunction · 0.92
RESTFunction · 0.92
FileResponseFunction · 0.92
NewImmutableSafeURLFunction · 0.92
JoinMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected