From d4c458d19324cd03ecb9533ca098271fff7278d4 Mon Sep 17 00:00:00 2001 From: Deluan Date: Sun, 26 Mar 2023 01:17:23 -0400 Subject: [PATCH] Add tests --- server/api/helpers_test.go | 22 ++++++++++++++++++++++ server/server_test.go | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/server/api/helpers_test.go b/server/api/helpers_test.go index 0b4a9e7d2..cd8b56c49 100644 --- a/server/api/helpers_test.go +++ b/server/api/helpers_test.go @@ -1,6 +1,8 @@ package api import ( + "net/http" + "net/http/httptest" "net/url" . "github.com/onsi/ginkgo/v2" @@ -125,6 +127,26 @@ var _ = Describe("BuildPaginationLinksAndMeta", func() { }) }) +var _ = Describe("storeRequestInContext", func() { + var ( + nextHandler http.Handler + handler http.Handler + ) + + BeforeEach(func() { + nextHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + Expect(r.Context().Value(requestInContext).(*http.Request).URL).To(Equal(r.URL)) + }) + handler = storeRequestInContext(nextHandler) + }) + + It("adds the full request object to the context", func() { + req := httptest.NewRequest("GET", "http://example.com", nil) + resp := httptest.NewRecorder() + handler.ServeHTTP(resp, req) + }) +}) + func testLinkEquality(link1, link2 *string) { parsedLink1, err := url.Parse(*link1) Expect(err).NotTo(HaveOccurred()) diff --git a/server/server_test.go b/server/server_test.go index 61d2f78da..26155f3c0 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -5,11 +5,15 @@ import ( "net/url" "github.com/navidrome/navidrome/conf" + "github.com/navidrome/navidrome/conf/configtest" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) var _ = Describe("AbsoluteURL", func() { + BeforeEach(func() { + DeferCleanup(configtest.SetupConfig()) + }) When("BaseURL is empty", func() { BeforeEach(func() { conf.Server.BasePath = ""