(t *testing.T)
| 21 | ) |
| 22 | |
| 23 | func Test_Run(t *testing.T) { |
| 24 | t.Parallel() |
| 25 | if testutil.RaceEnabled() { |
| 26 | t.Skip("skipping timing-sensitive test because of race detector") |
| 27 | } |
| 28 | if runtime.GOOS == "windows" { |
| 29 | t.Skip("skipping test on Windows") |
| 30 | } |
| 31 | |
| 32 | successAction := func(_ context.Context) error { |
| 33 | <-time.After(testutil.IntervalFast) |
| 34 | return nil |
| 35 | } |
| 36 | |
| 37 | failAction := func(_ context.Context) error { |
| 38 | <-time.After(testutil.IntervalMedium) |
| 39 | return assert.AnError |
| 40 | } |
| 41 | |
| 42 | //nolint: gosec // just for testing |
| 43 | rg := rand.New(rand.NewSource(0)) // deterministic for testing |
| 44 | |
| 45 | client := coderdtest.New(t, nil) |
| 46 | _ = coderdtest.CreateFirstUser(t, client) |
| 47 | |
| 48 | log := slogtest.Make(t, &slogtest.Options{ |
| 49 | IgnoreErrors: true, |
| 50 | }) |
| 51 | m := &testMetrics{} |
| 52 | var ( |
| 53 | waitLoadedCalled atomic.Bool |
| 54 | screenshotCalled atomic.Bool |
| 55 | ) |
| 56 | cancelDone := make(chan struct{}) |
| 57 | cfg := dashboard.Config{ |
| 58 | Interval: 500 * time.Millisecond, |
| 59 | Jitter: 100 * time.Millisecond, |
| 60 | Logger: log, |
| 61 | Headless: true, |
| 62 | WaitLoaded: func(_ context.Context, _ time.Time) error { |
| 63 | waitLoadedCalled.Store(true) |
| 64 | return nil |
| 65 | }, |
| 66 | ActionFunc: func(_ context.Context, _ slog.Logger, rnd func(int) int, _ time.Time) (dashboard.Label, dashboard.Action, error) { |
| 67 | if rnd(2) == 0 { |
| 68 | return "fails", failAction, nil |
| 69 | } |
| 70 | return "succeeds", successAction, nil |
| 71 | }, |
| 72 | Screenshot: func(_ context.Context, name string) (string, error) { |
| 73 | screenshotCalled.Store(true) |
| 74 | return "/fake/path/to/" + name + ".png", nil |
| 75 | }, |
| 76 | RandIntn: rg.Intn, |
| 77 | InitChromeDPCtx: func(ctx context.Context, _ slog.Logger, _ *url.URL, _ string, _ bool) (context.Context, context.CancelFunc, error) { |
| 78 | return ctx, func() { close(cancelDone) }, nil |
| 79 | }, |
| 80 | } |
nothing calls this directly
no test coverage detected