(t *testing.T)
| 83 | } |
| 84 | |
| 85 | func TestClockWithDefaultStartTime(t *testing.T) { |
| 86 | t.Parallel() |
| 87 | |
| 88 | tests := []struct { |
| 89 | name string |
| 90 | step time.Duration |
| 91 | wants []time.Duration // The return values of sequential calls to Now() after added to Start() |
| 92 | }{ |
| 93 | { |
| 94 | name: "increment-ms", |
| 95 | step: 1000, |
| 96 | wants: []time.Duration{ |
| 97 | 0, |
| 98 | 1000, |
| 99 | 2000, |
| 100 | 3000, |
| 101 | }, |
| 102 | }, |
| 103 | { |
| 104 | name: "increment-second", |
| 105 | step: time.Second, |
| 106 | wants: []time.Duration{ |
| 107 | 0 * time.Second, |
| 108 | 1 * time.Second, |
| 109 | 2 * time.Second, |
| 110 | 3 * time.Second, |
| 111 | }, |
| 112 | }, |
| 113 | { |
| 114 | name: "no-increment", |
| 115 | wants: []time.Duration{0, 0, 0, 0}, |
| 116 | }, |
| 117 | } |
| 118 | |
| 119 | for _, tt := range tests { |
| 120 | t.Run(tt.name, func(t *testing.T) { |
| 121 | t.Parallel() |
| 122 | clock := NewClock(ClockOpts{ |
| 123 | Step: tt.step, |
| 124 | }) |
| 125 | start := clock.GetStart() |
| 126 | |
| 127 | if step := clock.GetStep(); step != tt.step { |
| 128 | t.Errorf("clock has step %v, want %v", step, tt.step) |
| 129 | } |
| 130 | |
| 131 | for i := range tt.wants { |
| 132 | want := start.Add(tt.wants[i]) |
| 133 | if got := clock.Now(); !got.Equal(want) { |
| 134 | t.Errorf("step %v: clock.Now() = %v, want %v", i, got, tt.wants[i]) |
| 135 | } |
| 136 | if got := clock.PeekNow(); !got.Equal(want) { |
| 137 | t.Errorf("step %v: clock.PeekNow() = %v, want %v", i, got, tt.wants[i]) |
| 138 | } |
| 139 | } |
| 140 | }) |
| 141 | } |
| 142 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…