-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser_test.go
61 lines (51 loc) · 1.44 KB
/
user_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
56
57
58
59
60
61
package sentry
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func ExampleUser() {
user := UserInfo{
ID: "17ba08f7cc89a912bf812918",
Email: "[email protected]",
Username: "Test User",
IPAddress: "127.0.0.1",
Extra: map[string]string{
"role": "Tester",
},
}
cl := NewClient(
// You can specify your user when you create your client
User(&user),
)
cl.Capture(
// Or when you send an event to Sentry
User(&user),
)
}
func TestUser(t *testing.T) {
assert.Nil(t, User(nil), "it should return nil if the user details are nil")
user := UserInfo{
ID: "17ba08f7cc89a912bf812918",
Email: "[email protected]",
Username: "Test User",
IPAddress: "127.0.0.1",
Extra: map[string]string{
"role": "Tester",
},
}
fields := map[string]interface{}{
"id": "17ba08f7cc89a912bf812918",
"email": "[email protected]",
"username": "Test User",
"ip_address": "127.0.0.1",
"role": "Tester",
}
o := User(&user)
require.NotNil(t, o, "should not return a nil option")
assert.Implements(t, (*Option)(nil), o, "it should implement the Option interface")
assert.Equal(t, "user", o.Class(), "it should use the right option class")
t.Run("MarshalJSON()", func(t *testing.T) {
assert.Equal(t, fields, testOptionsSerialize(t, o), "it should serialize to the right fields")
})
}