Skip to content

Commit c64a2ef

Browse files
committed
fix some tests
1 parent 6a0d1cb commit c64a2ef

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

site/site.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
225225
// If requesting the install.sh script, fill in the template with the
226226
// appropriate hostname and version info.
227227
case reqFile == "install.sh":
228-
h.serveInstallScript(rw, r)
228+
rw.Header().Add("Content-Type", "text/plain; charset=utf-8")
229+
http.ServeContent(rw, r, reqFile, time.Time{}, bytes.NewReader(h.installScript))
229230
return
230231
// If the original file path exists we serve it.
231232
case h.exists(reqFile):
@@ -316,11 +317,6 @@ func ShouldCacheFile(reqFile string) bool {
316317
return true
317318
}
318319

319-
func (h *Handler) serveInstallScript(rw http.ResponseWriter, r *http.Request) {
320-
rw.Header().Add("content-type", "text/plain; charset=utf-8")
321-
http.ServeContent(rw, r, "install.sh", time.Time{}, bytes.NewReader(h.installScript))
322-
}
323-
324320
func (h *Handler) serveHTML(resp http.ResponseWriter, request *http.Request, reqPath string, state htmlState) bool {
325321
if data, err := h.renderHTMLWithState(request, reqPath, state); err == nil {
326322
if reqPath == "" {

site/site_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ func TestInjection(t *testing.T) {
4141
"index.html": &fstest.MapFile{
4242
Data: []byte("{{ .User }}"),
4343
},
44+
"install.sh": &fstest.MapFile{
45+
Data: []byte{},
46+
},
4447
}
4548
binFs := http.FS(fstest.MapFS{})
4649
db := dbmem.New()
@@ -99,6 +102,9 @@ func TestInjectionFailureProducesCleanHTML(t *testing.T) {
99102
"index.html": &fstest.MapFile{
100103
Data: []byte("<html>{{ .User }}</html>"),
101104
},
105+
"install.sh": &fstest.MapFile{
106+
Data: []byte{},
107+
},
102108
}
103109
handler := site.New(&site.Options{
104110
BinFS: binFs,
@@ -144,6 +150,9 @@ func TestCaching(t *testing.T) {
144150
"terminal.html": &fstest.MapFile{
145151
Data: []byte("folderFile"),
146152
},
153+
"install.sh": &fstest.MapFile{
154+
Data: []byte{},
155+
},
147156
}
148157
binFS := http.FS(fstest.MapFS{})
149158

@@ -207,6 +216,9 @@ func TestServingFiles(t *testing.T) {
207216
"dashboard.css": &fstest.MapFile{
208217
Data: []byte("dashboard-css-bytes"),
209218
},
219+
"install.sh": &fstest.MapFile{
220+
Data: []byte("install-sh-bytes"),
221+
},
210222
}
211223
binFS := http.FS(fstest.MapFS{})
212224

@@ -248,6 +260,9 @@ func TestServingFiles(t *testing.T) {
248260
// JS, CSS cases
249261
{"/dashboard.js", "dashboard-js-bytes"},
250262
{"/dashboard.css", "dashboard-css-bytes"},
263+
264+
// Install script
265+
{"/install.sh", "install-sh-bytes"},
251266
}
252267

253268
for _, testCase := range testCases {
@@ -348,6 +363,9 @@ func TestServingBin(t *testing.T) {
348363
"dashboard.css": &fstest.MapFile{
349364
Data: []byte("dashboard-css-bytes"),
350365
},
366+
"install.sh": &fstest.MapFile{
367+
Data: []byte{},
368+
},
351369
}
352370

353371
sampleBinFSCorrupted := sampleBinFS()

0 commit comments

Comments
 (0)