(t *testing.T)
| 161 | } |
| 162 | |
| 163 | func TestSAdds(t *testing.T) { |
| 164 | // Creating a list of cases for testing. |
| 165 | tests := []struct { |
| 166 | name string |
| 167 | setup func(*SetStructure) |
| 168 | key string |
| 169 | membersAdd []string |
| 170 | membersWant []string |
| 171 | wantErr error |
| 172 | ttl int64 |
| 173 | }{ |
| 174 | { |
| 175 | name: "test when key empty", |
| 176 | setup: func(s *SetStructure) {}, |
| 177 | key: "", |
| 178 | membersAdd: []string{"key1", "key2"}, |
| 179 | membersWant: []string{}, |
| 180 | wantErr: _const.ErrKeyIsEmpty, |
| 181 | ttl: 0, |
| 182 | }, |
| 183 | { |
| 184 | name: "test add two members", |
| 185 | setup: func(s *SetStructure) {}, |
| 186 | key: "destination", |
| 187 | membersAdd: []string{"key1", "key2"}, |
| 188 | membersWant: []string{"key1", "key2"}, |
| 189 | wantErr: nil, |
| 190 | ttl: 0, |
| 191 | }, |
| 192 | { |
| 193 | name: "test add three members one duplicate", |
| 194 | setup: func(s *SetStructure) { |
| 195 | _ = s.SAdds("destination", 0, "key2") |
| 196 | }, |
| 197 | key: "destination", |
| 198 | membersAdd: []string{"key1", "key2"}, |
| 199 | membersWant: []string{"key1", "key2"}, |
| 200 | wantErr: nil, |
| 201 | ttl: 0, |
| 202 | }, |
| 203 | } |
| 204 | |
| 205 | for _, tt := range tests { |
| 206 | t.Run(tt.name, func(t *testing.T) { |
| 207 | s, _ := initTestSetDb() |
| 208 | tt.setup(s) |
| 209 | // Call the method with test case parameters. |
| 210 | err := s.SAdds(tt.key, tt.ttl, tt.membersAdd...) |
| 211 | if !errors.Is(err, tt.wantErr) { |
| 212 | t.Errorf("SRems() error = %v, wantErr %v", err, tt.wantErr) |
| 213 | } |
| 214 | if tt.wantErr == nil { |
| 215 | // positive verify |
| 216 | assert.True(t, s.exists(tt.key, tt.membersWant...)) |
| 217 | } |
| 218 | }) |
| 219 | } |
| 220 | } |
nothing calls this directly
no test coverage detected