-
Notifications
You must be signed in to change notification settings - Fork 458
/
client_test.go
66 lines (57 loc) · 1.59 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
package client
import (
"context"
"io"
"testing"
"github.com/golang/mock/gomock"
"github.com/sirupsen/logrus/hooks/test"
"github.com/spiffe/spire/proto/api/node"
"github.com/spiffe/spire/proto/common"
"github.com/spiffe/spire/test/mock/proto/api/node"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
var (
log, _ = test.NewNullLogger()
)
func TestFetchUpdates(t *testing.T) {
cfg := &Config{
Log: log,
}
ctrl := gomock.NewController(t)
nodeClient := mock_node.NewMockNodeClient(ctrl)
nodeFsc := mock_node.NewMockNode_FetchX509SVIDClient(ctrl)
client := New(cfg)
client.newNodeClientCallback = func() (node.NodeClient, error) {
return nodeClient, nil
}
req := &node.FetchX509SVIDRequest{
Csrs: [][]byte{{1, 2, 3, 4}},
}
res := &node.FetchX509SVIDResponse{
SvidUpdate: &node.X509SVIDUpdate{
Bundle: []byte{10, 20, 30, 40},
RegistrationEntries: []*common.RegistrationEntry{{
EntryId: "1",
}},
Svids: map[string]*node.X509SVID{
"someSpiffeId": {
Cert: []byte{11, 22, 33},
},
},
},
}
nodeClient.EXPECT().FetchX509SVID(gomock.Any()).Return(nodeFsc, nil)
nodeFsc.EXPECT().Send(req)
nodeFsc.EXPECT().CloseSend()
nodeFsc.EXPECT().Recv().Return(res, nil)
nodeFsc.EXPECT().Recv().Return(nil, io.EOF)
update, err := client.FetchUpdates(context.Background(), req)
require.Nil(t, err)
assert.Equal(t, res.SvidUpdate.Bundle, update.Bundle)
assert.Equal(t, res.SvidUpdate.Svids, update.SVIDs)
for _, entry := range res.SvidUpdate.RegistrationEntries {
assert.Equal(t, entry, update.Entries[entry.EntryId])
}
client.Release()
}