Skip to content

Commit

Permalink
add/update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Noah Kreiger <noahkreiger@gmail.com>
  • Loading branch information
nkreiger committed Apr 21, 2024
1 parent eb14de5 commit 99d5c4c
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
87 changes: 87 additions & 0 deletions v2/protocol/http/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,93 @@ func TestWithShutdownTimeout(t *testing.T) {
}
}

func TestWithReadTimeout(t *testing.T) {
testCases := map[string]struct {
t *Protocol
timeout time.Duration
want *Protocol
wantErr string
}{
"valid timeout": {
t: &Protocol{},
timeout: time.Minute * 4,
want: &Protocol{
ReadTimeout: time.Minute * 4,
},
},
"nil protocol": {
wantErr: `http read timeout option can not set nil protocol`,
},
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {

err := tc.t.applyOptions(WithReadTimeout(tc.timeout))

if tc.wantErr != "" || err != nil {
var gotErr string
if err != nil {
gotErr = err.Error()
}
if diff := cmp.Diff(tc.wantErr, gotErr); diff != "" {
t.Errorf("unexpected error (-want, +got) = %v", diff)
}
return
}

got := tc.t

if diff := cmp.Diff(tc.want, got,
cmpopts.IgnoreUnexported(Protocol{})); diff != "" {
t.Errorf("unexpected (-want, +got) = %v", diff)
}
})
}
}

func TestWithWriteTimeout(t *testing.T) {
testCases := map[string]struct {
t *Protocol
timeout time.Duration
want *Protocol
wantErr string
}{
"valid timeout": {
t: &Protocol{},
timeout: time.Minute * 4,
want: &Protocol{
WriteTimeout: time.Minute * 4,
},
},
"nil protocol": {
wantErr: `http write timeout option can not set nil protocol`,
},
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {

err := tc.t.applyOptions(WithWriteTimeout(tc.timeout))

if tc.wantErr != "" || err != nil {
var gotErr string
if err != nil {
gotErr = err.Error()
}
if diff := cmp.Diff(tc.wantErr, gotErr); diff != "" {
t.Errorf("unexpected error (-want, +got) = %v", diff)
}
return
}

got := tc.t

if diff := cmp.Diff(tc.want, got,
cmpopts.IgnoreUnexported(Protocol{})); diff != "" {
t.Errorf("unexpected (-want, +got) = %v", diff)
}
})
}
}
func TestWithPort(t *testing.T) {
testCases := map[string]struct {
t *Protocol
Expand Down
3 changes: 3 additions & 0 deletions v2/protocol/http/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

func TestNew(t *testing.T) {
dst := DefaultShutdownTimeout
ot := DefaultTimeout

testCases := map[string]struct {
opts []Option
Expand All @@ -36,6 +37,8 @@ func TestNew(t *testing.T) {
want: &Protocol{
Client: http.DefaultClient,
ShutdownTimeout: dst,
ReadTimeout: ot,
WriteTimeout: ot,
Port: -1,
},
},
Expand Down

0 comments on commit 99d5c4c

Please sign in to comment.