1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
package grpctool
import (
"testing"
"github.com/stretchr/testify/assert"
)
func makePtr(x int64) *int64 {
return &x
}
func TestHttpRequest_Header_IsRequestWithoutBody(t *testing.T) {
testcases := []struct {
name string
contentLength *int64
expectedIsWithoutBody bool
}{
{
name: "no content length is set, expecting body",
contentLength: nil,
expectedIsWithoutBody: false,
},
{
name: "content length is -1, expecting body",
contentLength: makePtr(-1),
expectedIsWithoutBody: false,
},
{
name: "content length is 0, NOT expecting body",
contentLength: makePtr(0),
expectedIsWithoutBody: true,
},
{
name: "content length is 1, expecting body",
contentLength: makePtr(1),
expectedIsWithoutBody: false,
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
// GIVEN
header := HttpRequest_Header{
ContentLength: tc.contentLength,
}
// WHEN
isWithoutBody := header.IsRequestWithoutBody()
// THEN
assert.Equal(t, tc.expectedIsWithoutBody, isWithoutBody)
})
}
}
|