go-zero/gateway/internal/headerprocessor_test.go

23 lines
559 B
Go
Raw Normal View History

package internal
import (
2022-10-17 06:30:58 +08:00
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBuildHeadersNoValue(t *testing.T) {
2022-10-17 06:30:58 +08:00
req := httptest.NewRequest("GET", "/", http.NoBody)
req.Header.Add("a", "b")
assert.Nil(t, ProcessHeaders(req.Header))
}
func TestBuildHeadersWithValues(t *testing.T) {
2022-10-17 06:30:58 +08:00
req := httptest.NewRequest("GET", "/", http.NoBody)
req.Header.Add("grpc-metadata-a", "b")
req.Header.Add("grpc-metadata-b", "b")
assert.ElementsMatch(t, []string{"gateway-A:b", "gateway-B:b"}, ProcessHeaders(req.Header))
}