test(asset): add list-assets retries
Fixes
@@ -19,6 +19,7 @@ import (
"os"
"strings"
"testing"
+ "time"
"github.com/GoogleCloudPlatform/golang-samples/internal/testutil"
)
@@ -27,8 +28,9 @@ func TestMain(t *testing.T) {
tc := testutil.SystemTest(t)
os.Setenv("GOOGLE_CLOUD_PROJECT", tc.ProjectID)
+ testutil.Retry(t, 5, 5*time.Second, func(r *testutil.R) {
oldStdout := os.Stdout
- r, w, _ := os.Pipe()
+ re, w, _ := os.Pipe()
os.Stdout = w
main()
@@ -36,11 +38,13 @@ func TestMain(t *testing.T) {
w.Close()
os.Stdout = oldStdout
- out, err := ioutil.ReadAll(r)
+ out, err := ioutil.ReadAll(re)
if err != nil {
- t.Fatalf("Failed to read stdout: %v", err)
+ r.Errorf("Failed to read stdout: %v", err)
+ return
}
if got, want := string(out), "asset"; !strings.Contains(got, want) && len(got) > 0 {
- t.Errorf("stdout returned %s, wanted either empty or contain %s", got, want)
+ r.Errorf("stdout returned %s, wanted either empty or contain %s", got, want)
}
+ })
}
