mirror of
https://github.com/docker/cli.git
synced 2026-08-26 10:05:28 -05:00
- skip aec to construct the formatting and use a const instead - skip fmt.Println and write directly to the writer - move newlines outside of the "bold" formatting Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
46 lines
862 B
Go
46 lines
862 B
Go
package hooks_test
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/docker/cli/cli-plugins/hooks"
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestPrintHookMessages(t *testing.T) {
|
|
const header = "\n\x1b[1mWhat's next:\x1b[0m\n"
|
|
|
|
tests := []struct {
|
|
doc string
|
|
messages []string
|
|
expectedOutput string
|
|
}{
|
|
{
|
|
doc: "no messages",
|
|
messages: nil,
|
|
expectedOutput: "",
|
|
},
|
|
{
|
|
doc: "single message",
|
|
messages: []string{"Bork!"},
|
|
expectedOutput: header +
|
|
" Bork!\n",
|
|
},
|
|
{
|
|
doc: "multiple messages",
|
|
messages: []string{"Foo", "bar"},
|
|
expectedOutput: header +
|
|
" Foo\n" +
|
|
" bar\n",
|
|
},
|
|
}
|
|
for _, tc := range tests {
|
|
t.Run(tc.doc, func(t *testing.T) {
|
|
var w strings.Builder
|
|
hooks.PrintNextSteps(&w, tc.messages)
|
|
assert.Equal(t, w.String(), tc.expectedOutput)
|
|
})
|
|
}
|
|
}
|