MCPcopy
hub / github.com/cli/cli / Test_Download

Function Test_Download

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected