github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/packer/multi_error_test.go (about) 1 package packer 2 3 import ( 4 "errors" 5 "testing" 6 ) 7 8 func TestMultiError_Impl(t *testing.T) { 9 var raw interface{} 10 raw = &MultiError{} 11 if _, ok := raw.(error); !ok { 12 t.Fatal("MultiError must implement error") 13 } 14 } 15 16 func TestMultiErrorError(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 := &MultiError{errors} 28 if multi.Error() != expected { 29 t.Fatalf("bad: %s", multi.Error()) 30 } 31 } 32 33 func TestMultiErrorAppend_MultiError(t *testing.T) { 34 original := &MultiError{ 35 Errors: []error{errors.New("foo")}, 36 } 37 38 result := MultiErrorAppend(original, errors.New("bar")) 39 if len(result.Errors) != 2 { 40 t.Fatalf("wrong len: %d", len(result.Errors)) 41 } 42 43 original = &MultiError{} 44 result = MultiErrorAppend(original, errors.New("bar")) 45 if len(result.Errors) != 1 { 46 t.Fatalf("wrong len: %d", len(result.Errors)) 47 } 48 } 49 50 func TestMultiErrorAppend_NonMultiError(t *testing.T) { 51 original := errors.New("foo") 52 result := MultiErrorAppend(original, errors.New("bar")) 53 if len(result.Errors) != 2 { 54 t.Fatalf("wrong len: %d", len(result.Errors)) 55 } 56 }