diff --git a/fs_test.go b/fs_test.go index 167ac1af..48cfd6f0 100644 --- a/fs_test.go +++ b/fs_test.go @@ -48,6 +48,36 @@ func TestOnlyFilesFS_Open_err(t *testing.T) { 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) { n := neutralizedReaddirFile{} diff --git a/gin_test.go b/gin_test.go index ce75cab1..56115547 100644 --- a/gin_test.go +++ b/gin_test.go @@ -326,8 +326,8 @@ func TestLoadHTMLFilesFuncMap(t *testing.T) { assert.Equal(t, "Date: 2017/07/01", string(resp)) } -//go:embed testdata/template/* -var htmlFS embed.FS +//go:embed testdata/template/*.tmpl +var tmplFS embed.FS func TestLoadHTMLFSTestMode(t *testing.T) { ts := setupHTMLFiles( @@ -335,7 +335,7 @@ func TestLoadHTMLFSTestMode(t *testing.T) { TestMode, false, 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() @@ -355,7 +355,7 @@ func TestLoadHTMLFSDebugMode(t *testing.T) { DebugMode, false, 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() @@ -375,7 +375,7 @@ func TestLoadHTMLFSReleaseMode(t *testing.T) { ReleaseMode, false, 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() @@ -395,7 +395,7 @@ func TestLoadHTMLFSUsingTLS(t *testing.T) { TestMode, true, 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() @@ -422,7 +422,7 @@ func TestLoadHTMLFSFuncMap(t *testing.T) { TestMode, false, 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()