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

Function TestSCard

structure/set_test.go:366–412  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

364}
365
366func TestSCard(t *testing.T) {
367 // Creating a list of cases for testing.
368 tests := []struct {
369 name string
370 setup func(*SetStructure)
371 key string
372 want int
373 wantErr error
374 }{
375 {
376 name: "test when key empty",
377 setup: func(s *SetStructure) {},
378 key: "",
379 want: -1,
380 wantErr: _const.ErrKeyIsEmpty,
381 },
382 {
383 name: "test two members",
384 setup: func(s *SetStructure) {
385 _ = s.SAdds("destination", 0, "mem1", "mem2")
386 },
387 key: "destination",
388 want: 2,
389 wantErr: nil,
390 },
391 {
392 name: "test three members one duplicate",
393 setup: func(s *SetStructure) {
394 _ = s.SAdds("destination", 0, "mem1", "mem2", "mem1")
395 },
396 key: "destination",
397 want: 2,
398 wantErr: nil,
399 },
400 }
401
402 for _, tt := range tests {
403 t.Run(tt.name, func(t *testing.T) {
404 s, _ := initTestSetDb()
405 tt.setup(s)
406 // Call the method with test case parameters.
407 got, err := s.SCard(tt.key)
408 assert.Equal(t, tt.wantErr, err)
409 assert.Equal(t, tt.want, got)
410 })
411 }
412}
413
414func TestSMembers(t *testing.T) {
415 // Creating a list of cases for testing.

Callers

nothing calls this directly

Calls 3

initTestSetDbFunction · 0.85
SAddsMethod · 0.65
SCardMethod · 0.65

Tested by

no test coverage detected