MCPcopy Create free account
hub / github.com/couchbase/moss / TestCollectionGet

Function TestCollectionGet

collection_test.go:1328–1410  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1326}
1327
1328func TestCollectionGet(t *testing.T) {
1329 m, _ := NewCollection(CollectionOptions{})
1330 m.Start()
1331
1332 b, err := m.NewBatch(5, 5*4)
1333 if err != nil {
1334 t.Errorf("Expected NewBatch() to succeed!")
1335 }
1336
1337 for i := 0; i < 5; i++ {
1338 k := []byte(fmt.Sprintf("k%d", i))
1339 v := []byte(fmt.Sprintf("v%d", i))
1340 b.Set(k, v)
1341 }
1342
1343 err = m.ExecuteBatch(b, WriteOptions{})
1344 if err != nil {
1345 t.Errorf("Expected ExecuteBatch() to succeed!")
1346 }
1347
1348 b, err = m.NewBatch(3, 3*4)
1349 if err != nil {
1350 t.Errorf("Expected NewBatch() to succeed!")
1351 }
1352
1353 for i := 0; i < 3; i++ {
1354 k := []byte(fmt.Sprintf("k%d", i))
1355 v := []byte(fmt.Sprintf("n%d", i))
1356 b.Set(k, v)
1357 }
1358
1359 err = m.ExecuteBatch(b, WriteOptions{})
1360 if err != nil {
1361 t.Errorf("Expected ExecuteBatch() to succeed!")
1362 }
1363
1364 val, err := m.Get([]byte("k1"), ReadOptions{})
1365 if err != nil || val == nil {
1366 t.Errorf("Expected Get() to succeed!")
1367 }
1368 if string(val[:]) != "n1" {
1369 t.Errorf("Unexpected value for k1")
1370 }
1371
1372 val, err = m.Get([]byte("k2"), ReadOptions{})
1373 if err != nil || val == nil {
1374 t.Errorf("Expected Get() to succeed!")
1375 }
1376 if string(val[:]) != "n2" {
1377 t.Errorf("Unexpected value for k2")
1378 }
1379
1380 val, err = m.Get([]byte("k4"), ReadOptions{})
1381 if err != nil || val == nil {
1382 t.Errorf("Expected Get() to succeed!")
1383 }
1384 if string(val[:]) != "v4" {
1385 t.Errorf("Unexpected value for k1")

Callers

nothing calls this directly

Calls 8

StartMethod · 0.95
NewBatchMethod · 0.95
SetMethod · 0.95
ExecuteBatchMethod · 0.95
GetMethod · 0.95
CloseMethod · 0.95
StatsMethod · 0.95
NewCollectionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…