-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_test.go
83 lines (66 loc) · 2.61 KB
/
client_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package rig
import (
"context"
"testing"
"connectrpc.com/connect"
"github.com/rigdev/rig-go-api/api/v1/group"
"github.com/rigdev/rig-go-api/api/v1/user"
"github.com/stretchr/testify/require"
)
func TestClient(t *testing.T) {
ctx := context.Background()
client := NewClient()
t.Log("successfully created client")
// test user client connection
createUserResp, err := client.User().Create(ctx, connect.NewRequest(&user.CreateRequest{Initializers: []*user.Update{
{Field: &user.Update_Email{Email: "[email protected]"}},
{Field: &user.Update_Password{Password: "TeamRig22!"}},
}}))
require.NoError(t, err)
t.Logf("successfully created user with ID: %v", createUserResp.Msg.GetUser().GetUserId())
_, err = client.User().Delete(ctx, connect.NewRequest(&user.DeleteRequest{
UserId: createUserResp.Msg.GetUser().GetUserId(),
}))
require.NoError(t, err)
t.Log("successfully deleted user")
// test group client connection
createGroupResp, err := client.Group().Create(ctx, connect.NewRequest(&group.CreateRequest{Initializers: []*group.Update{
{Field: &group.Update_GroupId{GroupId: "my-group"}},
}}))
require.NoError(t, err)
t.Log("successfully created group")
_, err = client.Group().Delete(ctx, connect.NewRequest(&group.DeleteRequest{
GroupId: createGroupResp.Msg.GetGroup().GetGroupId(),
}))
require.NoError(t, err)
t.Log("successfully deleted group")
}
func TestClientBasicAuth(t *testing.T) {
ctx := context.Background()
client := NewClient(WithBasicAuthOption(ClientCredential{}))
t.Log("successfully created client")
// test user client connection
createUserResp, err := client.User().Create(ctx, connect.NewRequest(&user.CreateRequest{Initializers: []*user.Update{
{Field: &user.Update_Email{Email: "[email protected]"}},
{Field: &user.Update_Password{Password: "TeamRig22!"}},
}}))
require.NoError(t, err)
t.Logf("successfully created user with ID: %v", createUserResp.Msg.GetUser().GetUserId())
_, err = client.User().Delete(ctx, connect.NewRequest(&user.DeleteRequest{
UserId: createUserResp.Msg.GetUser().GetUserId(),
}))
require.NoError(t, err)
t.Log("successfully deleted user")
// test group client connection
createGroupResp, err := client.Group().Create(ctx, connect.NewRequest(&group.CreateRequest{Initializers: []*group.Update{
{Field: &group.Update_GroupId{GroupId: "my-group"}},
}}))
require.NoError(t, err)
t.Log("successfully created group")
_, err = client.Group().Delete(ctx, connect.NewRequest(&group.DeleteRequest{
GroupId: createGroupResp.Msg.GetGroup().GetGroupId(),
}))
require.NoError(t, err)
t.Log("successfully deleted group")
t.Log("successfully created client")
}