MCPcopy Index your code
hub / github.com/labstack/echo / TestEcho_StaticFS

Function TestEcho_StaticFS

echo_test.go:136–360  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

134}
135
136func TestEcho_StaticFS(t *testing.T) {
137 dotsInFilenameFS := fstest.MapFS{
138 // On Windows filename `%2f..` can not be created but in Linux it is possible.
139 "%2f..": {Data: []byte("This filename is escaped to `/..` in URL.Path")},
140 }
141
142 var testCases = []struct {
143 givenFs fs.FS
144 name string
145 givenPrefix string
146 givenFsRoot string
147 givenEnablePathUnescapingStaticFiles bool
148 whenURL string
149 expectHeaderLocation string
150 expectBodyStartsWith string
151 expectStatus int
152 }{
153 {
154 name: "ok",
155 givenPrefix: "/images",
156 givenFs: os.DirFS("./_fixture/images"),
157 whenURL: "/images/walle.png",
158 expectStatus: http.StatusOK,
159 expectBodyStartsWith: string([]byte{0x89, 0x50, 0x4e, 0x47}),
160 },
161 {
162 name: "ok, from sub fs",
163 givenPrefix: "/images",
164 givenFs: MustSubFS(os.DirFS("./_fixture/"), "images"),
165 whenURL: "/images/walle.png",
166 expectStatus: http.StatusOK,
167 expectBodyStartsWith: string([]byte{0x89, 0x50, 0x4e, 0x47}),
168 },
169 {
170 name: "No file",
171 givenPrefix: "/images",
172 givenFs: os.DirFS("_fixture/scripts"),
173 whenURL: "/images/bolt.png",
174 expectStatus: http.StatusNotFound,
175 expectBodyStartsWith: "{\"message\":\"Not Found\"}\n",
176 },
177 {
178 name: "Directory",
179 givenPrefix: "/images",
180 givenFs: os.DirFS("_fixture/images"),
181 whenURL: "/images/",
182 expectStatus: http.StatusNotFound,
183 expectBodyStartsWith: "{\"message\":\"Not Found\"}\n",
184 },
185 {
186 name: "Directory Redirect",
187 givenPrefix: "/",
188 givenFs: os.DirFS("_fixture/"),
189 whenURL: "/folder",
190 expectStatus: http.StatusMovedPermanently,
191 expectHeaderLocation: "/folder/",
192 expectBodyStartsWith: "",
193 },

Callers

nothing calls this directly

Calls 5

MustSubFSFunction · 0.85
NewWithConfigFunction · 0.85
ServeHTTPMethod · 0.80
StaticFSMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…