mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-13 02:37:18 +03:00
Fix tests in pipeline
This commit is contained in:
parent
c1afe70d98
commit
b930c7253a
@ -53,7 +53,7 @@ func (app *Router) routes(path string) http.Handler {
|
||||
})
|
||||
|
||||
// Serve UI app assets
|
||||
r.Handle("/", ServeIndex(app.ds))
|
||||
r.Handle("/", ServeIndex(app.ds, assets.AssetFile()))
|
||||
r.Handle("/*", http.StripPrefix(path, http.FileServer(assets.AssetFile())))
|
||||
|
||||
return r
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/deluan/navidrome/assets"
|
||||
"github.com/deluan/navidrome/conf"
|
||||
"github.com/deluan/navidrome/consts"
|
||||
"github.com/deluan/navidrome/log"
|
||||
@ -15,13 +14,12 @@ import (
|
||||
)
|
||||
|
||||
// Injects the `firstTime` config in the `index.html` template
|
||||
func ServeIndex(ds model.DataStore) http.HandlerFunc {
|
||||
func ServeIndex(ds model.DataStore, fs http.FileSystem) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
c, err := ds.User(r.Context()).CountAll()
|
||||
firstTime := c == 0 && err == nil
|
||||
|
||||
t := template.New("initial state")
|
||||
fs := assets.AssetFile()
|
||||
indexHtml, err := fs.Open("index.html")
|
||||
if err != nil {
|
||||
log.Error(r, "Could not find `index.html` template", err)
|
||||
|
@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@ -17,6 +18,7 @@ import (
|
||||
var _ = Describe("ServeIndex", func() {
|
||||
var ds model.DataStore
|
||||
mockUser := &mockedUserRepo{}
|
||||
fs := http.Dir("tests/fixtures")
|
||||
|
||||
BeforeEach(func() {
|
||||
ds = &persistence.MockDataStore{MockedUser: mockUser}
|
||||
@ -26,7 +28,7 @@ var _ = Describe("ServeIndex", func() {
|
||||
r := httptest.NewRequest("GET", "/index.html", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
ServeIndex(ds)(w, r)
|
||||
ServeIndex(ds, fs)(w, r)
|
||||
|
||||
Expect(w.Code).To(Equal(200))
|
||||
config := extractAppConfig(w.Body.String())
|
||||
@ -38,7 +40,7 @@ var _ = Describe("ServeIndex", func() {
|
||||
r := httptest.NewRequest("GET", "/index.html", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
ServeIndex(ds)(w, r)
|
||||
ServeIndex(ds, fs)(w, r)
|
||||
|
||||
config := extractAppConfig(w.Body.String())
|
||||
Expect(config).To(HaveKeyWithValue("firstTime", true))
|
||||
@ -49,7 +51,7 @@ var _ = Describe("ServeIndex", func() {
|
||||
r := httptest.NewRequest("GET", "/index.html", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
ServeIndex(ds)(w, r)
|
||||
ServeIndex(ds, fs)(w, r)
|
||||
|
||||
config := extractAppConfig(w.Body.String())
|
||||
Expect(config).To(HaveKeyWithValue("firstTime", false))
|
||||
@ -60,7 +62,7 @@ var _ = Describe("ServeIndex", func() {
|
||||
r := httptest.NewRequest("GET", "/index.html", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
ServeIndex(ds)(w, r)
|
||||
ServeIndex(ds, fs)(w, r)
|
||||
|
||||
config := extractAppConfig(w.Body.String())
|
||||
Expect(config).To(HaveKeyWithValue("baseURL", "base_url_test"))
|
||||
|
16
tests/fixtures/index.html
vendored
Normal file
16
tests/fixtures/index.html
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta
|
||||
name="description"
|
||||
content="Navidrome Music Server - {{.Version}}"
|
||||
/>
|
||||
<title>Navidrome</title>
|
||||
<script>
|
||||
window.__APP_CONFIG__="{{.AppConfig}}"
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user