Run executes the Run function with a self-managed log writer, panic handler, error recording and duration recording. The test error is returned.
(ctx context.Context)
| 96 | // Run executes the Run function with a self-managed log writer, panic handler, |
| 97 | // error recording and duration recording. The test error is returned. |
| 98 | func (r *TestRun) Run(ctx context.Context) (err error) { |
| 99 | r.logs = &syncBuffer{ |
| 100 | buf: new(bytes.Buffer), |
| 101 | } |
| 102 | r.done = make(chan struct{}) |
| 103 | defer close(r.done) |
| 104 | |
| 105 | r.started = time.Now() |
| 106 | defer func() { |
| 107 | r.duration = time.Since(r.started) |
| 108 | r.err = err |
| 109 | c, ok := r.runner.(Collectable) |
| 110 | if !ok { |
| 111 | return |
| 112 | } |
| 113 | r.metrics = c.GetMetrics() |
| 114 | }() |
| 115 | defer func() { |
| 116 | e := recover() |
| 117 | if e != nil { |
| 118 | err = xerrors.Errorf("panic: %v", e) |
| 119 | } |
| 120 | }() |
| 121 | |
| 122 | err = r.runner.Run(ctx, r.id, r.logs) |
| 123 | |
| 124 | //nolint:revive // we use named returns because we mutate it in a defer |
| 125 | return |
| 126 | } |
| 127 | |
| 128 | func (r *TestRun) Cleanup(ctx context.Context) (err error) { |
| 129 | c, ok := r.runner.(Cleanable) |