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

Function Test_Download

pkg/cmd/run/download/http_test.go:61–109  ·  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 repo: ghrepo.New("OWNER", "REPO"),
76 }
77 require.NoError(t, api.Download(safeurl.NewImmutableSafeURL("https://api.github.com/repos/OWNER/REPO/actions/artifacts/12345/zip"), destDir))
78
79 var paths []string
80 parentPrefix := tmpDir + string(filepath.Separator)
81 err = filepath.Walk(tmpDir, func(p string, info os.FileInfo, err error) error {
82 if err != nil {
83 return err
84 }
85 if p == tmpDir {
86 return nil
87 }
88 entry := strings.TrimPrefix(p, parentPrefix)
89 if info.IsDir() {
90 entry += "/"
91 } else if info.Mode()&0111 != 0 {
92 entry += "(X)"
93 }
94 paths = append(paths, entry)
95 return nil
96 })
97 require.NoError(t, err)
98
99 sort.Strings(paths)
100 assert.Equal(t, []string{
101 "artifact/",
102 filepath.Join("artifact", "bin") + "/",
103 filepath.Join("artifact", "bin", "myexe"),
104 filepath.Join("artifact", "readme.md"),
105 filepath.Join("artifact", "src") + "/",
106 filepath.Join("artifact", "src", "main.go"),
107 filepath.Join("artifact", "src", "util.go"),
108 }, paths)
109}

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected