mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
67 lines
1.1 KiB
Go
67 lines
1.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func Test_formatExamples(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
examples []example
|
|
wantMatches []string
|
|
}{
|
|
{
|
|
name: "No examples",
|
|
examples: nil,
|
|
wantMatches: nil,
|
|
},
|
|
{
|
|
name: "Output examples",
|
|
examples: []example{
|
|
{
|
|
Description: "Hello world",
|
|
Command: "echo hello",
|
|
},
|
|
{
|
|
Description: "Bye bye",
|
|
Command: "echo bye",
|
|
},
|
|
},
|
|
wantMatches: []string{
|
|
"Hello world", "echo hello",
|
|
"Bye bye", "echo bye",
|
|
},
|
|
},
|
|
{
|
|
name: "No description outputs commands",
|
|
examples: []example{
|
|
{
|
|
Command: "echo hello",
|
|
},
|
|
},
|
|
wantMatches: []string{
|
|
"echo hello",
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got := formatExamples(tt.examples...)
|
|
if len(tt.wantMatches) == 0 {
|
|
require.Empty(t, got)
|
|
} else {
|
|
for _, want := range tt.wantMatches {
|
|
require.Contains(t, got, want)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|