diff --git a/helpers_test.go b/helpers_test.go index 5f3b82f..1c60f52 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -1,7 +1,11 @@ package gobrew import ( + "net/http" + "net/http/httptest" + "net/url" "path/filepath" + "reflect" "testing" "github.com/stretchr/testify/assert" @@ -156,6 +160,14 @@ func TestGoBrew_extract(t *testing.T) { }, wantErr: false, }, + { + name: "dont.tar.gz", + args: args{ + srcTar: "testdata/dont.tar.gz", + dstDir: "tmp", + }, + wantErr: true, + }, } for _, tt := range tests { tt := tt @@ -168,3 +180,35 @@ func TestGoBrew_extract(t *testing.T) { }) } } + +func Test_doRequest(t *testing.T) { + t.Parallel() + type args struct { + url string + } + tests := []struct { + name string + args args + wantData []byte + }{ + { + name: "test.txt", + args: args{ + url: "test.txt", + }, + wantData: []byte("test"), + }, + } + for _, tt := range tests { + tt := tt + 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() + if gotData := doRequest(urlGet); !reflect.DeepEqual(gotData, tt.wantData) { + t.Errorf("doRequest() = %s, want %s", gotData, tt.wantData) + } + }) + } +} diff --git a/testdata/test.txt b/testdata/test.txt new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/testdata/test.txt @@ -0,0 +1 @@ +test \ No newline at end of file