MCPcopy Create free account
hub / github.com/Permify/permify / TestTupleIterator

Function TestTupleIterator

pkg/database/iterators_test.go:12–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestTupleIterator(t *testing.T) {
13 // Create some tuples
14 tuple1 := &base.Tuple{
15 Subject: &base.Subject{Type: "user", Id: "u1"},
16 Relation: "rel1",
17 Entity: &base.Entity{
18 Type: "entity",
19 Id: "e1",
20 },
21 }
22
23 tuple2 := &base.Tuple{
24 Subject: &base.Subject{Type: "user", Id: "u2"},
25 Relation: "rel2",
26 Entity: &base.Entity{
27 Type: "entity",
28 Id: "e2",
29 },
30 }
31
32 tuple3 := &base.Tuple{
33 Subject: &base.Subject{Type: "user", Id: "u3"},
34 Relation: "rel3",
35 Entity: &base.Entity{
36 Type: "entity",
37 Id: "e3",
38 },
39 }
40
41 // Create a tuple collection and add the tuples
42 tupleCollection := NewTupleCollection(tuple1, tuple2, tuple3)
43
44 // Create a tuple iterator
45 tupleIterator := tupleCollection.CreateTupleIterator()
46
47 // Test HasNext() and GetNext() methods
48 if !tupleIterator.HasNext() {
49 t.Error("Expected true for HasNext(), but got false")
50 }
51 if tupleIterator.GetNext() != tuple1 {
52 t.Error("Expected tuple1 for GetNext(), but got something else")
53 }
54 if !tupleIterator.HasNext() {
55 t.Error("Expected true for HasNext(), but got false")
56 }
57 if tupleIterator.GetNext() != tuple2 {
58 t.Error("Expected tuple2 for GetNext(), but got something else")
59 }
60 if !tupleIterator.HasNext() {
61 t.Error("Expected true for HasNext(), but got false")
62 }
63 if tupleIterator.GetNext() != tuple3 {
64 t.Error("Expected tuple3 for GetNext(), but got something else")
65 }
66 if tupleIterator.HasNext() {
67 t.Error("Expected false for HasNext(), but got true")
68 }
69}

Callers

nothing calls this directly

Calls 5

CreateTupleIteratorMethod · 0.95
NewTupleCollectionFunction · 0.85
HasNextMethod · 0.45
ErrorMethod · 0.45
GetNextMethod · 0.45

Tested by

no test coverage detected