Skip to content

fix: Standardize and wrap example descriptions at 80 chars #2894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add tests for formatExamples
  • Loading branch information
mafredri committed Jul 11, 2022
commit 7e6b3b4ca6a52d447fd8413f075f0cbd5877b234
66 changes: 66 additions & 0 deletions cli/root_internal_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
})
}
}
3 changes: 1 addition & 2 deletions cli/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"bytes"
"testing"

"github.com/coder/coder/buildinfo"

"github.com/stretchr/testify/require"

"github.com/coder/coder/buildinfo"
"github.com/coder/coder/cli"
"github.com/coder/coder/cli/clitest"
)
Expand Down