This repository has been archived by the owner on Oct 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient_mock_test.go
237 lines (163 loc) · 6.08 KB
/
client_mock_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package schemaregistry
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_MockClient_GetSchemaByID(t *testing.T) {
mock := new(ClientMock)
mock.On("GetSchemaByID", 42).Return("some-schema", nil)
schema, err := mock.GetSchemaByID(context.Background(), 42)
assert.NoError(t, err)
assert.Equal(t, "some-schema", schema)
}
func Test_MockClient_Subjects(t *testing.T) {
mock := new(ClientMock)
mock.On("Subjects").Return([]string{"subject1", "subject2"}, nil)
subjects, err := mock.Subjects(context.Background())
assert.NoError(t, err)
assert.EqualValues(t, []string{"subject1", "subject2"}, subjects)
}
func Test_MockClient_Subjects_with_error(t *testing.T) {
mock := new(ClientMock)
mock.On("Subjects").Return(nil, fmt.Errorf("some-error"))
subjects, err := mock.Subjects(context.Background())
assert.Nil(t, subjects)
assert.EqualError(t, err, "some-error")
}
func Test_MockClient_Versions(t *testing.T) {
mock := new(ClientMock)
mock.On("Versions", "some-subject").Return([]int{1, 2, 3}, nil)
versions, err := mock.Versions(context.Background(), "some-subject")
assert.NoError(t, err)
assert.EqualValues(t, []int{1, 2, 3}, versions)
}
func Test_MockClient_Versions_with_error(t *testing.T) {
mock := new(ClientMock)
mock.On("Versions", "some-subject").Return(nil, fmt.Errorf("some-error"))
versions, err := mock.Versions(context.Background(), "some-subject")
assert.Nil(t, versions)
assert.EqualError(t, err, "some-error")
}
func Test_MockClient_DeleteSubject(t *testing.T) {
mock := new(ClientMock)
mock.On("DeleteSubject", "some-subject", true).Return([]int{1, 2, 3}, nil)
versions, err := mock.DeleteSubject(context.Background(), "some-subject", true)
assert.NoError(t, err)
assert.EqualValues(t, []int{1, 2, 3}, versions)
}
func Test_MockClient_DeleteSubject_with_error(t *testing.T) {
mock := new(ClientMock)
mock.On("DeleteSubject", "some-subject", false).Return(nil, fmt.Errorf("some-error"))
versions, err := mock.DeleteSubject(context.Background(), "some-subject", false)
assert.Nil(t, versions)
assert.EqualError(t, err, "some-error")
}
func Test_MockClient_IsRegistered(t *testing.T) {
mock := new(ClientMock)
validSchema := `{"key": "value"}`
mock.On("IsRegistered", "some-subject", validSchema).Return(true, &Schema{
Schema: validSchema,
Subject: "some-subject",
Version: 4,
}, nil)
registered, schema, err := mock.IsRegistered(context.Background(), "some-subject", validSchema)
assert.NoError(t, err)
assert.True(t, registered)
assert.EqualValues(t, &Schema{
Schema: validSchema,
Subject: "some-subject",
Version: 4,
}, schema)
}
func Test_MockClient_RegisterNewSchema(t *testing.T) {
mock := new(ClientMock)
validSchema := `{"key": "value"}`
mock.On("RegisterNewSchema", "some-subject", validSchema).Return(22, nil)
id, err := mock.RegisterNewSchema(context.Background(), "some-subject", validSchema)
assert.NoError(t, err)
assert.Equal(t, 22, id)
}
func Test_MockClient_GetSchemaBySubjectAndVersion(t *testing.T) {
mock := new(ClientMock)
validSchema := `{"key": "value"}`
mock.On("GetSchemaBySubjectAndVersion", "some-subject", 4).Return(&Schema{
Schema: validSchema,
Subject: "some-subject",
Version: 4,
}, nil)
schema, err := mock.GetSchemaBySubjectAndVersion(context.Background(), "some-subject", 4)
assert.NoError(t, err)
assert.EqualValues(t, &Schema{
Schema: validSchema,
Subject: "some-subject",
Version: 4,
}, schema)
}
func Test_MockClient_GetSchemaBySubjectAndVersion_with_error(t *testing.T) {
mock := new(ClientMock)
mock.On("GetSchemaBySubjectAndVersion", "some-subject", 4).Return(nil, fmt.Errorf("some-error"))
schema, err := mock.GetSchemaBySubjectAndVersion(context.Background(), "some-subject", 4)
assert.Nil(t, schema)
assert.EqualError(t, err, "some-error")
}
func Test_MockClient_GetLatestSchema(t *testing.T) {
mock := new(ClientMock)
validSchema := `{"key": "value"}`
mock.On("GetLatestSchema", "some-subject").Return(&Schema{
Schema: validSchema,
Subject: "some-subject",
Version: 4,
}, nil)
schema, err := mock.GetLatestSchema(context.Background(), "some-subject")
assert.NoError(t, err)
assert.EqualValues(t, &Schema{
Schema: validSchema,
Subject: "some-subject",
Version: 4,
}, schema)
}
func Test_MockClient_GetLatestSchema_with_error(t *testing.T) {
mock := new(ClientMock)
mock.On("GetLatestSchema", "some-subject").Return(nil, fmt.Errorf("some-error"))
schema, err := mock.GetLatestSchema(context.Background(), "some-subject")
assert.Nil(t, schema)
assert.EqualError(t, err, "some-error")
}
func Test_MockClient_GetConfig(t *testing.T) {
mock := new(ClientMock)
mock.On("GetConfig", "some-subject").Return(&Config{Compatibility: "FULL"}, nil)
config, err := mock.GetConfig(context.Background(), "some-subject")
assert.NoError(t, err)
assert.EqualValues(t, &Config{Compatibility: "FULL"}, config)
}
func Test_MockClient_GetConfig_with_error(t *testing.T) {
mock := new(ClientMock)
mock.On("GetConfig", "some-subject").Return(nil, fmt.Errorf("some-error"))
config, err := mock.GetConfig(context.Background(), "some-subject")
assert.Nil(t, config)
assert.EqualError(t, err, "some-error")
}
func Test_MockClient_DeleteSchemaVersion(t *testing.T) {
mock := new(ClientMock)
mock.On("DeleteSchemaVersion", "some-subject", 3, true).Return(12, nil)
id, err := mock.DeleteSchemaVersion(context.Background(), "some-subject", 3, true)
assert.NoError(t, err)
assert.Equal(t, 12, id)
}
func Test_MockClient_DeleteLatestSchemaVersion(t *testing.T) {
mock := new(ClientMock)
mock.On("DeleteLatestSchemaVersion", "some-subject", false).Return(12, nil)
id, err := mock.DeleteLatestSchemaVersion(context.Background(), "some-subject", false)
assert.NoError(t, err)
assert.Equal(t, 12, id)
}
func Test_MockClient_SchemaCompatibleWith(t *testing.T) {
mock := new(ClientMock)
validSchema := `{"key": "value"}`
mock.On("SchemaCompatibleWith", validSchema, "some-subject", 5).Return(true, nil)
isCompatible, err := mock.SchemaCompatibleWith(context.Background(), validSchema, "some-subject", 5)
assert.NoError(t, err)
assert.True(t, isCompatible)
}