소스 검색

Add slice cast test

Matt Bolt 5 년 전
부모
커밋
5182c95040
1개의 변경된 파일33개의 추가작업 그리고 0개의 파일을 삭제
  1. 33 0
      pkg/util/retry/retry_test.go

+ 33 - 0
pkg/util/retry/retry_test.go

@@ -8,6 +8,39 @@ import (
 	"time"
 )
 
+type Obj struct {
+	Name string
+}
+
+func TestPtrSliceRetry(t *testing.T) {
+	const Expected uint64 = 3
+
+	var count uint64 = 0
+
+	f := func() (interface{}, error) {
+		c := atomic.AddUint64(&count, 1)
+		fmt.Println("Try:", c)
+
+		if c == Expected {
+			return []*Obj{
+				{"A"},
+				{"B"},
+				{"C"},
+			}, nil
+		}
+
+		return nil, fmt.Errorf("Failed: %d", c)
+	}
+
+	result, err := Retry(context.Background(), f, 5, time.Second)
+	objs, ok := result.([]*Obj)
+	if err != nil || !ok {
+		t.Fatalf("Failed to correctly cast back to slice type")
+	}
+
+	t.Logf("Length: %d\n", len(objs))
+}
+
 func TestSuccessRetry(t *testing.T) {
 	const Expected uint64 = 3