TestApplyRespectsContextCancel: a cancelled ctx aborts the download and the local exec stays untouched.
(t *testing.T)
| 489 | // TestApplyRespectsContextCancel: a cancelled ctx aborts the download and |
| 490 | // the local exec stays untouched. |
| 491 | func 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 | } |
nothing calls this directly
no test coverage detected