(t *testing.T)
| 138 | } |
| 139 | |
| 140 | func 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. |
| 183 | type roundTripFunc func(*http.Request) *http.Response |
nothing calls this directly
no test coverage detected