vision/product_set: add retries to remove test
@@ -18,6 +18,7 @@ import (
"bytes"
"strings"
"testing"
+ "time"
"github.com/GoogleCloudPlatform/golang-samples/internal/testutil"
)
@@ -32,6 +33,7 @@ func TestRemoveProductFromProductSet(t *testing.T) {
const productCategory = "homegoods"
const productID = "fake_product_id_for_testing"
+ testutil.Retry(t, 5, 10*time.Second, func(r *testutil.R) {
var buf bytes.Buffer
// Ensure re-used resource names don't exist prior to test start.
@@ -45,41 +47,48 @@ func TestRemoveProductFromProductSet(t *testing.T) {
// Create fake product set and product.
if err := createProductSet(&buf, tc.ProjectID, location, productSetID, productSetDisplayName); err != nil {
- t.Fatalf("createProductSet: %v", err)
+ r.Errorf("createProductSet: %v", err)
+ return
}
if err := createProduct(&buf, tc.ProjectID, location, productID, productDisplayName, productCategory); err != nil {
- t.Fatalf("createProduct: %v", err)
+ r.Errorf("createProduct: %v", err)
+ return
}
// Add product to product set
if err := addProductToProductSet(&buf, tc.ProjectID, location, productID, productSetID); err != nil {
- t.Fatalf("addProductToProductSet: %v", err)
+ r.Errorf("addProductToProductSet: %v", err)
+ return
}
// Confirm that the product is in the product set now.
buf.Reset()
if err := listProductsInProductSet(&buf, tc.ProjectID, location, productSetID); err != nil {
- t.Fatalf("listProductsInProductSet: %v", err)
+ r.Errorf("listProductsInProductSet: %v", err)
+ return
}
if got := buf.String(); !strings.Contains(got, productID) {
- t.Errorf("Product ID %s is not in product set", productID)
+ r.Errorf("Product ID %s is not in product set", productID)
}
// Remove product from product set.
if err := removeProductFromProductSet(&buf, tc.ProjectID, location, productID, productSetID); err != nil {
- t.Fatalf("removeProductFromProductSet: %v", err)
+ r.Errorf("removeProductFromProductSet: %v", err)
+ return
}
// Check that the product is not in the product set now.
buf.Reset()
if err := listProductsInProductSet(&buf, tc.ProjectID, location, productSetID); err != nil {
- t.Fatalf("listProductsInProductSet: %v", err)
+ r.Errorf("listProductsInProductSet: %v", err)
+ return
}
if got := buf.String(); strings.Contains(got, productID) {
- t.Errorf("Product ID %s still in product set", productID)
+ r.Errorf("Product ID %s still in product set", productID)
}
// Clean up.
deleteProduct(&buf, tc.ProjectID, location, productID)
deleteProductSet(&buf, tc.ProjectID, location, productSetID)
+ })
}
