mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-06 22:17:37 +03:00
More tests
This commit is contained in:
parent
3bedd89c17
commit
e3079d81ea
3 changed files with 138 additions and 1 deletions
60
server/server_test.go
Normal file
60
server/server_test.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("AbsoluteURL", func() {
|
||||
When("BaseURL is empty", func() {
|
||||
BeforeEach(func() {
|
||||
conf.Server.BasePath = ""
|
||||
})
|
||||
It("uses the scheme/host from the request", func() {
|
||||
r, _ := http.NewRequest("GET", "https://myserver.com/rest/ping?id=123", nil)
|
||||
actual := AbsoluteURL(r, "/share/img/123", url.Values{"a": []string{"xyz"}})
|
||||
Expect(actual).To(Equal("https://myserver.com/share/img/123?a=xyz"))
|
||||
})
|
||||
It("does not override provided schema/host", func() {
|
||||
r, _ := http.NewRequest("GET", "http://127.0.0.1/rest/ping?id=123", nil)
|
||||
actual := AbsoluteURL(r, "http://public.myserver.com/share/img/123", url.Values{"a": []string{"xyz"}})
|
||||
Expect(actual).To(Equal("http://public.myserver.com/share/img/123?a=xyz"))
|
||||
})
|
||||
})
|
||||
When("BaseURL has only path", func() {
|
||||
BeforeEach(func() {
|
||||
conf.Server.BasePath = "/music"
|
||||
})
|
||||
It("uses the scheme/host from the request", func() {
|
||||
r, _ := http.NewRequest("GET", "https://myserver.com/rest/ping?id=123", nil)
|
||||
actual := AbsoluteURL(r, "/share/img/123", url.Values{"a": []string{"xyz"}})
|
||||
Expect(actual).To(Equal("https://myserver.com/music/share/img/123?a=xyz"))
|
||||
})
|
||||
It("does not override provided schema/host", func() {
|
||||
r, _ := http.NewRequest("GET", "http://127.0.0.1/rest/ping?id=123", nil)
|
||||
actual := AbsoluteURL(r, "http://public.myserver.com/share/img/123", url.Values{"a": []string{"xyz"}})
|
||||
Expect(actual).To(Equal("http://public.myserver.com/share/img/123?a=xyz"))
|
||||
})
|
||||
})
|
||||
When("BaseURL has full URL", func() {
|
||||
BeforeEach(func() {
|
||||
conf.Server.BaseScheme = "https"
|
||||
conf.Server.BaseHost = "myserver.com:8080"
|
||||
conf.Server.BasePath = "/music"
|
||||
})
|
||||
It("use the configured scheme/host/path", func() {
|
||||
r, _ := http.NewRequest("GET", "https://localhost:4533/rest/ping?id=123", nil)
|
||||
actual := AbsoluteURL(r, "/share/img/123", url.Values{"a": []string{"xyz"}})
|
||||
Expect(actual).To(Equal("https://myserver.com:8080/music/share/img/123?a=xyz"))
|
||||
})
|
||||
It("does not override provided schema/host", func() {
|
||||
r, _ := http.NewRequest("GET", "http://127.0.0.1/rest/ping?id=123", nil)
|
||||
actual := AbsoluteURL(r, "http://public.myserver.com/share/img/123", url.Values{"a": []string{"xyz"}})
|
||||
Expect(actual).To(Equal("http://public.myserver.com/share/img/123?a=xyz"))
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue