1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
package config
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_ErrorList_Error_NoErrors(t *testing.T) {
// arrange
errors := &ErrorList{}
// assert
assert.EqualError(t, errors, "no errors")
}
func Test_ErrorList_Error_OneError(t *testing.T) {
// arrange
errors := &ErrorList{}
errors.add("qux", "zzz", "bean")
// assert
assert.EqualError(t, errors, "cannot set 'qux' to 'zzz': bean")
}
func Test_ErrorList_Error_TwoErrorsSorted(t *testing.T) {
// arrange
errors := &ErrorList{}
errors.add("foo", "xxx", "boom")
errors.add("bar", "yyy", "ugh")
// act
errors.sort()
// assert
assert.EqualError(t, errors, "cannot set 'bar' to 'yyy': ugh (and 1 more errors)")
}
func Test_ErrorList_Error_TwoErrorsUnsorted(t *testing.T) {
// arrange
errors := &ErrorList{}
errors.add("foo", "xxx", "boom")
errors.add("bar", "yyy", "ugh")
// assert
assert.EqualError(t, errors, "cannot set 'foo' to 'xxx': boom (and 1 more errors)")
}
func Test_ErrorList_Error_MoreThanTwoErrorsUnsorted(t *testing.T) {
// arrange
errors := &ErrorList{}
errors.add("foo", "xxx", "boom")
errors.add("bar", "yyy", "ugh")
errors.add("qux", "zzz", "bean")
// assert
assert.EqualError(t, errors, "cannot set 'foo' to 'xxx': boom (and 2 more errors)")
}
|