diff --git a/binding/binding_test.go b/binding/binding_test.go index f90488cd..78302fdf 100644 --- a/binding/binding_test.go +++ b/binding/binding_test.go @@ -1432,3 +1432,23 @@ func requestWithBody(method, path, body string) (req *http.Request) { req, _ = http.NewRequest(method, path, bytes.NewBufferString(body)) return } + +func TestPlainBindingBody(t *testing.T) { + p := Plain + + var s string + require.NoError(t, p.BindBody([]byte("hello body"), &s)) + assert.Equal(t, "hello body", s) + + var bs []byte + require.NoError(t, p.BindBody([]byte("bytes body"), &bs)) + assert.Equal(t, []byte("bytes body"), bs) + + var i int + require.Error(t, p.BindBody([]byte("fail"), &i)) + + require.NoError(t, p.BindBody([]byte(""), nil)) + + var ptr *string + require.NoError(t, p.BindBody([]byte(""), ptr)) +} diff --git a/ginS/gins_test.go b/ginS/gins_test.go index ffde85d2..995c6da1 100644 --- a/ginS/gins_test.go +++ b/ginS/gins_test.go @@ -244,3 +244,44 @@ func TestStaticFS(t *testing.T) { assert.Equal(t, http.StatusOK, w.Code) } + +func TestLoadHTMLGlob(t *testing.T) { + assert.NotPanics(t, func() { + LoadHTMLGlob("../testdata/template/*.tmpl") + }) + assert.NotNil(t, engine()) +} + +func TestLoadHTMLFiles(t *testing.T) { + assert.NotPanics(t, func() { + LoadHTMLFiles("../testdata/template/hello.tmpl", "../testdata/template/raw.tmpl") + }) + assert.NotNil(t, engine()) +} + +func TestLoadHTMLFS(t *testing.T) { + assert.NotPanics(t, func() { + LoadHTMLFS(http.Dir("../testdata/template"), "*.tmpl") + }) + assert.NotNil(t, engine()) +} + +func TestRunError(t *testing.T) { + err := Run("not-valid-address") + assert.Error(t, err) +} + +func TestRunTLSError(t *testing.T) { + err := RunTLS(":0", "/nonexistent.cert", "/nonexistent.key") + assert.Error(t, err) +} + +func TestRunUnixError(t *testing.T) { + err := RunUnix("/nonexistent/deep/path/gin-test.sock") + assert.Error(t, err) +} + +func TestRunFdError(t *testing.T) { + err := RunFd(99999) + assert.Error(t, err) +} diff --git a/render/render_test.go b/render/render_test.go index f63878b9..0236abca 100644 --- a/render/render_test.go +++ b/render/render_test.go @@ -805,3 +805,14 @@ func TestRenderWriteError(t *testing.T) { require.Error(t, err) assert.Equal(t, "write error", err.Error()) } + +func TestRedirectWriteContentType(t *testing.T) { + w := httptest.NewRecorder() + req, _ := http.NewRequest(http.MethodGet, "/", nil) + r := Redirect{Code: http.StatusFound, Request: req, Location: "/new"} + // WriteContentType is a no-op for Redirect; verify it doesn't panic + assert.NotPanics(t, func() { + r.WriteContentType(w) + }) + assert.Empty(t, w.Header().Get("Content-Type")) +}