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

     1  // Copyright 2020 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 multi_test
     6  
     7  import (
     8  	"errors"
     9  	"fmt"
    10  	"testing"
    11  
    12  	"github.com/searKing/golang/go/error/multi"
    13  )
    14  
    15  func TestNew(t *testing.T) {
    16  	tests := []struct {
    17  		errs []error
    18  		want error
    19  	}{
    20  		{nil, nil},
    21  		{[]error{}, nil},
    22  		{[]error{fmt.Errorf("foo")}, fmt.Errorf("foo")},
    23  		{[]error{fmt.Errorf("foo"), fmt.Errorf("fun")}, multi.New(fmt.Errorf("foo"), fmt.Errorf("fun"))},
    24  	}
    25  
    26  	for _, tt := range tests {
    27  		got := multi.New(tt.errs...)
    28  		if errors.Is(got, tt.want) {
    29  			continue
    30  		}
    31  		if got == nil || tt.want == nil || got.Error() != tt.want.Error() {
    32  			t.Errorf("New.Error(): got: %q, want %q", got, tt.want)
    33  		}
    34  	}
    35  }