github.com/adamar/terraform@v0.2.2-0.20141016210445-2e703afdad0e/helper/resource/wait_test.go (about)

     1  package resource
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  )
     8  
     9  func TestRetry(t *testing.T) {
    10  	t.Parallel()
    11  
    12  	tries := 0
    13  	f := func() error {
    14  		tries++
    15  		if tries == 1 {
    16  			return nil
    17  		}
    18  
    19  		return fmt.Errorf("error")
    20  	}
    21  
    22  	err := Retry(2*time.Second, f)
    23  	if err != nil {
    24  		t.Fatalf("err: %s", err)
    25  	}
    26  }
    27  
    28  func TestRetry_timeout(t *testing.T) {
    29  	t.Parallel()
    30  
    31  	f := func() error {
    32  		return fmt.Errorf("always")
    33  	}
    34  
    35  	err := Retry(1*time.Second, f)
    36  	if err == nil {
    37  		t.Fatal("should error")
    38  	}
    39  }