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

Function TestApplyRespectsContextCancel

internal/update/update_test.go:491–513  ·  view source on GitHub ↗

TestApplyRespectsContextCancel: a cancelled ctx aborts the download and the local exec stays untouched.

(t *testing.T)

Source from the content-addressed store, hash-verified

489// TestApplyRespectsContextCancel: a cancelled ctx aborts the download and
490// the local exec stays untouched.
491func TestApplyRespectsContextCancel(t *testing.T) {
492 asset := platformAsset(t)
493 body := []byte("matters not\n")
494 r := newFakeRelease(t, asset, body, hashOf(body))
495 withReleaseURLs(t, r.srv.URL)
496
497 tmpDir := t.TempDir()
498 exec := filepath.Join(tmpDir, "codehamr")
499 original := []byte("origcontents\n")
500 if err := os.WriteFile(exec, original, 0o755); err != nil {
501 t.Fatal(err)
502 }
503
504 ctx, cancel := context.WithCancel(context.Background())
505 cancel() // already cancelled
506 if err := Apply(ctx, exec); err == nil {
507 t.Fatal("cancelled ctx must propagate as an Apply error")
508 }
509 got, _ := os.ReadFile(exec)
510 if string(got) != string(original) {
511 t.Fatalf("exec was replaced after cancelled Apply, got %q", got)
512 }
513}

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