Merge pull request #472 from mattmoyer/deflake-getpinnipedcategory-test

Make TestGetPinnipedCategory and TestKubeClientOwnerRef tests more resilient.
This commit is contained in:
Matt Moyer 2021-03-02 16:42:23 -06:00 committed by GitHub
commit aa826a1579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 10 deletions

View File

@ -7,6 +7,7 @@ import (
"bytes"
"os/exec"
"testing"
"time"
"github.com/stretchr/testify/require"
@ -20,13 +21,21 @@ func TestGetPinnipedCategory(t *testing.T) {
t.Run("category, no special params", func(t *testing.T) {
var stdOut, stdErr bytes.Buffer
cmd := exec.Command("kubectl", "get", "pinniped", "-A")
cmd.Stdout = &stdOut
cmd.Stderr = &stdErr
err := cmd.Run()
require.NoError(t, err, stdErr.String(), stdOut.String())
var err error
require.Eventuallyf(t, func() bool {
cmd := exec.Command("kubectl", "get", "pinniped", "-A")
cmd.Stdout = &stdOut
cmd.Stderr = &stdErr
err = cmd.Run()
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.NotContains(t, stdOut.String(), "MethodNotAllowed")
require.Contains(t, stdOut.String(), dotSuffix)
})

View File

@ -5,6 +5,7 @@ package integration
import (
"context"
"fmt"
"testing"
"time"
@ -75,15 +76,18 @@ func TestKubeClientOwnerRef(t *testing.T) {
UID: parentSecret.UID,
}
snorlaxAPIGroup := fmt.Sprintf("%s.snorlax.dev", library.RandHex(t, 8))
parentAPIService, err := regularAggregationClient.ApiregistrationV1().APIServices().Create(
ctx,
&apiregistrationv1.APIService{
ObjectMeta: metav1.ObjectMeta{
Name: "v1.snorlax.dev",
Name: "v1." + snorlaxAPIGroup,
Labels: map[string]string{"pinniped.dev/test": ""},
Annotations: map[string]string{"pinniped.dev/testName": t.Name()},
},
Spec: apiregistrationv1.APIServiceSpec{
Version: "v1",
Group: "snorlax.dev",
Group: snorlaxAPIGroup,
GroupPriorityMinimum: 10_000,
VersionPriority: 500,
},
@ -183,16 +187,19 @@ func TestKubeClientOwnerRef(t *testing.T) {
})
// cluster scoped API service should be owned by the other one we created above
pandasAPIGroup := fmt.Sprintf("%s.pandas.dev", library.RandHex(t, 8))
apiService, err := ownerRefClient.Aggregation.ApiregistrationV1().APIServices().Create(
ctx,
&apiregistrationv1.APIService{
ObjectMeta: metav1.ObjectMeta{
Name: "v1.pandas.dev",
Name: "v1." + pandasAPIGroup,
OwnerReferences: nil, // no owner refs set
Labels: map[string]string{"pinniped.dev/test": ""},
Annotations: map[string]string{"pinniped.dev/testName": t.Name()},
},
Spec: apiregistrationv1.APIServiceSpec{
Version: "v1",
Group: "pandas.dev",
Group: pandasAPIGroup,
GroupPriorityMinimum: 10_000,
VersionPriority: 500,
},