MCPcopy Create free account
hub / github.com/codehamr/codehamr / TestApplyAcceptsMatchingChecksum

Function TestApplyAcceptsMatchingChecksum

internal/update/update_test.go:185–216  ·  view source on GitHub ↗

TestApplyAcceptsMatchingChecksum: positive case, a download whose hash equals the manifest entry promotes the binary into place.

(t *testing.T)

Source from the content-addressed store, hash-verified

183// TestApplyAcceptsMatchingChecksum: positive case, a download whose hash
184// equals the manifest entry promotes the binary into place.
185func TestApplyAcceptsMatchingChecksum(t *testing.T) {
186 asset := platformAsset(t)
187 body := []byte("legit binary content\n")
188 r := newFakeRelease(t, asset, body, hashOf(body))
189 withReleaseURLs(t, r.srv.URL)
190
191 tmpDir := t.TempDir()
192 exec := filepath.Join(tmpDir, "codehamr")
193 if err := os.WriteFile(exec, []byte("old\n"), 0o755); err != nil {
194 t.Fatal(err)
195 }
196
197 if err := Apply(context.Background(), exec); err != nil {
198 t.Fatalf("Apply on matching checksum should succeed: %v", err)
199 }
200 got, err := os.ReadFile(exec)
201 if err != nil {
202 t.Fatal(err)
203 }
204 if string(got) != string(body) {
205 t.Fatalf("exec not replaced with downloaded body: got %q", got)
206 }
207 st, _ := os.Stat(exec)
208 if st.Mode()&0o100 == 0 {
209 t.Fatalf("exec should be executable, got mode %v", st.Mode())
210 }
211 // Temp file must be cleaned up.
212 matches, _ := filepath.Glob(filepath.Join(tmpDir, ".codehamr-update-*"))
213 if len(matches) != 0 {
214 t.Fatalf("temp file leaked after successful Apply: %+v", matches)
215 }
216}
217
218// TestApplyRejectsMissingManifestEntry: a manifest that exists but doesn't
219// list our asset (a bad release) must make Apply abort, not skip verification

Callers

nothing calls this directly

Calls 5

platformAssetFunction · 0.85
newFakeReleaseFunction · 0.85
hashOfFunction · 0.85
withReleaseURLsFunction · 0.85
ApplyFunction · 0.85

Tested by

no test coverage detected