1
// Copyright Istio Authors
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
23
testErrs = Errors{fmt.Errorf("err1"), fmt.Errorf("err2")}
24
wantStr = "err1, err2"
27
func TestError(t *testing.T) {
28
if got, want := testErrs.Error(), wantStr; got != want {
29
t.Errorf("got: %s, want: %s", got, want)
33
func TestString(t *testing.T) {
34
if got, want := testErrs.String(), wantStr; got != want {
35
t.Errorf("got: %s, want: %s", got, want)
39
func TestToString(t *testing.T) {
40
if got, want := ToString(testErrs, defaultSeparator), wantStr; got != want {
41
t.Errorf("got: %s, want: %s", got, want)
45
func TestNewErrs(t *testing.T) {
48
t.Errorf("got: %s, want: nil", errs)
51
errs = NewErrs(fmt.Errorf("err1"))
52
if got, want := errs.String(), "err1"; got != want {
53
t.Errorf("got: %s, want: %s", got, want)
57
func TestAppendErr(t *testing.T) {
59
if got, want := errs.String(), ""; got != want {
60
t.Errorf("got: %s, want: %s", got, want)
63
errs = AppendErr(errs, nil)
64
if got, want := errs.String(), ""; got != want {
65
t.Errorf("got: %s, want: %s", got, want)
68
errs = AppendErr(errs, fmt.Errorf("err1"))
69
if got, want := errs.String(), "err1"; got != want {
70
t.Errorf("got: %s, want: %s", got, want)
73
errs = AppendErr(errs, nil)
74
errs = AppendErr(errs, fmt.Errorf("err2"))
75
if got, want := errs.String(), "err1, err2"; got != want {
76
t.Errorf("got: %s, want: %s", got, want)
80
func TestAppendErrs(t *testing.T) {
83
errs = AppendErrs(errs, []error{nil})
84
if got, want := errs.String(), ""; got != want {
85
t.Errorf("got: %s, want: %s", got, want)
88
errs = AppendErrs(errs, testErrs)
89
errs = AppendErrs(errs, []error{nil})
90
if got, want := errs.String(), wantStr; got != want {
91
t.Errorf("got: %s, want: %s", got, want)
95
func TestAppendErrsInFunction(t *testing.T) {
96
myAppendErrFunc := func() (errs Errors) {
97
errs = AppendErr(errs, fmt.Errorf("err1"))
98
errs = AppendErr(errs, fmt.Errorf("err2"))
101
if got, want := myAppendErrFunc().String(), wantStr; got != want {
102
t.Errorf("got: %s, want: %s", got, want)
105
myAppendErrsFunc := func() (errs Errors) {
106
errs = AppendErrs(errs, testErrs)
109
if got, want := myAppendErrsFunc().String(), wantStr; got != want {
110
t.Errorf("got: %s, want: %s", got, want)
113
myErrorSliceFunc := func() (errs []error) {
114
errs = AppendErrs(errs, testErrs)
118
if got, want := Errors(myErrorSliceFunc()).String(), wantStr; got != want {
119
t.Errorf("got: %s, want: %s", got, want)