-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynapse_test.go
69 lines (56 loc) · 1.38 KB
/
synapse_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
62
63
64
65
66
67
68
69
package main
import (
"testing"
"github.com/h2non/gock"
"github.com/stretchr/testify/suite"
)
type SynapseTestSuite struct {
suite.Suite
}
func (s *SynapseTestSuite) SetupTest() {
defer gock.Off()
}
func (s *SynapseTestSuite) TestFetchUsers() {
s.Run("Success", func() {
gock.New("http://synapse").
Get("/_synapse/admin/v3/users").
MatchHeader("Authorization", "Bearer token").
MatchHeader("Content-Type", "application/json").
MatchHeader("User-Agent", "Userli-Synapse-User-Retention").
Reply(200).
JSON(map[string]interface{}{
"users": []map[string]interface{}{
{
"name": "test",
"creation_ts": 123456,
"last_seen_ts": 123456,
},
},
})
client := NewSynapseClient("http://synapse", "token")
users, err := client.FetchUsers()
s.True(gock.IsDone())
s.NoError(err)
s.Len(users, 1)
s.Equal("test", users[0].Name)
})
s.Run("Synapse Error", func() {
gock.New("http://synapse").
Get("/_synapse/admin/v3/users").
Reply(500)
client := NewSynapseClient("http://synapse", "token")
users, err := client.FetchUsers()
s.True(gock.IsDone())
s.Error(err)
s.Nil(users)
})
s.Run("Network Error", func() {
client := NewSynapseClient("http://synapse", "token")
users, err := client.FetchUsers()
s.Error(err)
s.Nil(users)
})
}
func TestSynapseClient(t *testing.T) {
suite.Run(t, new(SynapseTestSuite))
}