From cfec746d8b2d0b47b4aa66c951defa135f8791de Mon Sep 17 00:00:00 2001 From: Jeremy Jacobson Date: Thu, 3 Aug 2023 12:51:54 -0700 Subject: [PATCH] Fix suggestions --- command/acl/acl_helpers.go | 6 ++---- command/acl/acl_test.go | 20 +++++++++----------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/command/acl/acl_helpers.go b/command/acl/acl_helpers.go index 644fb0a402..2e6bc86dd2 100644 --- a/command/acl/acl_helpers.go +++ b/command/acl/acl_helpers.go @@ -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 diff --git a/command/acl/acl_test.go b/command/acl/acl_test.go index e04dbd0b5c..764fc35e7d 100644 --- a/command/acl/acl_test.go +++ b/command/acl/acl_test.go @@ -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) {