MCPcopy
hub / github.com/tailscale/tailscale / TestClockWithDefinedStartTime

Function TestClockWithDefinedStartTime

tstest/clock_test.go:15–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestClockWithDefinedStartTime(t *testing.T) {
16 t.Parallel()
17
18 tests := []struct {
19 name string
20 start time.Time
21 step time.Duration
22 wants []time.Time // The return values of sequential calls to Now().
23 }{
24 {
25 name: "increment-ms",
26 start: time.Unix(12345, 1000),
27 step: 1000,
28 wants: []time.Time{
29 time.Unix(12345, 1000),
30 time.Unix(12345, 2000),
31 time.Unix(12345, 3000),
32 time.Unix(12345, 4000),
33 },
34 },
35 {
36 name: "increment-second",
37 start: time.Unix(12345, 1000),
38 step: time.Second,
39 wants: []time.Time{
40 time.Unix(12345, 1000),
41 time.Unix(12346, 1000),
42 time.Unix(12347, 1000),
43 time.Unix(12348, 1000),
44 },
45 },
46 {
47 name: "no-increment",
48 start: time.Unix(12345, 1000),
49 wants: []time.Time{
50 time.Unix(12345, 1000),
51 time.Unix(12345, 1000),
52 time.Unix(12345, 1000),
53 time.Unix(12345, 1000),
54 },
55 },
56 }
57
58 for _, tt := range tests {
59 t.Run(tt.name, func(t *testing.T) {
60 t.Parallel()
61 clock := NewClock(ClockOpts{
62 Start: tt.start,
63 Step: tt.step,
64 })
65
66 if start := clock.GetStart(); !start.Equal(tt.start) {
67 t.Errorf("clock has start %v, want %v", start, tt.start)
68 }
69 if step := clock.GetStep(); step != tt.step {
70 t.Errorf("clock has step %v, want %v", step, tt.step)
71 }
72

Callers

nothing calls this directly

Calls 8

GetStartMethod · 0.95
GetStepMethod · 0.95
NowMethod · 0.95
PeekNowMethod · 0.95
NewClockFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…