diff --git a/pkg/downloader/getter_test.go b/pkg/downloader/getter_test.go index 74aa473b6..9dce465db 100644 --- a/pkg/downloader/getter_test.go +++ b/pkg/downloader/getter_test.go @@ -17,6 +17,7 @@ package downloader import ( + "fmt" "reflect" "testing" ) @@ -131,3 +132,115 @@ func TestGetURLSubDir(t *testing.T) { } } } + +func TestDownload(t *testing.T) { + + table := []struct { + name string + URL string + dest string + wantDest string + wantErr error + }{ + { + name: "empty URL", + URL: "", + dest: "some-destination", + wantDest: "", + wantErr: ErrEmptyURLDest, + }, + { + name: "empty destination", + URL: "some-url", + dest: "", + wantDest: "", + wantErr: ErrEmptyURLDest, + }, + { + name: "invalid url", + URL: "github.com/some-repo", + dest: "some-dest", + wantDest: "", + wantErr: fmt.Errorf("GitHub URLs should be github.com/username/repo"), + }, + } + + for _, tt := range table { + t.Run(tt.name, func(t *testing.T) { + g := NewGoGetter() + gotDest, gotErr := g.Download(tt.URL, tt.dest) + if !reflect.DeepEqual(gotErr, tt.wantErr) { + t.Errorf("error got: '%v', want: '%v'", gotErr, tt.wantErr) + } + if !reflect.DeepEqual(gotDest, tt.wantDest) { + t.Errorf("dest got: '%v', want: '%v'", gotDest, tt.wantDest) + } + }) + } +} + +func TestDownloadWithType(t *testing.T) { + + table := []struct { + name string + Type string + URL string + dest string + wantDest string + wantErr error + }{ + { + name: "empty URL and Type", + Type: "", + URL: "", + dest: "some-destination", + wantDest: "", + wantErr: ErrEmptyURLType, + }, + { + name: "empty URL", + Type: "some-type", + URL: "", + dest: "some-destination", + wantDest: "", + wantErr: ErrEmptyURLDest, + }, + { + name: "empty Type", + Type: "", + URL: "some-url", + dest: "some-destination", + wantDest: "", + wantErr: ErrEmptyURLDest, + }, + { + name: "empty dest", + Type: "some-type", + URL: "some-url", + dest: "", + wantDest: "", + wantErr: ErrEmptyURLDest, + }, + { + name: "invalid url", + Type: "some-type", + URL: "github.com/some-url", + dest: "some-dest", + wantDest: "", + wantErr: fmt.Errorf("download not supported for scheme 'some-type'"), + }, + } + + for _, tt := range table { + t.Run(tt.name, func(t *testing.T) { + g := NewGoGetter() + gotDest, gotErr := g.DownloadWithType(tt.Type, tt.URL, tt.dest) + if !reflect.DeepEqual(gotErr, tt.wantErr) { + t.Errorf("error got: '%v', want: '%v'", gotErr, tt.wantErr) + } + if !reflect.DeepEqual(gotDest, tt.wantDest) { + t.Errorf("dest got: '%v', want: '%v'", gotDest, tt.wantDest) + } + }) + } +}