(t *testing.T)
| 88 | } |
| 89 | |
| 90 | func TestSAdd(t *testing.T) { |
| 91 | // Creating a list of cases for testing. |
| 92 | tests := []struct { |
| 93 | name string |
| 94 | setup func(*SetStructure) |
| 95 | key string |
| 96 | membersAdd []string |
| 97 | membersWant []string |
| 98 | wantErr error |
| 99 | ttl int64 |
| 100 | }{ |
| 101 | { |
| 102 | name: "test when key empty", |
| 103 | setup: func(s *SetStructure) {}, |
| 104 | key: "", |
| 105 | membersAdd: []string{"key1", "key2"}, |
| 106 | membersWant: []string{}, |
| 107 | wantErr: _const.ErrKeyIsEmpty, |
| 108 | ttl: 0, |
| 109 | }, |
| 110 | { |
| 111 | name: "test add two members", |
| 112 | setup: func(s *SetStructure) {}, |
| 113 | key: "destination", |
| 114 | membersAdd: []string{"key1", "key2"}, |
| 115 | membersWant: []string{"key1", "key2"}, |
| 116 | wantErr: nil, |
| 117 | ttl: 0, |
| 118 | }, |
| 119 | { |
| 120 | name: "test add three members one duplicate", |
| 121 | setup: func(s *SetStructure) { |
| 122 | _ = s.SAdds("destination", 0, "key2") |
| 123 | }, |
| 124 | key: "destination", |
| 125 | membersAdd: []string{"key1", "key2"}, |
| 126 | membersWant: []string{"key1", "key2"}, |
| 127 | wantErr: nil, |
| 128 | ttl: 0, |
| 129 | }, |
| 130 | { |
| 131 | name: "test add db not init", |
| 132 | setup: func(s *SetStructure) { |
| 133 | s.db = nil |
| 134 | }, |
| 135 | key: "destination", |
| 136 | membersAdd: []string{"key1", "key2"}, |
| 137 | membersWant: []string{"key1", "key2"}, |
| 138 | wantErr: ErrSetNotInitialized, |
| 139 | ttl: 0, |
| 140 | }, |
| 141 | } |
| 142 | |
| 143 | for _, tt := range tests { |
| 144 | t.Run(tt.name, func(t *testing.T) { |
| 145 | s, _ := initTestSetDb() |
| 146 | tt.setup(s) |
| 147 | // Call the method with test case parameters. |
nothing calls this directly
no test coverage detected