go-zero/gateway/internal/timeout_test.go
Kevin Wan 557383fbbf
feat: verify RpcPath on startup (#2159)
* feat: verify RpcPath on startup

* feat: support http header Grpc-Timeout
2022-07-17 12:37:23 +08:00

23 lines
504 B
Go

package internal
import (
"net/http/httptest"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestGetTimeout(t *testing.T) {
req := httptest.NewRequest("GET", "/", nil)
req.Header.Set(grpcTimeoutHeader, "1s")
timeout := GetTimeout(req.Header, time.Second*5)
assert.Equal(t, time.Second, timeout)
}
func TestGetTimeoutDefault(t *testing.T) {
req := httptest.NewRequest("GET", "/", nil)
timeout := GetTimeout(req.Header, time.Second*5)
assert.Equal(t, time.Second*5, timeout)
}