terraform/helper/multierror/error_test.go

57 lines
1.0 KiB
Go
Raw Normal View History

2014-07-03 19:14:17 +02:00
package multierror
import (
"errors"
"testing"
)
2014-07-03 19:14:17 +02:00
func TestError_Impl(t *testing.T) {
var raw interface{}
2014-07-03 19:14:17 +02:00
raw = &Error{}
if _, ok := raw.(error); !ok {
2014-07-03 19:14:17 +02:00
t.Fatal("Error must implement error")
}
}
2014-07-03 19:14:17 +02:00
func TestErrorError(t *testing.T) {
expected := `2 error(s) occurred:
* foo
* bar`
errors := []error{
errors.New("foo"),
errors.New("bar"),
}
2014-07-03 19:14:17 +02:00
multi := &Error{errors}
if multi.Error() != expected {
t.Fatalf("bad: %s", multi.Error())
}
}
2014-07-03 19:14:17 +02:00
func TestErrorAppend_Error(t *testing.T) {
original := &Error{
Errors: []error{errors.New("foo")},
}
2014-07-03 19:14:17 +02:00
result := ErrorAppend(original, errors.New("bar"))
if len(result.Errors) != 2 {
t.Fatalf("wrong len: %d", len(result.Errors))
}
2014-07-03 19:14:17 +02:00
original = &Error{}
result = ErrorAppend(original, errors.New("bar"))
if len(result.Errors) != 1 {
t.Fatalf("wrong len: %d", len(result.Errors))
}
}
2014-07-03 19:14:17 +02:00
func TestErrorAppend_NonError(t *testing.T) {
original := errors.New("foo")
2014-07-03 19:14:17 +02:00
result := ErrorAppend(original, errors.New("bar"))
if len(result.Errors) != 2 {
t.Fatalf("wrong len: %d", len(result.Errors))
}
}