forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_operation_test.go
67 lines (56 loc) · 1.24 KB
/
common_operation_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package google
import (
"net/url"
"testing"
"time"
)
type TestWaiter struct {
runCount int
}
func (w *TestWaiter) State() string {
if w.runCount == 2 {
return "DONE"
}
return "RUNNING"
}
func (TestWaiter) IsRetryable(err error) bool {
return false
}
func (TestWaiter) Error() error {
return nil
}
func (TestWaiter) SetOp(interface{}) error {
return nil
}
func (w *TestWaiter) QueryOp() (interface{}, error) {
w.runCount++
if w.runCount == 1 {
return nil, &url.Error{
Err: &TimeoutError{timeout: true},
}
}
return "my return value", nil
}
func (TestWaiter) OpName() string {
return "my-operation-name"
}
func (TestWaiter) PendingStates() []string {
return []string{}
}
func (TestWaiter) TargetStates() []string {
return []string{"DONE"}
}
func TestOperationWait_TimeoutsShouldRetry(t *testing.T) {
testWaiter := TestWaiter{
runCount: 0,
}
err := OperationWait(&testWaiter, "my-activity", 1*time.Minute, 0*time.Second)
if err != nil {
t.Fatalf("unexpected error waiting for operation: got '%v', want 'nil'", err)
}
expectedRunCount := 2
if testWaiter.runCount != expectedRunCount {
t.Errorf("expected the retryFunc to be called %v time(s), instead was called %v time(s)",
expectedRunCount, testWaiter.runCount)
}
}