mirror of
https://github.com/gin-gonic/gin.git
synced 2025-04-06 03:57:46 +08:00
Add OnlyHTMLFS test
This commit is contained in:
parent
3df1d433b3
commit
e21fcce345
30
fs_test.go
30
fs_test.go
@ -48,6 +48,36 @@ func TestOnlyFilesFS_Open_err(t *testing.T) {
|
|||||||
assert.Nil(t, file)
|
assert.Nil(t, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOnlyHTMLFS_Open(t *testing.T) {
|
||||||
|
var testFile *os.File
|
||||||
|
mockFS := &mockFileSystem{
|
||||||
|
open: func(name string) (http.File, error) {
|
||||||
|
return testFile, nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
fs := &OnlyHTMLFS{FileSystem: mockFS}
|
||||||
|
|
||||||
|
file, err := fs.Open("foo")
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, testFile, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOnlyHTMLFS_Open_err(t *testing.T) {
|
||||||
|
testError := errors.New("mock")
|
||||||
|
mockFS := &mockFileSystem{
|
||||||
|
open: func(_ string) (http.File, error) {
|
||||||
|
return nil, testError
|
||||||
|
},
|
||||||
|
}
|
||||||
|
fs := &OnlyHTMLFS{FileSystem: mockFS}
|
||||||
|
|
||||||
|
file, err := fs.Open("foo")
|
||||||
|
|
||||||
|
require.ErrorIs(t, err, testError)
|
||||||
|
assert.Nil(t, file)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_neuteredReaddirFile_Readdir(t *testing.T) {
|
func Test_neuteredReaddirFile_Readdir(t *testing.T) {
|
||||||
n := neutralizedReaddirFile{}
|
n := neutralizedReaddirFile{}
|
||||||
|
|
||||||
|
14
gin_test.go
14
gin_test.go
@ -326,8 +326,8 @@ func TestLoadHTMLFilesFuncMap(t *testing.T) {
|
|||||||
assert.Equal(t, "Date: 2017/07/01", string(resp))
|
assert.Equal(t, "Date: 2017/07/01", string(resp))
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:embed testdata/template/*
|
//go:embed testdata/template/*.tmpl
|
||||||
var htmlFS embed.FS
|
var tmplFS embed.FS
|
||||||
|
|
||||||
func TestLoadHTMLFSTestMode(t *testing.T) {
|
func TestLoadHTMLFSTestMode(t *testing.T) {
|
||||||
ts := setupHTMLFiles(
|
ts := setupHTMLFiles(
|
||||||
@ -335,7 +335,7 @@ func TestLoadHTMLFSTestMode(t *testing.T) {
|
|||||||
TestMode,
|
TestMode,
|
||||||
false,
|
false,
|
||||||
func(router *Engine) {
|
func(router *Engine) {
|
||||||
router.LoadHTMLFS(http.FS(htmlFS), "testdata/template/hello.tmpl", "testdata/template/raw.tmpl")
|
router.LoadHTMLFS(http.FS(tmplFS), "testdata/template/hello.tmpl", "testdata/template/raw.tmpl")
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
@ -355,7 +355,7 @@ func TestLoadHTMLFSDebugMode(t *testing.T) {
|
|||||||
DebugMode,
|
DebugMode,
|
||||||
false,
|
false,
|
||||||
func(router *Engine) {
|
func(router *Engine) {
|
||||||
router.LoadHTMLFS(http.FS(htmlFS), "testdata/template/hello.tmpl", "testdata/template/raw.tmpl")
|
router.LoadHTMLFS(http.FS(tmplFS), "testdata/template/hello.tmpl", "testdata/template/raw.tmpl")
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
@ -375,7 +375,7 @@ func TestLoadHTMLFSReleaseMode(t *testing.T) {
|
|||||||
ReleaseMode,
|
ReleaseMode,
|
||||||
false,
|
false,
|
||||||
func(router *Engine) {
|
func(router *Engine) {
|
||||||
router.LoadHTMLFS(http.FS(htmlFS), "testdata/template/hello.tmpl", "testdata/template/raw.tmpl")
|
router.LoadHTMLFS(http.FS(tmplFS), "testdata/template/hello.tmpl", "testdata/template/raw.tmpl")
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
@ -395,7 +395,7 @@ func TestLoadHTMLFSUsingTLS(t *testing.T) {
|
|||||||
TestMode,
|
TestMode,
|
||||||
true,
|
true,
|
||||||
func(router *Engine) {
|
func(router *Engine) {
|
||||||
router.LoadHTMLFS(http.FS(htmlFS), "testdata/template/hello.tmpl", "testdata/template/raw.tmpl")
|
router.LoadHTMLFS(http.FS(tmplFS), "testdata/template/hello.tmpl", "testdata/template/raw.tmpl")
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
@ -422,7 +422,7 @@ func TestLoadHTMLFSFuncMap(t *testing.T) {
|
|||||||
TestMode,
|
TestMode,
|
||||||
false,
|
false,
|
||||||
func(router *Engine) {
|
func(router *Engine) {
|
||||||
router.LoadHTMLFS(http.FS(htmlFS), "testdata/template/hello.tmpl", "testdata/template/raw.tmpl")
|
router.LoadHTMLFS(http.FS(tmplFS), "testdata/template/hello.tmpl", "testdata/template/raw.tmpl")
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user