TestFetchHashHandlesCorruptManifest: a manifest not in ` ` form must not crash fetchHash; it just yields an empty hash.
(t *testing.T)
| 274 | // TestFetchHashHandlesCorruptManifest: a manifest not in `<hash> <name>` |
| 275 | // form must not crash fetchHash; it just yields an empty hash. |
| 276 | func TestFetchHashHandlesCorruptManifest(t *testing.T) { |
| 277 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 278 | _, _ = w.Write([]byte("not a real manifest\nrandom text\n")) |
| 279 | })) |
| 280 | t.Cleanup(srv.Close) |
| 281 | origCS := checksumsURL |
| 282 | checksumsURL = srv.URL + "/codehamr_checksums.txt" |
| 283 | t.Cleanup(func() { checksumsURL = origCS }) |
| 284 | |
| 285 | got, err := fetchHash(context.Background(), "codehamr-linux-amd64") |
| 286 | if err != nil { |
| 287 | t.Fatalf("corrupt manifest should not error, got: %v", err) |
| 288 | } |
| 289 | if got != "" { |
| 290 | t.Fatalf("missing entry should yield empty hash, got %q", got) |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | // TestCheckHonoursEnvDisableFlag: CODEHAMR_NO_UPDATE_CHECK=1 must short-circuit |
| 295 | // Check before any HTTP work, sparing CI/offline launches the fetch deadline. |