Fix suggestions

pull/18347/head
Jeremy Jacobson 2023-08-03 12:51:54 -07:00
parent 1a9cded960
commit cfec746d8b
2 changed files with 11 additions and 15 deletions

View File

@ -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

View File

@ -4,6 +4,7 @@
package acl
import (
"fmt"
"io"
"testing"
@ -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) {