MCPcopy Index your code
hub / github.com/codehamr/codehamr / TestApplyCleansTempOnFailure

Function TestApplyCleansTempOnFailure

internal/update/update_test.go:247–272  ·  view source on GitHub ↗

TestApplyCleansTempOnFailure: a failed download (server returns 500) must not leave a half-written temp file in the install directory.

(t *testing.T)

Source from the content-addressed store, hash-verified

245// TestApplyCleansTempOnFailure: a failed download (server returns 500)
246// must not leave a half-written temp file in the install directory.
247func TestApplyCleansTempOnFailure(t *testing.T) {
248 asset := platformAsset(t)
249 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
250 switch {
251 case strings.HasSuffix(req.URL.Path, "checksums.txt"):
252 _, _ = w.Write([]byte(hashOf([]byte{}) + " " + asset + "\n"))
253 default:
254 http.Error(w, "boom", http.StatusInternalServerError)
255 }
256 }))
257 t.Cleanup(srv.Close)
258 withReleaseURLs(t, srv.URL)
259
260 tmpDir := t.TempDir()
261 exec := filepath.Join(tmpDir, "codehamr")
262 if err := os.WriteFile(exec, []byte("o\n"), 0o755); err != nil {
263 t.Fatal(err)
264 }
265 if err := Apply(context.Background(), exec); err == nil {
266 t.Fatal("Apply must error on download failure")
267 }
268 matches, _ := filepath.Glob(filepath.Join(tmpDir, ".codehamr-update-*"))
269 if len(matches) != 0 {
270 t.Fatalf("temp file leaked after failed Apply: %+v", matches)
271 }
272}
273
274// TestFetchHashHandlesCorruptManifest: a manifest not in `<hash> <name>`
275// form must not crash fetchHash; it just yields an empty hash.

Callers

nothing calls this directly

Calls 6

platformAssetFunction · 0.85
hashOfFunction · 0.85
withReleaseURLsFunction · 0.85
ApplyFunction · 0.85
WriteMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected