github.com/verrazzano/verrazzano@v1.7.0/cluster-operator/internal/errors/errors_test.go (about)

     1  // Copyright (c) 2023, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  package errors
     5  
     6  import (
     7  	"errors"
     8  	"fmt"
     9  	"github.com/stretchr/testify/assert"
    10  	"testing"
    11  )
    12  
    13  func TestErrorAggregator(t *testing.T) {
    14  	const (
    15  		e1 = "boom!"
    16  		e2 = "kaboom!"
    17  	)
    18  	e := NewAggregator(";")
    19  	assert.False(t, e.HasError())
    20  	e.Add(errors.New(e1))
    21  	assert.True(t, e.HasError())
    22  	assert.Equal(t, e1, e.Error())
    23  	e.Addf("warning: %s", e2)
    24  	assert.True(t, e.HasError())
    25  	assert.Equal(t, fmt.Sprintf("%s;warning: %s", e1, e2), e.Error())
    26  }