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

Function TestBoltDbStore_Get

lib/datastore/boltdb_test.go:219–278  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

testBoltDatastoreFunction · 0.85
stringToBytesFunction · 0.85
SetMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected