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 55 56 57 58 59 60
|
//go:build !integration
// +build !integration
package network
import (
"net/http"
"testing"
"time"
"github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/assert"
)
func responseWithHeader(key string, value string) *http.Response {
r := new(http.Response)
r.Header = make(http.Header)
r.Header.Add(key, value)
return r
}
func TestNewTracePatchResponse(t *testing.T) {
testCases := map[string]struct {
response *http.Response
expectedRemoteUpdateInterval time.Duration
}{
"nil response": {
response: nil,
expectedRemoteUpdateInterval: 0,
},
"no remote update period in header": {
response: new(http.Response),
expectedRemoteUpdateInterval: 0,
},
"invalid remote update period in header": {
response: responseWithHeader(updateIntervalHeader, "invalid"),
expectedRemoteUpdateInterval: 0,
},
"negative remote update period in header": {
response: responseWithHeader(updateIntervalHeader, "-10"),
expectedRemoteUpdateInterval: time.Duration(-10) * time.Second,
},
"valid remote update period in header": {
response: responseWithHeader(updateIntervalHeader, "10"),
expectedRemoteUpdateInterval: time.Duration(10) * time.Second,
},
}
for tn, tc := range testCases {
t.Run(tn, func(t *testing.T) {
log, _ := test.NewNullLogger()
tpr := NewRemoteJobStateResponse(tc.response, log)
assert.NotNil(t, tpr)
assert.IsType(t, &RemoteJobStateResponse{}, tpr)
assert.Equal(t, tc.expectedRemoteUpdateInterval, tpr.RemoteUpdateInterval)
})
}
}
|