...

Source file src/go.uber.org/multierr/error_post_go120_test.go

Documentation: go.uber.org/multierr

     1  // Copyright (c) 2023 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  //go:build go1.20
    22  // +build go1.20
    23  
    24  package multierr
    25  
    26  import (
    27  	"errors"
    28  	"testing"
    29  
    30  	"github.com/stretchr/testify/assert"
    31  )
    32  
    33  func TestErrorsOnErrorsJoin(t *testing.T) {
    34  	err1 := errors.New("err1")
    35  	err2 := errors.New("err2")
    36  	err := errors.Join(err1, err2)
    37  
    38  	errs := Errors(err)
    39  	assert.Equal(t, 2, len(errs))
    40  	assert.Equal(t, err1, errs[0])
    41  	assert.Equal(t, err2, errs[1])
    42  }
    43  
    44  func TestEveryWithErrorsJoin(t *testing.T) {
    45  	myError1 := errors.New("woeful misfortune")
    46  	myError2 := errors.New("worrisome travesty")
    47  
    48  	t.Run("all match", func(t *testing.T) {
    49  		err := errors.Join(myError1, myError1, myError1)
    50  
    51  		assert.True(t, errors.Is(err, myError1))
    52  		assert.True(t, Every(err, myError1))
    53  		assert.False(t, errors.Is(err, myError2))
    54  		assert.False(t, Every(err, myError2))
    55  	})
    56  
    57  	t.Run("one matches", func(t *testing.T) {
    58  		err := errors.Join(myError1, myError2)
    59  
    60  		assert.True(t, errors.Is(err, myError1))
    61  		assert.False(t, Every(err, myError1))
    62  		assert.True(t, errors.Is(err, myError2))
    63  		assert.False(t, Every(err, myError2))
    64  	})
    65  }
    66  

View as plain text