github.com/jerryclinesmith/packer@v0.3.7/packer/multi_error_test.go (about)

     1  package packer
     2  
     3  import (
     4  	"cgl.tideland.biz/asserts"
     5  	"errors"
     6  	"testing"
     7  )
     8  
     9  func TestMultiError_Impl(t *testing.T) {
    10  	var raw interface{}
    11  	raw = &MultiError{}
    12  	if _, ok := raw.(error); !ok {
    13  		t.Fatal("MultiError must implement error")
    14  	}
    15  }
    16  
    17  func TestMultiErrorError(t *testing.T) {
    18  	assert := asserts.NewTestingAsserts(t, true)
    19  
    20  	expected := `2 error(s) occurred:
    21  
    22  * foo
    23  * bar`
    24  
    25  	errors := []error{
    26  		errors.New("foo"),
    27  		errors.New("bar"),
    28  	}
    29  
    30  	multi := &MultiError{errors}
    31  	assert.Equal(multi.Error(), expected, "should have proper error")
    32  }
    33  
    34  func TestMultiErrorAppend_MultiError(t *testing.T) {
    35  	original := &MultiError{
    36  		Errors: []error{errors.New("foo")},
    37  	}
    38  
    39  	result := MultiErrorAppend(original, errors.New("bar"))
    40  	if len(result.Errors) != 2 {
    41  		t.Fatalf("wrong len: %d", len(result.Errors))
    42  	}
    43  
    44  	original = &MultiError{}
    45  	result = MultiErrorAppend(original, errors.New("bar"))
    46  	if len(result.Errors) != 1 {
    47  		t.Fatalf("wrong len: %d", len(result.Errors))
    48  	}
    49  }
    50  
    51  func TestMultiErrorAppend_NonMultiError(t *testing.T) {
    52  	original := errors.New("foo")
    53  	result := MultiErrorAppend(original, errors.New("bar"))
    54  	if len(result.Errors) != 2 {
    55  		t.Fatalf("wrong len: %d", len(result.Errors))
    56  	}
    57  }