🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Fix tests in pipeline
Deluanb930c7253afb
diff --git a/server/app/app.go b/server/app/app.goindex cd09a7c2f..13f27c61e 100644--- a/server/app/app.go+++ b/server/app/app.go@@ -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 rdiff --git a/server/app/serve_index.go b/server/app/serve_index.goindex 0752a78a9..f2b175cdc 100644--- a/server/app/serve_index.go+++ b/server/app/serve_index.go@@ -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 == nilt := 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)diff --git a/server/app/serve_index_test.go b/server/app/serve_index_test.goindex 9eaa58010..20f914ee8 100644--- a/server/app/serve_index_test.go+++ b/server/app/serve_index_test.go@@ -3,6 +3,7 @@ package appimport ("encoding/json""fmt"+ "net/http""net/http/httptest""regexp""strconv"@@ -17,6 +18,7 @@ import (var _ = Describe("ServeIndex", func() {var ds model.DataStoremockUser := &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"))diff --git a/tests/fixtures/index.html b/tests/fixtures/index.htmlnew file mode 100644index 000000000..f93ce189c--- /dev/null+++ b/tests/fixtures/index.html@@ -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>