MCPcopy Create free account
hub / github.com/cli/cli / TestFetchExpectedChecksum

Function TestFetchExpectedChecksum

pkg/cmd/copilot/copilot_test.go:448–502  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

446}
447
448func TestFetchExpectedChecksum(t *testing.T) {
449 t.Run("parses checksums file correctly", func(t *testing.T) {
450 reg := &httpmock.Registry{}
451 checksums := "abc123def456 copilot-linux-x64.tar.gz\n789xyz copilot-darwin-arm64.tar.gz\n"
452 reg.Register(
453 httpmock.MatchAny,
454 httpmock.StringResponse(checksums),
455 )
456
457 client := &http.Client{Transport: reg}
458 checksum, err := fetchExpectedChecksum(client, safeurl.NewImmutableSafeURL("https://example.com/checksums"), "copilot-linux-x64.tar.gz")
459 require.NoError(t, err, "unexpected error")
460 require.Equal(t, "abc123def456", checksum, "checksum mismatch")
461 })
462
463 t.Run("returns error for missing archive", func(t *testing.T) {
464 reg := &httpmock.Registry{}
465 checksums := "abc123 copilot-linux-x64.tar.gz\n"
466 reg.Register(
467 httpmock.MatchAny,
468 httpmock.StringResponse(checksums),
469 )
470
471 client := &http.Client{Transport: reg}
472 _, err := fetchExpectedChecksum(client, safeurl.NewImmutableSafeURL("https://example.com/checksums"), "copilot-win32-x64.zip")
473 require.Error(t, err, "expected error for missing archive")
474 require.Equal(t, "checksum not found for copilot-win32-x64.zip", err.Error(), "unexpected error")
475 })
476
477 t.Run("handles single space separator", func(t *testing.T) {
478 reg := &httpmock.Registry{}
479 checksums := "abc123 copilot-darwin-x64.tar.gz\n"
480 reg.Register(
481 httpmock.MatchAny,
482 httpmock.StringResponse(checksums),
483 )
484
485 client := &http.Client{Transport: reg}
486 checksum, err := fetchExpectedChecksum(client, safeurl.NewImmutableSafeURL("https://example.com/checksums"), "copilot-darwin-x64.tar.gz")
487 require.NoError(t, err, "unexpected error")
488 require.Equal(t, "abc123", checksum, "checksum mismatch")
489 })
490
491 t.Run("handles HTTP error", func(t *testing.T) {
492 reg := &httpmock.Registry{}
493 reg.Register(
494 httpmock.MatchAny,
495 httpmock.StatusStringResponse(http.StatusNotFound, "not found"),
496 )
497
498 client := &http.Client{Transport: reg}
499 _, err := fetchExpectedChecksum(client, safeurl.NewImmutableSafeURL("https://example.com/checksums"), "copilot-linux-x64.tar.gz")
500 require.Error(t, err, "expected error for HTTP 404")
501 })
502}
503
504func archString() string {
505 arch := runtime.GOARCH

Callers

nothing calls this directly

Calls 8

RegisterMethod · 0.95
StringResponseFunction · 0.92
NewImmutableSafeURLFunction · 0.92
StatusStringResponseFunction · 0.92
fetchExpectedChecksumFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected