Skip to content

Commit

Permalink
remove bracketing
Browse files Browse the repository at this point in the history
  • Loading branch information
rboyer committed Feb 2, 2024
1 parent c0021f6 commit 0425833
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
12 changes: 2 additions & 10 deletions internal/catalog/internal/controllers/endpoints/bound.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,11 @@ func GetBoundIdentities(typ *pbresource.Type, res *pbresource.Resource) []*pbres
break
}
}
if len(encoded) <= 2 {
return nil // it could only ever be [] which is nothing
}

n := len(encoded)

if encoded[0] != '[' || encoded[n-1] != ']' {
if encoded == "" {
return nil
}

trimmed := encoded[1 : n-1]

identities := strings.Split(trimmed, ",")
identities := strings.Split(encoded, ",")

// Ensure determinstic sort so we don't get into infinite-reconcile
sort.Strings(identities)
Expand Down
10 changes: 5 additions & 5 deletions internal/catalog/internal/controllers/endpoints/bound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,27 @@ func TestGetBoundIdentities(t *testing.T) {
require.Empty(t, run(build(&pbresource.Condition{
Type: endpoints.StatusConditionBoundIdentities,
State: pbresource.Condition_STATE_TRUE,
Message: "[]",
Message: "",
})))
require.Equal(t, []string{"foo"}, run(build(&pbresource.Condition{
Type: endpoints.StatusConditionBoundIdentities,
State: pbresource.Condition_STATE_TRUE,
Message: "[foo]",
Message: "foo",
})))
require.Empty(t, run(build(&pbresource.Condition{
Type: endpoints.StatusConditionBoundIdentities,
State: pbresource.Condition_STATE_FALSE,
Message: "[foo]",
Message: "foo",
})))
require.Equal(t, []string{"bar", "foo"}, run(build(&pbresource.Condition{
Type: endpoints.StatusConditionBoundIdentities,
State: pbresource.Condition_STATE_TRUE,
Message: "[bar,foo]", // proper order
Message: "bar,foo", // proper order
})))
require.Equal(t, []string{"bar", "foo"}, run(build(&pbresource.Condition{
Type: endpoints.StatusConditionBoundIdentities,
State: pbresource.Condition_STATE_TRUE,
Message: "[foo,bar]", // incorrect order gets fixed
Message: "foo,bar", // incorrect order gets fixed
})))

}
4 changes: 2 additions & 2 deletions internal/catalog/internal/controllers/endpoints/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (
Type: StatusConditionBoundIdentities,
State: pbresource.Condition_STATE_FALSE,
Reason: StatusReasonNoWorkloadIdentitiesFound,
Message: "[]",
Message: "",
}
)

Expand All @@ -56,6 +56,6 @@ func ConditionIdentitiesFound(identities []string) *pbresource.Condition {
Type: StatusConditionBoundIdentities,
State: pbresource.Condition_STATE_TRUE,
Reason: StatusReasonWorkloadIdentitiesFound,
Message: "[" + strings.Join(identities, ",") + "]",
Message: strings.Join(identities, ","),
}
}

0 comments on commit 0425833

Please sign in to comment.