-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiter_test.go
76 lines (62 loc) · 1.83 KB
/
iter_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
package okms
import (
"context"
"errors"
"testing"
"github.com/ovh/okms-sdk-go/mocks"
"github.com/ovh/okms-sdk-go/types"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func TestKeyIter(t *testing.T) {
mc := mocks.NewAPIMock(t)
client := Client{mc}
it := client.ListAllServiceKeys(nil, nil)
contToken := "abcdef"
keys := []types.GetServiceKeyResponse{
{Name: "a"},
{Name: "b"},
{Name: "c"},
{Name: "d"},
}
mc.EXPECT().ListServiceKeys(mock.Anything, (*string)(nil), (*int32)(nil), (*types.KeyStates)(nil)).
Return(&types.ListServiceKeysResponse{IsTruncated: true, ContinuationToken: contToken, ObjectsList: keys[:2]}, nil).
Once()
mc.EXPECT().ListServiceKeys(mock.Anything, &contToken, (*int32)(nil), (*types.KeyStates)(nil)).
Return(&types.ListServiceKeysResponse{IsTruncated: false, ContinuationToken: "", ObjectsList: keys[2:]}, nil).
Once()
i := 0
for k, err := range it.Iter(context.Background()) {
require.NoError(t, err)
require.EqualValues(t, &keys[i], k)
i++
}
}
func TestKeyIter_error(t *testing.T) {
mc := mocks.NewAPIMock(t)
client := Client{mc}
it := client.ListAllServiceKeys(nil, nil)
contToken := "abcdef"
keys := []types.GetServiceKeyResponse{
{Name: "a"},
{Name: "b"},
{Name: "c"},
{Name: "d"},
}
mc.EXPECT().ListServiceKeys(mock.Anything, (*string)(nil), (*int32)(nil), (*types.KeyStates)(nil)).
Return(&types.ListServiceKeysResponse{IsTruncated: true, ContinuationToken: contToken, ObjectsList: keys[:2]}, nil).
Once()
mc.EXPECT().ListServiceKeys(mock.Anything, &contToken, (*int32)(nil), (*types.KeyStates)(nil)).
Return(nil, errors.New("Failure")).
Once()
i := 0
for k, err := range it.Iter(context.Background()) {
if i > 1 {
require.Error(t, err)
} else {
require.NoError(t, err)
require.EqualValues(t, &keys[i], k)
}
i++
}
}