mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-04 17:58:14 +08:00
test: add tests for ginS and binding/plain to improve coverage
This commit is contained in:
parent
c29589e72f
commit
edff09195a
@ -1403,6 +1403,23 @@ func TestPlainBinding(t *testing.T) {
|
|||||||
require.NoError(t, p.Bind(req, ptr))
|
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) {
|
func testProtoBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body, badBody string) {
|
||||||
assert.Equal(t, name, b.Name())
|
assert.Equal(t, name, b.Name())
|
||||||
|
|
||||||
|
|||||||
@ -244,3 +244,30 @@ func TestStaticFS(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user