MCPcopy
hub / github.com/hashicorp/go-memdb / TestTxn_Snapshot

Function TestTxn_Snapshot

txn_test.go:1567–1627  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1565}
1566
1567func TestTxn_Snapshot(t *testing.T) {
1568 db := testDB(t)
1569 txn := db.Txn(true)
1570
1571 err := txn.Insert("main", &TestObject{
1572 ID: "one",
1573 Foo: "abc",
1574 Qux: []string{"abc1", "abc2"},
1575 })
1576 if err != nil {
1577 t.Fatalf("err: %v", err)
1578 }
1579
1580 snapshot := txn.Snapshot()
1581
1582 err = txn.Insert("main", &TestObject{
1583 ID: "two",
1584 Foo: "def",
1585 Qux: []string{"def1", "def2"},
1586 })
1587 if err != nil {
1588 t.Fatalf("err: %v", err)
1589 }
1590
1591 txn.Commit()
1592
1593 raw, err := snapshot.First("main", "id", "one")
1594 if err != nil {
1595 t.Fatalf("err: %v", err)
1596 }
1597 if raw == nil || raw.(*TestObject).ID != "one" {
1598 t.Fatalf("TestObject one not found")
1599 }
1600
1601 raw, err = snapshot.First("main", "id", "two")
1602 if err != nil {
1603 t.Fatalf("err: %v", err)
1604 }
1605 if raw != nil {
1606 t.Fatalf("TestObject two found")
1607 }
1608
1609 txn = db.Txn(false)
1610 snapshot = txn.Snapshot()
1611
1612 raw, err = snapshot.First("main", "id", "one")
1613 if err != nil {
1614 t.Fatalf("err: %v", err)
1615 }
1616 if raw == nil || raw.(*TestObject).ID != "one" {
1617 t.Fatalf("TestObject one not found")
1618 }
1619
1620 raw, err = snapshot.First("main", "id", "two")
1621 if err != nil {
1622 t.Fatalf("err: %v", err)
1623 }
1624 if raw == nil || raw.(*TestObject).ID != "two" {

Callers

nothing calls this directly

Calls 6

testDBFunction · 0.85
TxnMethod · 0.80
InsertMethod · 0.80
CommitMethod · 0.80
FirstMethod · 0.80
SnapshotMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…