-
Notifications
You must be signed in to change notification settings - Fork 1
/
unarystr_test.go
48 lines (42 loc) · 1.14 KB
/
unarystr_test.go
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
44
45
46
47
48
package htadaptor_test
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/dkotik/htadaptor"
"github.com/dkotik/htadaptor/extract"
)
var unaryStringCases = []testCaseJSON[testResponse]{
{
Name: "simple unary string request",
Request: httptest.NewRequest(http.MethodGet, "/test/unarystr", nil),
Response: &testResponse{Value: "test string"},
},
}
// var unaryStringErrorCases = []testCaseJSON[errorResponse]{
// {
// Name: "empty unary string request",
// Request: httptest.NewRequest(http.MethodGet, "/test/unarystr", nil),
// Response: &errorResponse{Error: "invalid request: UUID is empty"},
// },
// }
func TestUnaryStringRequest(t *testing.T) {
mux := http.NewServeMux()
mux.Handle("/test/unarystr", htadaptor.Must(
htadaptor.NewUnaryStringFuncAdaptor(
func(ctx context.Context, s string) (*testResponse, error) {
return &testResponse{
Value: s,
}, nil
},
extract.StringValueExtractorFunc(
func(r *http.Request) (string, error) {
return "test string", nil
},
),
),
))
runCasesJSON(t, mux, unaryStringCases)
// runCasesJSON(t, mux, unaryStringErrorCases)
}