-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonapi_test.go
55 lines (44 loc) · 1.03 KB
/
jsonapi_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
49
50
51
52
53
54
55
package jsonapi_test
import (
"context"
"embed"
"fmt"
"github.com/mnavarrocarter/jsonapi"
"io/fs"
"net/http"
"reflect"
"testing"
)
//go:embed testdata
var testdata embed.FS
func mustOpen(t *testing.T, name string) fs.File {
t.Helper()
f, err := testdata.Open(fmt.Sprintf("testdata/%s", name))
if err != nil {
panic(err)
}
return f
}
type testCmd struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Months int `json:"months,omitempty"`
Rate float64 `json:"rate,omitempty"`
Deposit bool `json:"deposit,omitempty"`
}
type testResp struct {
Msg string `json:"msg"`
}
var stringMapType = reflect.TypeOf((*map[string]string)(nil)).Elem()
type wrappedResolver struct {
next jsonapi.ArgumentResolver
}
func (w *wrappedResolver) Resolve(req *http.Request, t reflect.Type, pos int) (reflect.Value, error) {
if t == stringMapType {
return reflect.ValueOf(map[string]string{"hello": "world"}), nil
}
return w.next.Resolve(req, t, pos)
}
type customContext struct {
context.Context
}