MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / TestInMemStore_Get

Function TestInMemStore_Get

lib/datastore/inmem_test.go:207–265  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

205
206}
207func 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

Callers

nothing calls this directly

Calls 4

testMemoryDatastoreFunction · 0.85
stringToBytesFunction · 0.85
SetMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected