MCPcopy Create free account
hub / github.com/compozy/agh / TestClientDownloadSingleTarballAsset

Function TestClientDownloadSingleTarballAsset

internal/registry/github/client_test.go:98–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

96}
97
98func TestClientDownloadSingleTarballAsset(t *testing.T) {
99 t.Parallel()
100
101 archive := mustTarGz(t, map[string]string{"demo/extension.toml": "name = \"demo\"\nversion = \"1.2.3\"\n"})
102 server := newGitHubServer(t, func(writer http.ResponseWriter, request *http.Request) {
103 switch request.URL.Path {
104 case "/repos/acme/demo/releases/latest":
105 writeJSON(writer, `{
106 "tag_name":"v1.2.3",
107 "draft":false,
108 "prerelease":false,
109 "tarball_url":"`+serverURLPlaceholder+`/downloads/source.tar.gz",
110 "assets":[{"name":"demo-v1.2.3.tar.gz","url":"`+serverURLPlaceholder+`/downloads/asset.tar.gz","browser_download_url":"`+serverURLPlaceholder+`/downloads/asset-browser.tar.gz","content_type":"application/gzip","size":123}]
111 }`)
112 case "/downloads/asset.tar.gz":
113 writer.Header().Set("Content-Type", "application/gzip")
114 _, _ = writer.Write(archive)
115 default:
116 http.NotFound(writer, request)
117 }
118 })
119 defer server.Close()
120
121 client := NewClient(server.URL)
122 result, err := client.Download(context.Background(), "acme/demo", registry.DownloadOpts{})
123 if err != nil {
124 t.Fatalf("Download() error = %v", err)
125 }
126 t.Cleanup(func() {
127 if err := result.Reader.Close(); err != nil {
128 t.Errorf("result.Reader.Close() error = %v", err)
129 }
130 })
131
132 if result.Version != "v1.2.3" || result.ContentType != "application/gzip" {
133 t.Fatalf("Download() result = %#v", result)
134 }
135 files := readTarGz(t, result.Reader)
136 if files["demo/extension.toml"] == "" {
137 t.Fatalf("downloaded files = %#v, want extension.toml", files)
138 }
139}
140
141func TestClientDownloadMultipleAssetsRequiresSelection(t *testing.T) {
142 t.Parallel()

Callers

nothing calls this directly

Calls 10

DownloadMethod · 0.95
newGitHubServerFunction · 0.85
CleanupMethod · 0.80
mustTarGzFunction · 0.70
writeJSONFunction · 0.70
NewClientFunction · 0.70
readTarGzFunction · 0.70
WriteMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected