Make TestGetPinnipedCategory more resilient.

If the test is run immediately after the Concierge is installed, the API server can still have broken discovery data and return an error on the first call.
This commit adds a retry loop to attempt this first kubectl command for up to 60s before declaring failure.
The subsequent tests should be covered by this as well since they are not run in parallel.

Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
Matt Moyer 2021-03-02 14:17:27 -06:00
parent 30f5f66090
commit 45f57939af
No known key found for this signature in database
GPG Key ID: EAE88AD172C5AE2D

View File

@ -7,6 +7,7 @@ import (
"bytes" "bytes"
"os/exec" "os/exec"
"testing" "testing"
"time"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -20,13 +21,21 @@ func TestGetPinnipedCategory(t *testing.T) {
t.Run("category, no special params", func(t *testing.T) { t.Run("category, no special params", func(t *testing.T) {
var stdOut, stdErr bytes.Buffer var stdOut, stdErr bytes.Buffer
var err error
require.Eventuallyf(t, func() bool {
cmd := exec.Command("kubectl", "get", "pinniped", "-A") cmd := exec.Command("kubectl", "get", "pinniped", "-A")
cmd.Stdout = &stdOut cmd.Stdout = &stdOut
cmd.Stderr = &stdErr cmd.Stderr = &stdErr
err := cmd.Run() err = cmd.Run()
require.NoError(t, err, stdErr.String(), stdOut.String()) return err == nil
},
60*time.Second,
1*time.Second,
"never ran 'kubectl get pinniped -A' successfully:\n%s\n\n%s",
stdErr.String(),
stdOut.String(),
)
require.Empty(t, stdErr.String()) require.Empty(t, stdErr.String())
require.NotContains(t, stdOut.String(), "MethodNotAllowed") require.NotContains(t, stdOut.String(), "MethodNotAllowed")
require.Contains(t, stdOut.String(), dotSuffix) require.Contains(t, stdOut.String(), dotSuffix)
}) })