(t *testing.T)
| 513 | } |
| 514 | |
| 515 | func TestSUnion(t *testing.T) { |
| 516 | // Creating a list of cases for testing. |
| 517 | tests := []struct { |
| 518 | name string |
| 519 | setup func(*SetStructure) |
| 520 | keys []string |
| 521 | want []string |
| 522 | wantErr error |
| 523 | }{ |
| 524 | { |
| 525 | name: "test when key empty", |
| 526 | setup: func(s *SetStructure) {}, |
| 527 | keys: []string{""}, |
| 528 | want: nil, |
| 529 | wantErr: _const.ErrKeyIsEmpty, |
| 530 | }, |
| 531 | { |
| 532 | name: "test when no keys", |
| 533 | setup: func(s *SetStructure) {}, |
| 534 | keys: []string{}, |
| 535 | want: nil, |
| 536 | wantErr: nil, |
| 537 | }, |
| 538 | { |
| 539 | name: "test two members", |
| 540 | setup: func(s *SetStructure) { |
| 541 | _ = s.SAdds("key1", 0, "mem1", "mem2") |
| 542 | _ = s.SAdds("key2", 0, "mem1", "mem2") |
| 543 | }, |
| 544 | keys: []string{"key1", "key2"}, |
| 545 | want: []string{"mem1", "mem2"}, |
| 546 | wantErr: nil, |
| 547 | }, |
| 548 | { |
| 549 | name: "test three members ", |
| 550 | setup: func(s *SetStructure) { |
| 551 | _ = s.SAdds("key1", 0, "mem2", "mem1") |
| 552 | _ = s.SAdds("key2", 0, "mem3") |
| 553 | }, |
| 554 | keys: []string{"key1", "key2"}, |
| 555 | want: []string{"mem1", "mem2", "mem3"}, |
| 556 | wantErr: nil, |
| 557 | }, |
| 558 | } |
| 559 | |
| 560 | for _, tt := range tests { |
| 561 | t.Run(tt.name, func(t *testing.T) { |
| 562 | s, _ := initTestSetDb() |
| 563 | tt.setup(s) |
| 564 | got, err := s.SUnion(tt.keys...) |
| 565 | assert.Equal(t, tt.wantErr, err) |
| 566 | sort.Strings(got) |
| 567 | assert.True(t, reflect.DeepEqual(tt.want, got)) |
| 568 | |
| 569 | }) |
| 570 | } |
| 571 | } |
| 572 |
nothing calls this directly
no test coverage detected