github.com/searKing/golang/go@v1.2.117/errors/multi_test.go (about)

     1  // Copyright 2023 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package errors_test
     6  
     7  import (
     8  	"errors"
     9  	"testing"
    10  
    11  	errors_ "github.com/searKing/golang/go/errors"
    12  )
    13  
    14  func TestMultiReturnsNil(t *testing.T) {
    15  	if err := errors_.Multi(); err != nil {
    16  		t.Errorf("errors_.Multi() = %v, want nil", err)
    17  	}
    18  	if err := errors_.Multi(nil); err != nil {
    19  		t.Errorf("errors_.Multi(nil) = %v, want nil", err)
    20  	}
    21  	if err := errors_.Multi(nil, nil); err != nil {
    22  		t.Errorf("errors_.Multi(nil, nil) = %v, want nil", err)
    23  	}
    24  }
    25  
    26  func TestMultiErrorMethod(t *testing.T) {
    27  	err1 := errors.New("err1")
    28  	err2 := errors.New("err2")
    29  	for _, test := range []struct {
    30  		errs []error
    31  		want string
    32  	}{{
    33  		errs: []error{err1},
    34  		want: "err1",
    35  	}, {
    36  		errs: []error{err1, err2},
    37  		want: "err1\nerr2",
    38  	}, {
    39  		errs: []error{err1, nil, err2},
    40  		want: "err1\nerr2",
    41  	}} {
    42  		got := errors_.Multi(test.errs...).Error()
    43  		if got != test.want {
    44  			t.Errorf("Multi(%v).Error() = %q; want %q", test.errs, got, test.want)
    45  		}
    46  	}
    47  }