github.com/prebid/prebid-server/v2@v2.18.0/errortypes/aggregate_test.go (about)

     1  package errortypes
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestAggregateError(t *testing.T) {
    11  	var testCases = []struct {
    12  		description string
    13  		message     string
    14  		errors      []error
    15  		expected    string
    16  	}{
    17  		{
    18  			description: "None",
    19  			message:     "anyMessage",
    20  			errors:      []error{},
    21  			expected:    "",
    22  		},
    23  		{
    24  			description: "One",
    25  			message:     "anyMessage",
    26  			errors:      []error{errors.New("err1")},
    27  			expected:    "anyMessage (1 error):\n  1: err1\n",
    28  		},
    29  		{
    30  			description: "Many",
    31  			message:     "anyMessage",
    32  			errors:      []error{errors.New("err1"), errors.New("err2")},
    33  			expected:    "anyMessage (2 errors):\n  1: err1\n  2: err2\n",
    34  		},
    35  	}
    36  
    37  	for _, test := range testCases {
    38  		err := NewAggregateError(test.message, test.errors)
    39  		assert.Equal(t, test.expected, err.Error(), test.description)
    40  	}
    41  }