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

Function TestFetchExpectedChecksum

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

Source from the content-addressed store, hash-verified

336}
337
338func TestFetchExpectedChecksum(t *testing.T) {
339 t.Run("parses checksums file correctly", func(t *testing.T) {
340 reg := &httpmock.Registry{}
341 checksums := "abc123def456 copilot-linux-x64.tar.gz\n789xyz copilot-darwin-arm64.tar.gz\n"
342 reg.Register(
343 httpmock.MatchAny,
344 httpmock.StringResponse(checksums),
345 )
346
347 client := &http.Client{Transport: reg}
348 checksum, err := fetchExpectedChecksum(client, safeurl.NewImmutableSafeURL("https://example.com/checksums"), "copilot-linux-x64.tar.gz")
349 require.NoError(t, err, "unexpected error")
350 require.Equal(t, "abc123def456", checksum, "checksum mismatch")
351 })
352
353 t.Run("returns error for missing archive", func(t *testing.T) {
354 reg := &httpmock.Registry{}
355 checksums := "abc123 copilot-linux-x64.tar.gz\n"
356 reg.Register(
357 httpmock.MatchAny,
358 httpmock.StringResponse(checksums),
359 )
360
361 client := &http.Client{Transport: reg}
362 _, err := fetchExpectedChecksum(client, safeurl.NewImmutableSafeURL("https://example.com/checksums"), "copilot-win32-x64.zip")
363 require.Error(t, err, "expected error for missing archive")
364 require.Equal(t, "checksum not found for copilot-win32-x64.zip", err.Error(), "unexpected error")
365 })
366
367 t.Run("handles single space separator", func(t *testing.T) {
368 reg := &httpmock.Registry{}
369 checksums := "abc123 copilot-darwin-x64.tar.gz\n"
370 reg.Register(
371 httpmock.MatchAny,
372 httpmock.StringResponse(checksums),
373 )
374
375 client := &http.Client{Transport: reg}
376 checksum, err := fetchExpectedChecksum(client, safeurl.NewImmutableSafeURL("https://example.com/checksums"), "copilot-darwin-x64.tar.gz")
377 require.NoError(t, err, "unexpected error")
378 require.Equal(t, "abc123", checksum, "checksum mismatch")
379 })
380
381 t.Run("handles HTTP error", func(t *testing.T) {
382 reg := &httpmock.Registry{}
383 reg.Register(
384 httpmock.MatchAny,
385 httpmock.StatusStringResponse(http.StatusNotFound, "not found"),
386 )
387
388 client := &http.Client{Transport: reg}
389 _, err := fetchExpectedChecksum(client, safeurl.NewImmutableSafeURL("https://example.com/checksums"), "copilot-linux-x64.tar.gz")
390 require.Error(t, err, "expected error for HTTP 404")
391 })
392}
393
394func archString() string {
395 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