Skip to content

Commit

Permalink
Fix http test
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirvivien committed Jun 8, 2024
1 parent 46ed6f6 commit e2b8edb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/vladimirvivien/gexe

go 1.16
go 1.22
18 changes: 10 additions & 8 deletions http/http_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ func TestHttpReader_String(t *testing.T) {
func TestHttpReader_Bytes(t *testing.T) {
tests := []struct {
name string
data []byte
data string
}{
{name: "no data"},
{name: "string0", data: []byte("Hello World!")},
{name: "string1", data: []byte("Hello\nWorld!")},
{name: "string0", data: "Hello World!"},
{name: "string1", data: "Hello\nWorld!"},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, string(test.data))
w.Write([]byte(test.data))

Check failure on line 55 in http/http_reader_test.go

View workflow job for this annotation

GitHub Actions / Build

Error return value of `w.Write` is not checked (errcheck)

Check failure on line 55 in http/http_reader_test.go

View workflow job for this annotation

GitHub Actions / Build

Error return value of `w.Write` is not checked (errcheck)
}))
defer ts.Close()

Expand All @@ -61,13 +61,15 @@ func TestHttpReader_Bytes(t *testing.T) {
t.Fatal(r.Err())
}

dataLen := len(r.Bytes())
data := r.Bytes()
dataLen := len(data)

if dataLen != len(test.data) {
t.Fatal("unexpected server response length: ", dataLen)
t.Fatalf("unexpected server response length: %d ", dataLen)
}

if strings.TrimSpace(string(r.Bytes())) != string(test.data) {
t.Fatal("unexpected server response: ", r.String())
if strings.TrimSpace(string(data)) != test.data {
t.Fatalf("unexpected server response: %s", r.String())
}
})
}
Expand Down

0 comments on commit e2b8edb

Please sign in to comment.