go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/utils/multierr/errors_test.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package multierr_test
     5  
     6  import (
     7  	"errors"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  	"go.mondoo.com/cnquery/utils/multierr"
    12  )
    13  
    14  func TestMultiErr(t *testing.T) {
    15  	t.Run("add nil errors", func(t *testing.T) {
    16  		var e multierr.Errors
    17  		e.Add(nil)
    18  		e.Add(nil, nil, nil)
    19  		assert.Nil(t, e.Deduplicate())
    20  	})
    21  
    22  	t.Run("add mixed errors", func(t *testing.T) {
    23  		var e multierr.Errors
    24  		e.Add(errors.New("1"), nil, errors.New("1"))
    25  		var b multierr.Errors
    26  		b.Add(errors.New("1"))
    27  		assert.Equal(t, b.Deduplicate(), e.Deduplicate())
    28  	})
    29  }