Skip to content

Commit

Permalink
Fix suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jjacobson93 committed Aug 3, 2023
1 parent 1a9cded commit cfec746
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
6 changes: 2 additions & 4 deletions command/acl/acl_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ func GetTokenAccessorIDFromPartial(client *api.Client, partialAccessorID string)

func GetPolicyIDFromPartial(client *api.Client, partialID string) (string, error) {
// try the builtin policies (by name) first
for _, policy := range structs.ACLBuiltinPolicies {
if partialID == policy.Name {
return policy.ID, nil
}
if policy, ok := structs.ACLBuiltinPolicies[partialID]; ok {
return policy.ID, nil
}

// The full UUID string was given
Expand Down
20 changes: 9 additions & 11 deletions command/acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package acl

import (
"fmt"
"io"
"testing"

Expand Down Expand Up @@ -37,17 +38,14 @@ func Test_GetPolicyIDByName_Builtins(t *testing.T) {
client := a.Client()
client.AddHeader("X-Consul-Token", "root")

t.Run("global management policy", func(t *testing.T) {
id, err := GetPolicyIDByName(client, structs.ACLPolicyGlobalManagementName)
require.NoError(t, err)
require.Equal(t, structs.ACLPolicyGlobalManagementID, id)
})

t.Run("global read-only policy", func(t *testing.T) {
id, err := GetPolicyIDByName(client, structs.ACLPolicyGlobalReadOnlyName)
require.NoError(t, err)
require.Equal(t, structs.ACLPolicyGlobalReadOnlyID, id)
})
for _, policy := range structs.ACLBuiltinPolicies {
name := fmt.Sprintf("%s policy", policy.Name)
t.Run(name, func(t *testing.T) {
id, err := GetPolicyIDByName(client, policy.Name)
require.NoError(t, err)
require.Equal(t, policy.ID, id)
})
}
}

func Test_GetPolicyIDFromPartial_Builtins(t *testing.T) {
Expand Down

0 comments on commit cfec746

Please sign in to comment.