github.com/cobalt77/jfrog-client-go@v0.14.5/utils/retryexecutor_test.go (about) 1 package utils 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/cobalt77/jfrog-client-go/utils/log" 8 ) 9 10 func TestRetryExecutorSuccess(t *testing.T) { 11 retriesToPerform := 10 12 breakRetriesAt := 4 13 runCount := 0 14 15 executor := RetryExecutor{ 16 MaxRetries: retriesToPerform, 17 RetriesInterval: 0, 18 ErrorMessage: "Testing RetryExecutor", 19 ExecutionHandler: func() (bool, error) { 20 runCount++ 21 if runCount == breakRetriesAt { 22 log.Warn("Breaking after", runCount-1, "retries") 23 return false, nil 24 } 25 return true, nil 26 }, 27 } 28 29 executor.Execute() 30 if runCount != breakRetriesAt { 31 t.Error(fmt.Errorf("expected, %d, got: %d", breakRetriesAt, runCount)) 32 } 33 } 34 35 func TestRetryExecutorFail(t *testing.T) { 36 retriesToPerform := 5 37 runCount := 0 38 39 executor := RetryExecutor{ 40 MaxRetries: retriesToPerform, 41 RetriesInterval: 0, 42 ErrorMessage: "Testing RetryExecutor", 43 ExecutionHandler: func() (bool, error) { 44 runCount++ 45 return true, nil 46 }, 47 } 48 49 executor.Execute() 50 if runCount != retriesToPerform+1 { 51 t.Error(fmt.Errorf("expected, %d, got: %d", retriesToPerform, runCount)) 52 } 53 }