MCPcopy
hub / github.com/cli/cli / Test_downloadRun_cloberAndSkip

Function Test_downloadRun_cloberAndSkip

pkg/cmd/release/download/download_test.go:576–730  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

574}
575
576func Test_downloadRun_cloberAndSkip(t *testing.T) {
577 oldAssetContents := "older copy to be clobbered"
578 oldZipballContents := "older zipball to be clobbered"
579 // this should be shorter than oldAssetContents and oldZipballContents
580 newContents := "somedata"
581
582 tests := []struct {
583 name string
584 opts DownloadOptions
585 httpStubs func(*httpmock.Registry)
586 wantErr string
587 wantFileSize int64
588 wantArchiveSize int64
589 }{
590 {
591 name: "no clobber or skip",
592 opts: DownloadOptions{
593 TagName: "v1.2.3",
594 FilePatterns: []string{"windows-64bit.zip"},
595 Destination: "tmp/packages",
596 Concurrency: 2,
597 },
598 wantErr: "already exists (use `--clobber` to overwrite file or `--skip-existing` to skip file)",
599 wantFileSize: int64(len(oldAssetContents)),
600 wantArchiveSize: int64(len(oldZipballContents)),
601 },
602 {
603 name: "clobber",
604 opts: DownloadOptions{
605 TagName: "v1.2.3",
606 FilePatterns: []string{"windows-64bit.zip"},
607 Destination: "tmp/packages",
608 Concurrency: 2,
609 OverwriteExisting: true,
610 },
611 httpStubs: func(reg *httpmock.Registry) {
612 reg.Register(httpmock.REST("GET", "assets/3456"), httpmock.StringResponse(newContents))
613 },
614 wantFileSize: int64(len(newContents)),
615 wantArchiveSize: int64(len(oldZipballContents)),
616 },
617 {
618 name: "clobber archive",
619 opts: DownloadOptions{
620 TagName: "v1.2.3",
621 ArchiveType: "zip",
622 Destination: "tmp/packages",
623 Concurrency: 2,
624 OverwriteExisting: true,
625 },
626 httpStubs: func(reg *httpmock.Registry) {
627 reg.Register(
628 httpmock.REST("GET", "repos/OWNER/REPO/zipball/v1.2.3"),
629 httpmock.WithHeader(
630 httpmock.StringResponse(newContents), "content-disposition", "attachment; filename=zipball.zip",
631 ),
632 )
633 },

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
StringResponseFunction · 0.92
WithHeaderFunction · 0.92
TestFunction · 0.92
StubFetchReleaseFunction · 0.92
FromFullNameFunction · 0.92
downloadRunFunction · 0.85
JoinMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected