Skip to content

Commit

Permalink
Adding retry for flakey server-acl-init enterprise test
Browse files Browse the repository at this point in the history
  • Loading branch information
jmurret committed Mar 11, 2022
1 parent 83e93b7 commit 7461418
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions control-plane/subcommand/server-acl-init/command_ent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,22 +758,24 @@ func TestRun_TokensWithNamespacesEnabled(t *testing.T) {
})
require.NoError(err)

// Check that the expected policy was created.
for i := range c.PolicyNames {
policy := policyExists(t, c.PolicyNames[i], consul)
require.Equal(c.PolicyDCs, policy.Datacenters)
// Test that the token was created as a Kubernetes Secret.
tokenSecret, err := k8s.CoreV1().Secrets(ns).Get(context.Background(), c.SecretNames[i], metav1.GetOptions{})
require.NoError(err)
require.NotNil(tokenSecret)
token, ok := tokenSecret.Data["token"]
require.True(ok)
// Test that the token has the expected policies in Consul.
tokenData, _, err := consul.ACL().TokenReadSelf(&api.QueryOptions{Token: string(token)})
require.NoError(err)
require.Equal(c.PolicyNames[i], tokenData.Policies[0].Name)
require.Equal(c.LocalToken, tokenData.Local)
}
retry.Run(t, func(r *retry.R) {
// Check that the expected policy was created.
for i := range c.PolicyNames {
policy := policyExists(r, c.PolicyNames[i], consul)
require.Equal(c.PolicyDCs, policy.Datacenters)
// Test that the token was created as a Kubernetes Secret.
tokenSecret, err := k8s.CoreV1().Secrets(ns).Get(context.Background(), c.SecretNames[i], metav1.GetOptions{})
require.NoError(r, err)
require.NotNil(r, tokenSecret)
token, ok := tokenSecret.Data["token"]
require.True(ok)
// Test that the token has the expected policies in Consul.
tokenData, _, err := consul.ACL().TokenReadSelf(&api.QueryOptions{Token: string(token)})
require.NoError(r, err)
require.Equal(r, c.PolicyNames[i], tokenData.Policies[0].Name)
require.Equal(r, c.LocalToken, tokenData.Local)
}
})

// Test that if the same command is run again, it doesn't error.
t.Run(testName+"-retried", func(t *testing.T) {
Expand Down

0 comments on commit 7461418

Please sign in to comment.