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

Function TestFetchExpectedChecksum

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

Source from the content-addressed store, hash-verified

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