github.com/hduhelp/go-zero@v1.4.3/gateway/internal/timeout_test.go (about) 1 package internal 2 3 import ( 4 "net/http" 5 "net/http/httptest" 6 "testing" 7 "time" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestGetTimeout(t *testing.T) { 13 req := httptest.NewRequest("GET", "/", http.NoBody) 14 req.Header.Set(grpcTimeoutHeader, "1s") 15 timeout := GetTimeout(req.Header, time.Second*5) 16 assert.Equal(t, time.Second, timeout) 17 } 18 19 func TestGetTimeoutDefault(t *testing.T) { 20 req := httptest.NewRequest("GET", "/", http.NoBody) 21 timeout := GetTimeout(req.Header, time.Second*5) 22 assert.Equal(t, time.Second*5, timeout) 23 }