mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix: Standardize and wrap example descriptions at 80 chars (#2894)
This commit is contained in:
committed by
GitHub
parent
50e8a27d04
commit
749694b7de
66
cli/root_internal_test.go
Normal file
66
cli/root_internal_test.go
Normal file
@ -0,0 +1,66 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user