-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest_test.go
More file actions
43 lines (33 loc) · 1014 Bytes
/
request_test.go
File metadata and controls
43 lines (33 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package platform_test
import (
"context"
"io"
"net/http"
"testing"
"github.com/titpetric/platform"
"github.com/titpetric/platform/pkg/require"
)
func TestParam(t *testing.T) {
svc := platform.New(platform.NewTestOptions())
svc.Register(&platform.UnimplementedModule{
NameFn: func() string { return "TestParam" },
MountFn: func(_ context.Context, mux platform.Router) error {
mux.Get("/user/{id}", func(w http.ResponseWriter, r *http.Request) {
id := platform.Param(r, "id")
foo := platform.Param(r, "foo")
_, _ = w.Write([]byte("user: " + id + " foo: " + foo))
})
return nil
},
})
require.NoError(t, svc.Start(t.Context()))
resp, err := http.Get(svc.URL() + "/user/test-id?foo=bar")
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, resp.Body.Close()) })
require.Equal(t, http.StatusOK, resp.StatusCode)
want := "user: test-id foo: bar"
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.Equal(t, want, string(body))
svc.Stop()
}