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

Function TestRoot

cli/root_test.go:104–198  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

102}
103
104func TestRoot(t *testing.T) {
105 t.Parallel()
106 t.Run("MissingRootCommand", func(t *testing.T) {
107 t.Parallel()
108
109 out := new(bytes.Buffer)
110
111 inv, _ := clitest.New(t, "idontexist")
112 inv.Stdout = out
113
114 err := inv.Run()
115 assert.ErrorContains(t, err,
116 `unrecognized subcommand "idontexist"`)
117 require.Empty(t, out.String())
118 })
119
120 t.Run("MissingSubcommand", func(t *testing.T) {
121 t.Parallel()
122
123 out := new(bytes.Buffer)
124
125 inv, _ := clitest.New(t, "server", "idontexist")
126 inv.Stdout = out
127
128 err := inv.Run()
129 // subcommand error only when command has subcommands
130 assert.ErrorContains(t, err,
131 `unrecognized subcommand "idontexist"`)
132 require.Empty(t, out.String())
133 })
134
135 t.Run("BadSubcommandArgs", func(t *testing.T) {
136 t.Parallel()
137
138 out := new(bytes.Buffer)
139
140 inv, _ := clitest.New(t, "list", "idontexist")
141 inv.Stdout = out
142
143 err := inv.Run()
144 assert.ErrorContains(t, err,
145 `wanted no args but got 1 [idontexist]`)
146 require.Empty(t, out.String())
147 })
148
149 t.Run("Version", func(t *testing.T) {
150 t.Parallel()
151
152 buf := new(bytes.Buffer)
153 inv, _ := clitest.New(t, "version")
154 inv.Stdout = buf
155 err := inv.Run()
156 require.NoError(t, err)
157
158 output := buf.String()
159 require.Contains(t, output, buildinfo.Version(), "has version")
160 require.Contains(t, output, buildinfo.ExternalURL(), "has url")
161 })

Callers

nothing calls this directly

Calls 14

CloseMethod · 0.95
NewFunction · 0.92
VersionFunction · 0.92
ExternalURLFunction · 0.92
RunMethod · 0.65
AddMethod · 0.65
GetMethod · 0.65
EmptyMethod · 0.45
StringMethod · 0.45
ContainsMethod · 0.45
EqualMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected