test(dlp): add retries
Fixes
@@ -19,6 +19,7 @@ import (
"context"
"strings"
"testing"
+ "time"
"cloud.google.com/go/bigquery"
"cloud.google.com/go/datastore"
@@ -50,15 +51,18 @@ func TestInspectDatastore(t *testing.T) {
for _, test := range tests {
t.Run(test.kind, func(t *testing.T) {
t.Parallel()
+ testutil.Retry(t, 5, 15*time.Second, func(r *testutil.R) {
u := uuid.Must(uuid.NewV4()).String()[:8]
buf := new(bytes.Buffer)
if err := inspectDatastore(buf, tc.ProjectID, []string{"US_SOCIAL_SECURITY_NUMBER"}, []string{}, []string{}, topicName+u, subscriptionName+u, tc.ProjectID, "", test.kind); err != nil {
- t.Errorf("inspectDatastore(%s) got err: %v", test.kind, err)
+ r.Errorf("inspectDatastore(%s) got err: %v", test.kind, err)
+ return
}
if got := buf.String(); !strings.Contains(got, test.want) {
- t.Errorf("inspectDatastore(%s) = %q, want %q substring", test.kind, got, test.want)
+ r.Errorf("inspectDatastore(%s) = %q, want %q substring", test.kind, got, test.want)
}
})
+ })
}
}
@@ -66,10 +70,6 @@ type SSNTask struct {
Description string
}
-type BoringTask struct {
- Description string
-}
-
func writeTestDatastoreFiles(t *testing.T, projectID string) {
t.Helper()
ctx := context.Background()
@@ -103,15 +103,18 @@ func TestInspectGCS(t *testing.T) {
for _, test := range tests {
t.Run(test.fileName, func(t *testing.T) {
t.Parallel()
+ testutil.Retry(t, 5, 15*time.Second, func(r *testutil.R) {
u := uuid.Must(uuid.NewV4()).String()[:8]
buf := new(bytes.Buffer)
if err := inspectGCSFile(buf, tc.ProjectID, []string{"US_SOCIAL_SECURITY_NUMBER"}, []string{}, []string{}, topicName+u, subscriptionName+u, bucketName, test.fileName); err != nil {
- t.Errorf("inspectGCSFile(%s) got err: %v", test.fileName, err)
+ r.Errorf("inspectGCSFile(%s) got err: %v", test.fileName, err)
+ return
}
if got := buf.String(); !strings.Contains(got, test.want) {
- t.Errorf("inspectGCSFile(%s) = %q, want %q substring", test.fileName, got, test.want)
+ r.Errorf("inspectGCSFile(%s) = %q, want %q substring", test.fileName, got, test.want)
}
})
+ })
}
}
