Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions service/integration/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,42 @@ func (s *AttributesSuite) Test_CreateAttribute_NoMetadataSucceeds() {
s.NotNil(createdAttr)
}

func (s *AttributesSuite) Test_CreateAttribute_WithoutValues_DoesNotReturnEmptyValue() {
attr := &attributes.CreateAttributeRequest{
Name: "test__create_attribute_without_values",
NamespaceId: fixtureNamespaceID,
Rule: policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHY,
}

createdAttr, err := s.db.PolicyClient.CreateAttribute(s.ctx, attr)
s.Require().NoError(err)
s.Require().NotNil(createdAttr)
s.Empty(createdAttr.GetValues())

gotAttr, err := s.db.PolicyClient.GetAttribute(s.ctx, createdAttr.GetId())
s.Require().NoError(err)
s.Require().NotNil(gotAttr)
s.Empty(gotAttr.GetValues())

listRsp, err := s.db.PolicyClient.ListAttributes(s.ctx, &attributes.ListAttributesRequest{
Namespace: fixtureNamespaceID,
State: common.ActiveStateEnum_ACTIVE_STATE_ENUM_ANY,
})
s.Require().NoError(err)
s.Require().NotNil(listRsp)

for _, listedAttr := range listRsp.GetAttributes() {
if listedAttr.GetId() != createdAttr.GetId() {
continue
}

s.Empty(listedAttr.GetValues())
return
}

s.Failf("created attribute not found in list response", "attribute_id=%s", createdAttr.GetId())
}

func (s *AttributesSuite) Test_CreateAttribute_NormalizeName() {
name := "NaMe_12_ShOuLdBe-NoRmAlIzEd"
attr := &attributes.CreateAttributeRequest{
Expand Down
8 changes: 4 additions & 4 deletions service/policy/db/attributes.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions service/policy/db/queries/attributes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SELECT
'active', avt.active,
'fqn', CONCAT(fqns.fqn, '/value/', avt.value)
) ORDER BY ARRAY_POSITION(ad.values_order, avt.id)
) AS values,
) FILTER (WHERE avt.id IS NOT NULL) AS values,
Comment thread
jakedoublev marked this conversation as resolved.
Resolved
fqns.fqn,
COUNT(*) OVER() AS total
FROM attribute_definitions ad
Expand Down Expand Up @@ -307,7 +307,7 @@ SELECT
'active', avt.active,
'fqn', CONCAT(fqns.fqn, '/value/', avt.value)
) ORDER BY ARRAY_POSITION(ad.values_order, avt.id)
) AS values,
) FILTER (WHERE avt.id IS NOT NULL) AS values,
JSONB_AGG(
DISTINCT JSONB_BUILD_OBJECT(
'id', kas.id,
Expand Down
Loading