| 154 | } |
| 155 | |
| 156 | func TestEmbedFavicon(t *testing.T) { |
| 157 | is := is.New(t) |
| 158 | ctx := context.Background() |
| 159 | dir := t.TempDir() |
| 160 | td := testdir.New(dir) |
| 161 | td.BFiles["public/favicon.ico"] = favicon |
| 162 | is.NoErr(td.Write(ctx)) |
| 163 | cli := testcli.New(dir) |
| 164 | app, err := cli.Start(ctx, "run", "--embed", "--hot=false") |
| 165 | is.NoErr(err) |
| 166 | defer app.Close() |
| 167 | res, err := app.Get("/favicon.ico") |
| 168 | is.NoErr(err) |
| 169 | is.Equal(200, res.Status()) |
| 170 | is.Equal(res.Body().Bytes(), favicon) |
| 171 | // Replace favicon |
| 172 | favicon2 := []byte{0x00, 0x00, 0x01} |
| 173 | td.BFiles["public/favicon.ico"] = favicon2 |
| 174 | is.NoErr(td.Write(ctx)) |
| 175 | readyCtx, cancel := context.WithTimeout(ctx, 60*time.Second) |
| 176 | is.NoErr(app.Ready(readyCtx)) |
| 177 | cancel() |
| 178 | // Favicon shouldn't have changed because non-Go files don't trigger |
| 179 | // full rebuilds and server restarts |
| 180 | res, err = app.Get("/favicon.ico") |
| 181 | is.NoErr(err) |
| 182 | is.Equal(200, res.Status()) |
| 183 | is.Equal(res.Body().Bytes(), favicon) |
| 184 | is.NoErr(app.Close()) |
| 185 | } |