Skip to content

Commit

Permalink
refactored create_or_update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
aahel committed Jun 26, 2023
1 parent 00e4550 commit 2b5f74d
Showing 1 changed file with 8 additions and 32 deletions.
40 changes: 8 additions & 32 deletions control-plane/subcommand/server-acl-init/create_or_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,45 +103,23 @@ func TestCreateOrUpdateACLPolicy(t *testing.T) {
require.NoError(err)
policyDescription := "policy-description"
policyName := "policy-name"
policy, _, err := consul.ACL().PolicyCreate(&api.ACLPolicy{
Name: "new-policy-name",
Description: "new-policy-desc",
}, nil)
require.NoError(err)
cases := []struct {
Name string
ID string
PolicyDescription string
PolicyName string
Rules string
Err error
ExpPolicy *api.ACLPolicy
}{
{
Name: "create",
ID: "",
PolicyDescription: policyDescription,
PolicyName: policyName,
Rules: connectInjectRule,
Err: nil,
ExpPolicy: &api.ACLPolicy{
Name: policyName,
Description: policyDescription,
Rules: connectInjectRule,
},
},
{
Name: "update",
ID: policy.ID,
PolicyDescription: policy.Description,
PolicyName: policy.Name,
PolicyDescription: policyDescription,
PolicyName: policyName,
Rules: aclReplRule,
Err: nil,
ExpPolicy: &api.ACLPolicy{
Name: policyName,
Description: policyDescription,
Rules: aclReplRule,
},
},
}
for _, tt := range cases {
Expand All @@ -151,14 +129,12 @@ func TestCreateOrUpdateACLPolicy(t *testing.T) {
Description: tt.PolicyDescription,
Rules: tt.Rules,
}, consul)
require.Equal(tt.Err, err)
if tt.ID != "" {
readPolicy, _, err := consul.ACL().PolicyRead(tt.ID, nil)
require.NoError(err)
require.Equal(tt.Rules, readPolicy.Rules)
require.Equal(tt.PolicyName, readPolicy.Name)
require.Equal(tt.PolicyDescription, readPolicy.Description)
}
require.Nil(err)
policy, _, err := consul.ACL().PolicyReadByName(tt.PolicyName, nil)
require.Nil(err)
require.Equal(tt.Rules, policy.Rules)
require.Equal(tt.PolicyName, policy.Name)
require.Equal(tt.PolicyDescription, policy.Description)
})
}
}

0 comments on commit 2b5f74d

Please sign in to comment.