(t *testing.T)
| 303 | } |
| 304 | |
| 305 | func TestSRem(t *testing.T) { |
| 306 | // Creating a list of cases for testing. |
| 307 | tests := []struct { |
| 308 | name string |
| 309 | setup func(*SetStructure) |
| 310 | key string |
| 311 | membersRem []string |
| 312 | membersWant []string |
| 313 | wantErr error |
| 314 | }{ |
| 315 | { |
| 316 | name: "test when key not found", |
| 317 | setup: func(s *SetStructure) {}, |
| 318 | key: "destination", |
| 319 | membersRem: []string{"key1", "key2"}, |
| 320 | membersWant: []string{}, |
| 321 | wantErr: _const.ErrKeyNotFound, |
| 322 | }, |
| 323 | { |
| 324 | name: "test when remove one key", |
| 325 | setup: func(s *SetStructure) { |
| 326 | _ = s.SAdds("destination", 0, "key1", "key2") |
| 327 | }, |
| 328 | key: "destination", |
| 329 | membersRem: []string{"key1"}, |
| 330 | membersWant: []string{"key2"}, |
| 331 | wantErr: nil, |
| 332 | }, |
| 333 | { |
| 334 | name: "test remove all keys", |
| 335 | setup: func(s *SetStructure) { |
| 336 | _ = s.SAdds("destination", 0, "key3", "key4") |
| 337 | }, |
| 338 | key: "destination", |
| 339 | membersRem: []string{"key3", "key4"}, |
| 340 | membersWant: []string{}, |
| 341 | wantErr: nil, |
| 342 | }, |
| 343 | } |
| 344 | |
| 345 | for _, tt := range tests { |
| 346 | t.Run(tt.name, func(t *testing.T) { |
| 347 | s, _ := initTestSetDb() |
| 348 | tt.setup(s) |
| 349 | for _, s2 := range tt.membersRem { |
| 350 | // Call the method with test case parameters. |
| 351 | err := s.SRem(tt.key, s2) |
| 352 | if !errors.Is(err, tt.wantErr) { |
| 353 | t.Errorf("SRems() error = %v, wantErr %v", err, tt.wantErr) |
| 354 | } |
| 355 | } |
| 356 | if tt.wantErr == nil { |
| 357 | // positive verify |
| 358 | assert.True(t, s.exists(tt.key, tt.membersWant...)) |
| 359 | // verify removal |
| 360 | assert.False(t, s.exists(tt.key, tt.membersRem...)) |
| 361 | } |
| 362 | }) |
nothing calls this directly
no test coverage detected