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

Function StartWithAssert

cli/clitest/clitest.go:179–213  ·  view source on GitHub ↗

StartWithAssert starts the given invocation and calls assertCallback with the resulting error when the invocation completes. If assertCallback is nil, expected shutdown errors are silently tolerated.

(t *testing.T, inv *serpent.Invocation, assertCallback func(t *testing.T, err error))

Source from the content-addressed store, hash-verified

177// with the resulting error when the invocation completes. If assertCallback
178// is nil, expected shutdown errors are silently tolerated.
179func StartWithAssert(t *testing.T, inv *serpent.Invocation, assertCallback func(t *testing.T, err error)) {
180 t.Helper()
181
182 closeCh := make(chan struct{})
183 // StartWithWaiter adds its own `t.Cleanup`, so we need to be sure it's added
184 // before ours.
185 waiter := StartWithWaiter(t, inv)
186 t.Cleanup(func() {
187 waiter.Cancel()
188 <-closeCh
189 })
190
191 go func() {
192 defer close(closeCh)
193 err := waiter.Wait()
194
195 if assertCallback != nil {
196 assertCallback(t, err)
197 return
198 }
199
200 switch {
201 case errors.Is(err, context.Canceled):
202 return
203 case err != nil && strings.Contains(err.Error(), "driver: bad connection"):
204 // When we cancel the context on a query that's being executed within
205 // a transaction, sometimes, instead of a context.Canceled error we get
206 // a "driver: bad connection" error.
207 // https://github.com/lib/pq/issues/1137
208 return
209 default:
210 assert.NoError(t, err)
211 }
212 }()
213}
214
215// Run runs the command and asserts that there is no error.
216func Run(t *testing.T, inv *serpent.Invocation) {

Callers 3

StartFunction · 0.85

Calls 8

StartWithWaiterFunction · 0.85
HelperMethod · 0.65
CleanupMethod · 0.65
WaitMethod · 0.65
CancelMethod · 0.45
IsMethod · 0.45
ContainsMethod · 0.45
ErrorMethod · 0.45