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