MCPcopy Index your code
hub / github.com/riverqueue/river / TestBaseCommandSetIntegration

Function TestBaseCommandSetIntegration

cmd/river/rivercli/river_cli_test.go:124–234  ·  view source on GitHub ↗

High level integration tests that operate on the Cobra command directly. This isn't always appropriate because there's no way to inject a test transaction.

(t *testing.T)

Source from the content-addressed store, hash-verified

122// High level integration tests that operate on the Cobra command directly. This
123// isn't always appropriate because there's no way to inject a test transaction.
124func TestBaseCommandSetIntegration(t *testing.T) {
125 t.Parallel()
126
127 type testBundle struct {
128 out *bytes.Buffer
129 }
130
131 setup := func(t *testing.T) (*cobra.Command, *testBundle) {
132 t.Helper()
133
134 cli := NewCLI(&Config{
135 Name: "River",
136 })
137
138 var out bytes.Buffer
139 cli.SetOut(&out)
140
141 return cli.BaseCommandSet(), &testBundle{
142 out: &out,
143 }
144 }
145
146 t.Run("DebugVerboseMutuallyExclusive", func(t *testing.T) {
147 t.Parallel()
148
149 cmd, _ := setup(t)
150
151 cmd.SetArgs([]string{"--debug", "--verbose"})
152 require.EqualError(t, cmd.Execute(), "if any flags in the group [debug verbose] are set none of the others can be; [debug verbose] were all set")
153 })
154
155 t.Run("DatabaseURLWithInvalidPrefix", func(t *testing.T) {
156 t.Parallel()
157
158 cmd, _ := setup(t)
159
160 cmd.SetArgs([]string{"migrate-down", "--database-url", "post://"})
161 require.EqualError(t, cmd.Execute(), "unsupported database URL (`post://`); try one with a `postgres://`, `postgresql://`, or `sqlite://` scheme/prefix")
162 })
163
164 t.Run("MissingDatabaseURLAndPGEnv", func(t *testing.T) {
165 t.Parallel()
166
167 cmd, _ := setup(t)
168
169 cmd.SetArgs([]string{"migrate-down"})
170 require.EqualError(t, cmd.Execute(), "either PG* env vars or --database-url must be set")
171 })
172
173 t.Run("StatementTimeoutValidation", func(t *testing.T) {
174 t.Parallel()
175
176 t.Run("AllowsGreaterThanOneMillisecond", func(t *testing.T) {
177 t.Parallel()
178
179 cmd, _ := setup(t)
180 cmd.SetArgs([]string{"--statement-timeout", "2ms", "--version"})
181 require.NoError(t, cmd.Execute())

Callers

nothing calls this directly

Calls 6

SetOutMethod · 0.95
BaseCommandSetMethod · 0.95
NewCLIFunction · 0.85
ExecuteMethod · 0.80
HelperMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…