github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/testutils/fake_clock.go (about)

     1  package testutils
     2  
     3  import (
     4  	"math/rand"
     5  	"time"
     6  )
     7  
     8  type Clock func() time.Time
     9  
    10  type FakeClock struct {
    11  	Times    []time.Time
    12  	nextTime Clock
    13  }
    14  
    15  func (fc *FakeClock) next() time.Time {
    16  	ret := fc.nextTime()
    17  	fc.Times = append(fc.Times, ret)
    18  	return ret
    19  }
    20  
    21  func (fc *FakeClock) Clock() Clock {
    22  	return fc.next
    23  }
    24  
    25  func NewRandomFakeClock() *FakeClock {
    26  	return &FakeClock{
    27  		nextTime: func() time.Time {
    28  			d := rand.Int()
    29  			h := rand.Int()
    30  			return time.Date(2019, 1, d, h, 0, 0, 0, time.UTC)
    31  		},
    32  	}
    33  }