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

     1  package multierror
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  )
     7  
     8  func TestError_Impl(t *testing.T) {
     9  	var raw interface{}
    10  	raw = &Error{}
    11  	if _, ok := raw.(error); !ok {
    12  		t.Fatal("Error must implement error")
    13  	}
    14  }
    15  
    16  func TestErrorError(t *testing.T) {
    17  	expected := `2 error(s) occurred:
    18  
    19  * foo
    20  * bar`
    21  
    22  	errors := []error{
    23  		errors.New("foo"),
    24  		errors.New("bar"),
    25  	}
    26  
    27  	multi := &Error{errors}
    28  	if multi.Error() != expected {
    29  		t.Fatalf("bad: %s", multi.Error())
    30  	}
    31  }
    32  
    33  func TestErrorAppend_Error(t *testing.T) {
    34  	original := &Error{
    35  		Errors: []error{errors.New("foo")},
    36  	}
    37  
    38  	result := ErrorAppend(original, errors.New("bar"))
    39  	if len(result.Errors) != 2 {
    40  		t.Fatalf("wrong len: %d", len(result.Errors))
    41  	}
    42  
    43  	original = &Error{}
    44  	result = ErrorAppend(original, errors.New("bar"))
    45  	if len(result.Errors) != 1 {
    46  		t.Fatalf("wrong len: %d", len(result.Errors))
    47  	}
    48  }
    49  
    50  func TestErrorAppend_NonError(t *testing.T) {
    51  	original := errors.New("foo")
    52  	result := ErrorAppend(original, errors.New("bar"))
    53  	if len(result.Errors) != 2 {
    54  		t.Fatalf("wrong len: %d", len(result.Errors))
    55  	}
    56  }