MCPcopy Create free account
hub / github.com/docker/docker-agent / TestInstall_RawFormat

Function TestInstall_RawFormat

pkg/toolinstall/installer_test.go:140–180  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

138}
139
140func TestInstall_RawFormat(t *testing.T) {
141 t.Setenv("DOCKER_AGENT_TOOLS_DIR", t.TempDir())
142
143 binaryContent := "#!/bin/sh\necho hello"
144
145 pkg := &Package{
146 RepoOwner: "test",
147 RepoName: "raw-tool",
148 Format: "raw",
149 Asset: "raw-tool",
150 Files: []PackageFile{{Name: "raw-tool"}},
151 }
152
153 registry := &Registry{
154 httpClient: &http.Client{
155 Transport: roundTripFunc(func(_ *http.Request) *http.Response {
156 return &http.Response{
157 StatusCode: http.StatusOK,
158 Body: io.NopCloser(strings.NewReader(binaryContent)),
159 }
160 }),
161 },
162 }
163
164 result, err := registry.Install(t.Context(), pkg, "v1.0.0")
165 require.NoError(t, err)
166
167 data, err := os.ReadFile(result)
168 require.NoError(t, err)
169 assert.Equal(t, binaryContent, string(data))
170
171 info, err := os.Stat(result)
172 require.NoError(t, err)
173 assert.NotZero(t, info.Mode()&0o111, "binary should be executable")
174
175 // Verify symlink was created.
176 link := filepath.Join(BinDir(), "raw-tool")
177 target, err := os.Readlink(link)
178 require.NoError(t, err)
179 assert.Equal(t, result, target)
180}
181
182// roundTripFunc adapts a function to http.RoundTripper for test HTTP mocking.
183type roundTripFunc func(*http.Request) *http.Response

Callers

nothing calls this directly

Calls 5

InstallMethod · 0.95
BinDirFunction · 0.85
ContextMethod · 0.80
ReadFileMethod · 0.80
roundTripFuncFuncType · 0.70

Tested by

no test coverage detected