Skip to content

Commit

Permalink
feat: draft test for downloadAndExtract
Browse files Browse the repository at this point in the history
  • Loading branch information
juev committed Dec 10, 2023
1 parent b6519ed commit 34077fe
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gobrew.go
Expand Up @@ -297,7 +297,7 @@ func (gb *GoBrew) Install(version string) string {
gb.mkDirs(version)

color.Infof("==> [Info] Downloading version: %s\n", version)
gb.downloadAndExtract(version)
gb.downloadAndExtract(defaultRegistryPath, version)
gb.cleanDownloadsDir()
color.Successf("==> [Success] Downloaded version: %s\n", version)
return version
Expand Down
4 changes: 2 additions & 2 deletions helpers.go
Expand Up @@ -319,10 +319,10 @@ func (gb *GoBrew) getVersionDir(version string) string {
return filepath.Join(gb.versionsDir, version)
}

func (gb *GoBrew) downloadAndExtract(version string) {
func (gb *GoBrew) downloadAndExtract(url, version string) {
tarName := "go" + version + "." + gb.getArch() + tarNameExt

registryPath := defaultRegistryPath
registryPath := url
if p := os.Getenv("GOBREW_REGISTRY"); p != "" {
registryPath = p
}
Expand Down
35 changes: 32 additions & 3 deletions helpers_test.go
Expand Up @@ -153,9 +153,9 @@ func TestGoBrew_extract(t *testing.T) {
wantErr bool
}{
{
name: "arhive.tar.gz",
name: "go1.9.darwin-arm64.tar.gz",
args: args{
srcTar: "testdata/archive.tar.gz",
srcTar: "testdata/go1.9.darwin-arm64.tar.gz",
dstDir: "tmp",
},
wantErr: false,
Expand Down Expand Up @@ -204,11 +204,40 @@ func Test_doRequest(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ts := httptest.NewServer(http.FileServer(http.Dir("testdata")))
urlGet, _ := url.JoinPath(ts.URL, tt.args.url)
defer ts.Close()
urlGet, _ := url.JoinPath(ts.URL, tt.args.url)
if gotData := doRequest(urlGet); !reflect.DeepEqual(gotData, tt.wantData) {
t.Errorf("doRequest() = %s, want %s", gotData, tt.wantData)
}
})
}
}

func TestGoBrew_downloadAndExtract(t *testing.T) {
t.Skip()
t.Parallel()
type args struct {
version string
}
tests := []struct {
name string
args args
}{
{
name: "",
args: args{
version: "1.9",
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ts := httptest.NewServer(http.FileServer(http.Dir("testdata")))
defer ts.Close()
gb := NewGoBrew(t.TempDir())
gb.downloadAndExtract(ts.URL+"/", tt.args.version)
})
}
}
File renamed without changes.

0 comments on commit 34077fe

Please sign in to comment.