test: add tests for ginS and binding/plain to improve coverage

This commit is contained in:
mehrdadbn9 2026-02-13 14:38:53 +03:30
parent c29589e72f
commit edff09195a
2 changed files with 44 additions and 0 deletions

View File

@ -1403,6 +1403,23 @@ func TestPlainBinding(t *testing.T) {
require.NoError(t, p.Bind(req, ptr))
}
func TestPlainBindingBindBody(t *testing.T) {
p := Plain
var s string
require.NoError(t, p.BindBody([]byte("test body"), &s))
assert.Equal(t, "test body", s)
var bs []byte
require.NoError(t, p.BindBody([]byte("test bytes"), &bs))
assert.Equal(t, []byte("test bytes"), bs)
var i int
require.Error(t, p.BindBody([]byte("test"), &i))
require.NoError(t, p.BindBody([]byte("test"), nil))
}
func testProtoBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body, badBody string) {
assert.Equal(t, name, b.Name())

View File

@ -244,3 +244,30 @@ func TestStaticFS(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code)
}
func TestLoadHTMLGlob(t *testing.T) {
LoadHTMLGlob("../testdata/template/*.tmpl")
}
func TestLoadHTMLFiles(t *testing.T) {
LoadHTMLFiles("../testdata/template/hello.tmpl")
}
func TestLoadHTMLFS(t *testing.T) {
LoadHTMLFS(http.Dir("../testdata/template"), "hello.tmpl")
}
func TestRunInvalidAddress(t *testing.T) {
err := Run("invalid:address:format")
assert.Error(t, err)
}
func TestRunTLSInvalid(t *testing.T) {
err := RunTLS("invalid:address:format", "nonexistent.crt", "nonexistent.key")
assert.Error(t, err)
}
func TestRunUnixInvalid(t *testing.T) {
err := RunUnix("/nonexistent/path/socket.sock")
assert.Error(t, err)
}