From c6dbe4775a68c1a0ac7e273363c1bfa063a87bba Mon Sep 17 00:00:00 2001 From: Skyenought Date: Wed, 8 Nov 2023 10:27:19 +0800 Subject: [PATCH] add more uts --- pkg/app/server/hertz_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/app/server/hertz_test.go b/pkg/app/server/hertz_test.go index 5baa3ecf5..0cc936b9e 100644 --- a/pkg/app/server/hertz_test.go +++ b/pkg/app/server/hertz_test.go @@ -32,6 +32,9 @@ import ( "testing" "time" + "github.com/cloudwego/hertz/pkg/common/ut" + "github.com/cloudwego/hertz/pkg/route" + "github.com/cloudwego/hertz/pkg/app" c "github.com/cloudwego/hertz/pkg/app/client" "github.com/cloudwego/hertz/pkg/app/server/binding" @@ -1066,3 +1069,28 @@ func TestValidateConfigAndBindConfig(t *testing.T) { assert.Nil(t, err) time.Sleep(100 * time.Millisecond) } + +func TestWithDisableDefaultDate(t *testing.T) { + engine := route.NewEngine(config.NewOptions([]config.Option{ + WithDisableDefaultDate(true), + })) + engine.GET("/", func(_ context.Context, c *app.RequestContext) { + c.String(200, "test") + }) + r := ut.PerformRequest(engine, "GET", "/", nil) + assert.DeepEqual(t, "", r.Header().Get("Date")) +} + +func TestWithDisableDefaultContentType(t *testing.T) { + h := New( + WithHostPorts("localhost:8324"), + WithDisableDefaultContentType(true), + ) + h.GET("/", func(_ context.Context, c *app.RequestContext) {}) + go h.Spin() + time.Sleep(100 * time.Millisecond) + hc := http.Client{Timeout: time.Second} + r, _ := hc.Get("http://127.0.0.1:8324") //nolint:errcheck + assert.DeepEqual(t, "", r.Header.Get("Content-Type")) + _ = h.Shutdown(context.TODO()) //nolint:errcheck +}