(t *testing.T)
| 205 | |
| 206 | } |
| 207 | func TestInMemStore_Get(t *testing.T) { |
| 208 | type kv struct { |
| 209 | key string |
| 210 | val string |
| 211 | } |
| 212 | type test struct { |
| 213 | name string |
| 214 | input []kv |
| 215 | query []kv |
| 216 | expectError bool |
| 217 | } |
| 218 | tests := []test{ |
| 219 | { |
| 220 | name: "set three", |
| 221 | input: []kv{ |
| 222 | {key: "1", val: "2"}, |
| 223 | {key: "foo", val: "bar"}, |
| 224 | {key: "hello", val: "world"}, |
| 225 | }, |
| 226 | query: []kv{ |
| 227 | {key: "1", val: "2"}, |
| 228 | {key: "foo", val: "bar"}, |
| 229 | {key: "hello", val: "world"}, |
| 230 | }, |
| 231 | expectError: false, |
| 232 | }, |
| 233 | { |
| 234 | name: "non existence", |
| 235 | input: []kv{ |
| 236 | {key: "4", val: "bar"}, |
| 237 | }, |
| 238 | query: []kv{ |
| 239 | {key: "1", val: ""}, |
| 240 | {key: "2", val: ""}, |
| 241 | }, |
| 242 | expectError: true, |
| 243 | }, |
| 244 | } |
| 245 | for _, tc := range tests { |
| 246 | ds := testMemoryDatastore() |
| 247 | // set all inputs |
| 248 | for _, v := range tc.input { |
| 249 | _ = ds.Set(stringToBytes(v.key), stringToBytes(v.val)) |
| 250 | |
| 251 | } |
| 252 | // recall all inputs |
| 253 | for _, v := range tc.query { |
| 254 | val, err := ds.Get(stringToBytes(v.key)) |
| 255 | if tc.expectError { |
| 256 | assert.NotNil(t, err) |
| 257 | } else { |
| 258 | assert.NoError(t, err) |
| 259 | assert.Equal(t, v.val, string(val)) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | } |
| 264 |
nothing calls this directly
no test coverage detected