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

Function newProvisionerJob

cli/cliui/provisionerjob_test.go:214–263  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

212}
213
214func newProvisionerJob(t *testing.T) provisionerJobTest {
215 job := &codersdk.ProvisionerJob{
216 Status: codersdk.ProvisionerJobPending,
217 CreatedAt: dbtime.Now(),
218 }
219 jobLock := sync.Mutex{}
220 logs := make(chan codersdk.ProvisionerJobLog, 1)
221 cmd := &serpent.Command{
222 Handler: func(inv *serpent.Invocation) error {
223 return cliui.ProvisionerJob(inv.Context(), inv.Stdout, cliui.ProvisionerJobOptions{
224 FetchInterval: time.Millisecond,
225 Fetch: func() (codersdk.ProvisionerJob, error) {
226 jobLock.Lock()
227 defer jobLock.Unlock()
228 return *job, nil
229 },
230 Cancel: func() error {
231 return nil
232 },
233 Logs: func() (<-chan codersdk.ProvisionerJobLog, io.Closer, error) {
234 return logs, closeFunc(func() error {
235 return nil
236 }), nil
237 },
238 })
239 },
240 }
241 inv := cmd.Invoke()
242
243 ptty := ptytest.New(t)
244 ptty.Attach(inv)
245 done := make(chan struct{})
246 go func() {
247 defer close(done)
248 err := inv.WithContext(context.Background()).Run()
249 if err != nil {
250 assert.ErrorIs(t, err, cliui.ErrCanceled)
251 }
252 }()
253 t.Cleanup(func() {
254 <-done
255 })
256 return provisionerJobTest{
257 Next: make(chan struct{}),
258 Job: job,
259 JobMutex: &jobLock,
260 Logs: logs,
261 PTY: ptty,
262 }
263}
264
265type closeFunc func() error
266

Callers 1

TestProvisionerJobFunction · 0.85

Calls 12

NowFunction · 0.92
ProvisionerJobFunction · 0.92
NewFunction · 0.92
WithContextMethod · 0.80
closeFuncFuncType · 0.70
ContextMethod · 0.65
AttachMethod · 0.65
RunMethod · 0.65
CleanupMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
InvokeMethod · 0.45

Tested by

no test coverage detected