MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / TestZAdd

Function TestZAdd

structure/zset_test.go:229–275  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

227 }
228}
229func TestZAdd(t *testing.T) {
230 zs, _ := initZSetDB()
231 type testCase struct {
232 key string
233 score int
234 member string
235 value string
236 want ZSetValue
237 err error
238 }
239
240 testCases := []testCase{
241 {
242 "key",
243 10,
244 "member",
245 "value",
246 ZSetValue{member: "member"},
247 nil,
248 },
249 {
250 "",
251 10,
252 "member",
253 "value",
254 ZSetValue{member: ""},
255 _const.ErrKeyIsEmpty,
256 },
257 }
258
259 for _, tc := range testCases {
260 t.Run(tc.key, func(t *testing.T) {
261 err := zs.ZAdd(tc.key, tc.score, tc.member, tc.value)
262 assert.Equal(t, tc.err, err)
263 if tc.err == nil {
264 // check if member added
265 assert.True(t, zs.exists(tc.key, tc.score, tc.member))
266 err = zs.ZRem(tc.key, tc.member)
267 assert.NoError(t, err)
268 // should be removed successfully
269 assert.False(t, zs.exists(tc.key, tc.score, tc.member))
270 }
271 // Adjust according to your error handling
272
273 })
274 }
275}
276func TestZAdds(t *testing.T) {
277 zs, _ := initZSetDB()
278

Callers

nothing calls this directly

Calls 4

initZSetDBFunction · 0.85
ZAddMethod · 0.65
ZRemMethod · 0.65
existsMethod · 0.45

Tested by

no test coverage detected