mirror of
https://github.com/photoprism/photoprism.git
synced 2026-01-23 02:24:24 +00:00
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package header
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRequest(t *testing.T) {
|
|
t.Run("Header", func(t *testing.T) {
|
|
assert.Equal(t, "Cookie", Cookie)
|
|
assert.Equal(t, "Referer", Referer)
|
|
assert.Equal(t, "Sec-Ch-Ua", Browser)
|
|
assert.Equal(t, "Sec-Ch-Ua-Platform", Platform)
|
|
assert.Equal(t, "Sec-Fetch-Mode", FetchMode)
|
|
})
|
|
t.Run("UserAgent", func(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
w := httptest.NewRecorder()
|
|
c, _ := gin.CreateTestContext(w)
|
|
c.Request = &http.Request{
|
|
RemoteAddr: httptest.DefaultRemoteAddr,
|
|
Header: http.Header{
|
|
"User-Agent": []string{"TEST"},
|
|
Browser: []string{"\"Chromium\";v=\"130\", \"Google Chrome\";v=\"130\", \"Not?A_Brand\";v=\"99\""},
|
|
Platform: []string{"\"Linux\""},
|
|
FetchMode: []string{"navigate"},
|
|
Cookie: []string{"CockpitLang=en-us; Foo=Bar"},
|
|
},
|
|
}
|
|
assert.Equal(t, "TEST", ClientUserAgent(c))
|
|
assert.Equal(t, "\"Chromium\";v=\"130\", \"Google Chrome\";v=\"130\", \"Not?A_Brand\";v=\"99\"", c.GetHeader(Browser))
|
|
assert.Equal(t, "\"Linux\"", c.GetHeader(Platform))
|
|
assert.Equal(t, "navigate", c.GetHeader(FetchMode))
|
|
assert.Equal(t, "CockpitLang=en-us; Foo=Bar", c.GetHeader(Cookie))
|
|
})
|
|
}
|