(t *testing.T)
| 609 | } |
| 610 | |
| 611 | func TestInstallWithDeps_HTTPDownloadPath_Success(t *testing.T) { |
| 612 | payload := []byte("rootfs") |
| 613 | const downloadURL = "http://example.com/rootfs.tar.gz" |
| 614 | withInstallMockTransport(t, installRoundTripFunc(func(req *http.Request) (*http.Response, error) { |
| 615 | return &http.Response{ |
| 616 | StatusCode: http.StatusOK, |
| 617 | Body: io.NopCloser(strings.NewReader(string(payload))), |
| 618 | ContentLength: int64(len(payload)), |
| 619 | Header: make(http.Header), |
| 620 | }, nil |
| 621 | })) |
| 622 | |
| 623 | tmp := t.TempDir() |
| 624 | var gotRootPath string |
| 625 | wsl := wsllib.MockWslLib{ |
| 626 | RegisterDistributionFunc: func(name, rootPath string) error { |
| 627 | gotRootPath = rootPath |
| 628 | if name != "Arch" { |
| 629 | t.Fatalf("name = %q, want %q", name, "Arch") |
| 630 | } |
| 631 | return nil |
| 632 | }, |
| 633 | } |
| 634 | |
| 635 | deps := installDeps{ |
| 636 | tempDir: tmpDirConst(tmp), |
| 637 | createFile: func(path string) (io.Closer, error) { |
| 638 | return nopCloser{}, nil |
| 639 | }, |
| 640 | removeFile: func(path string) error { |
| 641 | return os.Remove(path) |
| 642 | }, |
| 643 | copyFile: func(srcPath, destPath string, compress bool) error { |
| 644 | return nil |
| 645 | }, |
| 646 | } |
| 647 | |
| 648 | err := installWithDeps(context.Background(), wsl, wsllib.MockWslReg{}, "Arch", downloadURL, "", false, deps) |
| 649 | if err != nil { |
| 650 | t.Fatalf("installWithDeps returned error: %v", err) |
| 651 | } |
| 652 | wantCachePath := getDownloadCachePath(tmp, downloadURL) |
| 653 | if gotRootPath != wantCachePath { |
| 654 | t.Fatalf("download path = %q, want %q", gotRootPath, wantCachePath) |
| 655 | } |
| 656 | if _, statErr := os.Stat(wantCachePath); !errors.Is(statErr, os.ErrNotExist) { |
| 657 | t.Fatalf("cached file still exists after successful install: %v", statErr) |
| 658 | } |
| 659 | if _, statErr := os.Stat(wantCachePath + ".part"); !errors.Is(statErr, os.ErrNotExist) { |
| 660 | t.Fatalf("partial file still exists: stat err = %v", statErr) |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | func TestInstallWithDeps_HTTPDownloadPath_RenameError(t *testing.T) { |
| 665 | payload := []byte("rootfs") |
nothing calls this directly
no test coverage detected