...

Source file src/github.com/letsencrypt/boulder/cmd/clock_integration.go

Documentation: github.com/letsencrypt/boulder/cmd

     1  //go:build integration
     2  
     3  package cmd
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  	"time"
     9  
    10  	"github.com/jmhodges/clock"
    11  	blog "github.com/letsencrypt/boulder/log"
    12  )
    13  
    14  // Clock functions similarly to clock.Default(), but the returned value can be
    15  // changed using the FAKECLOCK environment variable if the 'integration' build
    16  // flag is set.
    17  //
    18  // The FAKECLOCK env var is in the time.UnixDate format, returned by `date -d`.
    19  func Clock() clock.Clock {
    20  	if tgt := os.Getenv("FAKECLOCK"); tgt != "" {
    21  		targetTime, err := time.Parse(time.UnixDate, tgt)
    22  		FailOnError(err, fmt.Sprintf("cmd.Clock: bad format for FAKECLOCK: %v\n", err))
    23  
    24  		cl := clock.NewFake()
    25  		cl.Set(targetTime)
    26  		blog.Get().Infof("Time was set to %v via FAKECLOCK", targetTime)
    27  		return cl
    28  	}
    29  	return clock.Default()
    30  }
    31  

View as plain text