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

Function TestQueryAttributes4

internal/storage/context/attributes_test.go:88–132  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func TestQueryAttributes4(t *testing.T) {
89 attributes := []*base.Attribute{
90 {Entity: &base.Entity{Type: "type1", Id: "1"}, Attribute: "attribute1", Value: nil},
91 {Entity: &base.Entity{Type: "type3", Id: "3"}, Attribute: "attribute2", Value: nil},
92 {Entity: &base.Entity{Type: "type5", Id: "5"}, Attribute: "attribute3", Value: nil},
93 {Entity: &base.Entity{Type: "type5", Id: "4"}, Attribute: "attribute4", Value: nil},
94 {Entity: &base.Entity{Type: "type5", Id: "12"}, Attribute: "attribute12", Value: nil},
95 {Entity: &base.Entity{Type: "type5", Id: "22"}, Attribute: "attribute22", Value: nil},
96 }
97
98 contextualAttributes := NewContextualAttributes(attributes...)
99 filter := &base.AttributeFilter{Entity: &base.EntityFilter{Type: "type5", Ids: []string{}}, Attributes: []string{}}
100
101 iterator, err := contextualAttributes.QueryAttributes(filter, database.NewCursorPagination(database.Cursor("MjI="), database.Sort("entity_id")))
102 if err != nil {
103 t.Errorf("Unexpected error: %v", err)
104 }
105
106 if !iterator.HasNext() {
107 t.Errorf("Expected at least one attribute, got none")
108 }
109
110 filteredAttribute := iterator.GetNext()
111 if filteredAttribute.Entity.Type != "type5" || filteredAttribute.Entity.Id != "22" || filteredAttribute.Attribute != "attribute22" {
112 t.Errorf("Unexpected attribute: %+v", filteredAttribute)
113 }
114
115 if !iterator.HasNext() {
116 t.Errorf("Expected at least one attribute, got none")
117 }
118
119 filteredAttribute2 := iterator.GetNext()
120 if filteredAttribute2.Entity.Type != "type5" || filteredAttribute2.Entity.Id != "4" || filteredAttribute2.Attribute != "attribute4" {
121 t.Errorf("Unexpected attribute: %+v", filteredAttribute2)
122 }
123
124 if !iterator.HasNext() {
125 t.Errorf("Expected at least one attribute, got none")
126 }
127
128 filteredAttribute3 := iterator.GetNext()
129 if filteredAttribute3.Entity.Type != "type5" || filteredAttribute3.Entity.Id != "5" || filteredAttribute3.Attribute != "attribute3" {
130 t.Errorf("Unexpected attribute: %+v", filteredAttribute3)
131 }
132}

Callers

nothing calls this directly

Calls 7

QueryAttributesMethod · 0.95
NewCursorPaginationFunction · 0.92
CursorFunction · 0.92
SortFunction · 0.92
NewContextualAttributesFunction · 0.85
HasNextMethod · 0.45
GetNextMethod · 0.45

Tested by

no test coverage detected