Skip to content

Commit

Permalink
feat: add test for doRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
juev committed Dec 10, 2023
1 parent c0abcb6 commit b6519ed
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions 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"
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
})
}
}
1 change: 1 addition & 0 deletions testdata/test.txt
@@ -0,0 +1 @@
test

0 comments on commit b6519ed

Please sign in to comment.