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 79fdf64
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 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,23 @@ func makec(tb testing.TB, roots []string, audio bool) *Controller {

return contr
}

func TestParams(t *testing.T) {
t.Parallel()

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 79fdf64

Please sign in to comment.