github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/clock/clock.go (about)

     1  package clock
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"k8s.io/utils/clock"
     8  	clocktesting "k8s.io/utils/clock/testing"
     9  )
    10  
    11  var c clock.Clock = clock.RealClock{}
    12  
    13  // SetFakeTime sets a fake time for testing.
    14  func SetFakeTime(t *testing.T, fakeTime time.Time) {
    15  	c = clocktesting.NewFakeClock(fakeTime)
    16  	t.Cleanup(func() {
    17  		c = clock.RealClock{}
    18  	})
    19  }
    20  
    21  func Now() time.Time {
    22  	return c.Now()
    23  }