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

Function TestFlyDbStore_Get

lib/datastore/flydb_test.go:220–279  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

218
219}
220func TestFlyDbStore_Get(t *testing.T) {
221 type kv struct {
222 key string
223 val string
224 }
225 type test struct {
226 name string
227 input []kv
228 query []kv
229 expectError bool
230 }
231 tests := []test{
232 {
233 name: "set three",
234 input: []kv{
235 {key: "1", val: "2"},
236 {key: "foo", val: "bar"},
237 {key: "hello", val: "world"},
238 },
239 query: []kv{
240 {key: "1", val: "2"},
241 {key: "foo", val: "bar"},
242 {key: "hello", val: "world"},
243 },
244 expectError: false,
245 },
246 {
247 name: "non existence",
248 input: []kv{
249 {key: "4", val: "bar"},
250 },
251 query: []kv{
252 {key: "1", val: ""},
253 {key: "2", val: ""},
254 },
255 expectError: true,
256 },
257 }
258 for _, tc := range tests {
259 ds, err := testFlyDbDatastore()
260 assert.NoError(t, err)
261 // set all inputs
262 for _, v := range tc.input {
263 _ = ds.Set(stringToBytes(v.key), stringToBytes(v.val))
264
265 }
266 // recall all inputs
267 for _, v := range tc.query {
268 val, err := ds.Get(stringToBytes(v.key))
269 if tc.expectError {
270 assert.NotNil(t, err)
271 } else {
272 assert.NoError(t, err)
273 assert.Equal(t, v.val, string(val))
274 }
275 }
276
277 }

Callers

nothing calls this directly

Calls 4

testFlyDbDatastoreFunction · 0.85
stringToBytesFunction · 0.85
SetMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected