Skip to content

Commit

Permalink
Remove assert module (#11)
Browse files Browse the repository at this point in the history
It's an extra dependency which we only ever used in a few tests.

Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
  • Loading branch information
milosgajdos authored Jun 18, 2024
1 parent ea8b4ae commit 308d334
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 47 deletions.
8 changes: 0 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
module github.com/milosgajdos/go-vocode

go 1.21

require github.com/stretchr/testify v1.9.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12 changes: 0 additions & 12 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
schema = 3

[mod]
[mod."github.com/davecgh/go-spew"]
version = "v1.1.1"
hash = "sha256-nhzSUrE1fCkN0+RL04N4h8jWmRFPPPWbCuDc7Ss0akI="
[mod."github.com/pmezard/go-difflib"]
version = "v1.0.0"
hash = "sha256-/FtmHnaGjdvEIKAJtrUfEhV7EVo5A/eYrtdnUkuxLDA="
[mod."github.com/stretchr/testify"]
version = "v1.9.0"
hash = "sha256-uUp/On+1nK+lARkTVtb5RxlW15zxtw2kaAFuIASA+J0="
[mod."gopkg.in/yaml.v3"]
version = "v3.0.1"
hash = "sha256-FqL9TKYJ0XkNwJFnq9j0VvJ5ZUU1RvH/52h/f5bkYAU="
44 changes: 27 additions & 17 deletions request/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,21 @@ import (
"context"
"fmt"
"net/http"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

func TestNewHTTPRequest(t *testing.T) {
t.Parallel()
t.Run("nil_context", func(t *testing.T) {
t.Parallel()
// nolint:staticcheck
req, err := NewHTTP(nil, http.MethodGet, "http://foo.com", nil)
assert.NoError(t, err)
assert.NotNil(t, req.Context())
})
t.Run("nil_body", func(t *testing.T) {
t.Parallel()
req, err := NewHTTP(context.TODO(), http.MethodGet, "http://foo.com", nil)
assert.NoError(t, err)
assert.NotNil(t, req.Body)
if err != nil {
t.Fatal(err)
}
if req.Body == nil {
t.Fatal("expected non-nil request body")
}
})
t.Run("with_options", func(t *testing.T) {
t.Parallel()
Expand All @@ -32,8 +28,12 @@ func TestNewHTTPRequest(t *testing.T) {
WithBearer(token),
}
req, err := NewHTTP(context.TODO(), http.MethodGet, "http://foo.com", &bytes.Reader{}, options...)
assert.NoError(t, err)
assert.NotNil(t, req.Body)
if err != nil {
t.Fatal(err)
}
if req.Body == nil {
t.Fatal("expected non-nil request body")
}

// check all default headers are set as well as the bearer one
header := make(http.Header)
Expand All @@ -42,7 +42,9 @@ func TestNewHTTPRequest(t *testing.T) {
// NOTE: this header is set by default
// on every request we create via NewHTTP.
header.Set("User-Agent", UserAgent)
assert.Equal(t, header, req.Header)
if !reflect.DeepEqual(header, req.Header) {
t.Fatalf("expected header: %+v, got: %+v", header, req.Header)
}
})
}

Expand All @@ -53,14 +55,19 @@ func TestHTTPReqOption(t *testing.T) {
req := &http.Request{}
token := "token"
WithBearer(token)(req)
assert.Equal(t, req.Header.Get("Authorization"), fmt.Sprintf("Bearer %s", token))

if authzVal := req.Header.Get("Authorization"); authzVal != fmt.Sprintf("Bearer %s", token) {
t.Fatalf("expected Authorization header val: %+v, got: %+v", fmt.Sprintf("Bearer %s", token), authzVal)
}
})
t.Run("set_header", func(t *testing.T) {
t.Parallel()
req := &http.Request{}
key, val := "foo", "bar"
WithSetHeader(key, val)(req)
assert.Equal(t, req.Header.Get(key), val)
if headerVal := req.Header.Get(key); headerVal != val {
t.Fatalf("expected header val: %+v, got: %+v", val, headerVal)
}
})

t.Run("add_header", func(t *testing.T) {
Expand All @@ -71,6 +78,9 @@ func TestHTTPReqOption(t *testing.T) {
}
req.Header.Add(key, val)
WithAddHeader(key, val)(req)
assert.Equal(t, req.Header.Values(key), []string{val, val})

if headerVals := req.Header.Values(key); !reflect.DeepEqual(headerVals, []string{val, val}) {
t.Fatalf("expected header values: %+v, got: %+v", []string{val, val}, headerVals)
}
})
}

0 comments on commit 308d334

Please sign in to comment.