Skip to content

Commit

Permalink
add a test for params middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
sentriz committed Nov 30, 2023
1 parent 481940d commit 89de2ea
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions server/ctrlsubsonic/ctrl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"testing"

jd "github.com/josephburnett/jd/lib"
"github.com/stretchr/testify/require"

"go.senan.xyz/gonic"
"go.senan.xyz/gonic/db"
Expand Down Expand Up @@ -163,3 +164,21 @@ func makec(tb testing.TB, roots []string, audio bool) *Controller {

return contr
}

func TestParams(t *testing.T) {
handler := withParams(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
params := r.Context().Value(CtxParams).(params.Params)
require.Equal(t, "Client", params.GetOr("c", ""))
}))
params := url.Values{}
params.Set("c", "Client")

r, err := http.NewRequest(http.MethodGet, "/?"+params.Encode(), nil)
require.NoError(t, err)
handler.ServeHTTP(nil, r)

r, err = http.NewRequest(http.MethodPost, "/", strings.NewReader(params.Encode()))
require.NoError(t, err)
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
handler.ServeHTTP(nil, r)
}

0 comments on commit 89de2ea

Please sign in to comment.