open-nomad/helper/warning_test.go
2023-04-10 15:36:59 +00:00

58 lines
904 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package helper
import (
"errors"
"strings"
"testing"
"github.com/hashicorp/nomad/ci"
"github.com/shoenig/test/must"
)
func TestMergeMultierrorWarnings(t *testing.T) {
ci.Parallel(t)
testCases := []struct {
name string
errs []error
expected string
}{
{
name: "no warning",
errs: []error{},
expected: "",
},
{
name: "single warning",
errs: []error{
errors.New("warning"),
},
expected: `
1 warning:
* warning`,
},
{
name: "multiple warnings",
errs: []error{
errors.New("warning 1"),
errors.New("warning 2"),
},
expected: `
2 warnings:
* warning 1
* warning 2`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := MergeMultierrorWarnings(tc.errs...)
must.Eq(t, got, strings.TrimSpace(tc.expected))
})
}
}