-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparser_test.go
More file actions
88 lines (71 loc) · 1.89 KB
/
Copy pathparser_test.go
File metadata and controls
88 lines (71 loc) · 1.89 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package xconn_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/xconnio/xconn-go"
)
var (
testArgs = []any{"john", "wick", 34} //nolint:gochecknoglobals
testKwargs = map[string]any{ //nolint:gochecknoglobals
"location": "NYC",
"name": "John Wick",
"trilogy": true,
}
)
func checkArgsKwargs(t *testing.T, obj interface {
Args() []any
Kwargs() map[string]any
ArgsStruct(any) error
KwargsStruct(any) error
}) {
require.Equal(t, testArgs, obj.Args())
require.Equal(t, testKwargs, obj.Kwargs())
t.Run("args-struct", func(t *testing.T) {
type User struct {
FirstName string `json:"0"`
LastName string `json:"1"`
Age int `json:"2"`
}
var user User
require.NoError(t, obj.ArgsStruct(&user))
require.Equal(t, "john", user.FirstName)
require.Equal(t, "wick", user.LastName)
require.Equal(t, 34, user.Age)
})
t.Run("kwargs-struct", func(t *testing.T) {
type Movie struct {
Location string `json:"location"`
Name string `json:"name"`
Trilogy bool `json:"trilogy"`
}
var movie Movie
require.NoError(t, obj.KwargsStruct(&movie))
require.Equal(t, "NYC", movie.Location)
require.Equal(t, "John Wick", movie.Name)
require.True(t, movie.Trilogy)
})
}
func TestInvocation(t *testing.T) {
details := map[string]any{
"procedure": "hello",
"caller": 20000,
}
inv := xconn.NewInvocation(testArgs, testKwargs, details)
checkArgsKwargs(t, inv)
t.Run("details", func(t *testing.T) {
require.Equal(t, "hello", inv.Procedure())
require.EqualValues(t, 20000, inv.Caller())
})
}
func TestEvent(t *testing.T) {
details := map[string]any{
"topic": "hello",
"publisher": 20000,
}
event := xconn.NewEvent(testArgs, testKwargs, details)
checkArgsKwargs(t, event)
t.Run("details", func(t *testing.T) {
require.Equal(t, "hello", event.Topic())
require.EqualValues(t, 20000, event.Publisher())
})
}