Skip to content

Commit

Permalink
test: EntityAndCallOrAttributeToString
Browse files Browse the repository at this point in the history
  • Loading branch information
tolgaOzen committed Sep 16, 2023
1 parent c36d708 commit 80493d8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 43 deletions.
64 changes: 64 additions & 0 deletions pkg/attribute/attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,69 @@ var _ = Describe("attribute", func() {
Expect(Attribute(tt.target)).Should(Equal(tt.attribute))
}
})

It("EntityAndCallOrAttributeToString", func() {
tests := []struct {
entity *base.Entity
attributeOrCall string
arguments []*base.Argument
result string
}{
{
entity: &base.Entity{
Type: "organization",
Id: "1",
},
attributeOrCall: "check_credit",
arguments: []*base.Argument{
{
Type: &base.Argument_ComputedAttribute{
ComputedAttribute: &base.ComputedAttribute{
Name: "credit",
},
},
},
},
result: "organization:1$check_credit(credit)",
},
{
entity: &base.Entity{
Type: "organization",
Id: "1",
},
attributeOrCall: "is_public",
arguments: nil,
result: "organization:1$is_public",
},
{
entity: &base.Entity{
Type: "organization",
Id: "877",
},
attributeOrCall: "check_balance",
arguments: []*base.Argument{
{
Type: &base.Argument_ContextAttribute{
ContextAttribute: &base.ContextAttribute{
Name: "amount",
},
},
},
{
Type: &base.Argument_ComputedAttribute{
ComputedAttribute: &base.ComputedAttribute{
Name: "balance",
},
},
},
},
result: "organization:877$check_balance(request.amount,balance)",
},
}

for _, tt := range tests {
Expect(EntityAndCallOrAttributeToString(tt.entity, tt.attributeOrCall, tt.arguments...)).Should(Equal(tt.result))
}
})
})
})
48 changes: 5 additions & 43 deletions pkg/tuple/tuple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,65 +20,27 @@ var _ = Describe("tuple", func() {
Context("TupleToString", func() {
It("EntityAndRelationToString", func() {
tests := []struct {
target *base.EntityAndRelation
arguments []*base.Argument
expected string
target *base.EntityAndRelation
expected string
}{
{&base.EntityAndRelation{
Entity: &base.Entity{
Type: "repository",
Id: "1",
},
Relation: "admin",
}, nil, "repository:1#admin"},
}, "repository:1#admin"},
{&base.EntityAndRelation{
Entity: &base.Entity{
Type: "doc",
Id: "1",
},
Relation: "viewer",
}, nil, "doc:1#viewer"},
{&base.EntityAndRelation{
Entity: &base.Entity{
Type: "doc",
Id: "1",
},
Relation: "check_balance",
}, []*base.Argument{
{
Type: &base.Argument_ComputedAttribute{
ComputedAttribute: &base.ComputedAttribute{
Name: "balance",
},
},
},
}, "doc:1#check_balance(balance)"},
{&base.EntityAndRelation{
Entity: &base.Entity{
Type: "doc",
Id: "1",
},
Relation: "check_balance",
}, []*base.Argument{
{
Type: &base.Argument_ContextAttribute{
ContextAttribute: &base.ContextAttribute{
Name: "amount",
},
},
},
{
Type: &base.Argument_ComputedAttribute{
ComputedAttribute: &base.ComputedAttribute{
Name: "balance",
},
},
},
}, "doc:1#check_balance(request.amount,balance)"},
}, "doc:1#viewer"},
}

for _, tt := range tests {
Expect(EntityAndRelationToString(tt.target, tt.arguments...)).Should(Equal(tt.expected))
Expect(EntityAndRelationToString(tt.target.GetEntity(), tt.target.GetRelation())).Should(Equal(tt.expected))
}
})
})
Expand Down

0 comments on commit 80493d8

Please sign in to comment.