MCPcopy Index your code
hub / github.com/coder/coder / Test_formatExamples

Function Test_formatExamples

cli/root_internal_test.go:37–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func Test_formatExamples(t *testing.T) {
38 t.Parallel()
39
40 tests := []struct {
41 name string
42 examples []Example
43 wantMatches []string
44 }{
45 {
46 name: "No examples",
47 examples: nil,
48 wantMatches: nil,
49 },
50 {
51 name: "Output examples",
52 examples: []Example{
53 {
54 Description: "Hello world.",
55 Command: "echo hello",
56 },
57 {
58 Description: "Bye bye.",
59 Command: "echo bye",
60 },
61 },
62 wantMatches: []string{
63 "Hello world", "echo hello",
64 "Bye bye", "echo bye",
65 },
66 },
67 {
68 name: "No description outputs commands",
69 examples: []Example{
70 {
71 Command: "echo hello",
72 },
73 },
74 wantMatches: []string{
75 "echo hello",
76 },
77 },
78 }
79 for _, tt := range tests {
80 t.Run(tt.name, func(t *testing.T) {
81 t.Parallel()
82
83 got := FormatExamples(tt.examples...)
84 if len(tt.wantMatches) == 0 {
85 require.Empty(t, got)
86 } else {
87 for _, want := range tt.wantMatches {
88 require.Contains(t, got, want)
89 }
90 }
91 })
92 }
93}
94

Callers

nothing calls this directly

Calls 4

FormatExamplesFunction · 0.85
RunMethod · 0.65
EmptyMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected