Introduce cmd.Clock() for use in integration tests
If the FAKECLOCK environment variable is set, and the build was in a test environment, cmd.Clock will return a FakeClock with the time set to the content of the environment variable. The choice of the UnixDate format was because `date -d` is a common choice for shell scripts.
This commit is contained in:
parent
bad35e7fe8
commit
a6317d1717
|
|
@ -0,0 +1,14 @@
|
|||
// +build !integration
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/jmhodges/clock"
|
||||
|
||||
// Clock functions similarly to clock.Default(), but the returned value can be
|
||||
// changed using the FAKECLOCK environment variable if the 'integration' build
|
||||
// flag is set.
|
||||
//
|
||||
// This function returns the default Clock.
|
||||
func Clock() clock.Clock {
|
||||
return clock.Default()
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
// +build integration
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/jmhodges/clock"
|
||||
blog "github.com/letsencrypt/boulder/log"
|
||||
)
|
||||
|
||||
// Clock functions similarly to clock.Default(), but the returned value can be
|
||||
// changed using the FAKECLOCK environment variable if the 'integration' build
|
||||
// flag is set.
|
||||
//
|
||||
// The FAKECLOCK env var is in the time.UnixDate format, returned by `date -d`.
|
||||
func Clock() clock.Clock {
|
||||
if tgt := os.Getenv("FAKECLOCK"); tgt != "" {
|
||||
targetTime, err := time.Parse(tgt, time.UnixDate)
|
||||
FailOnError(err, fmt.Sprintf("cmd.Clock: bad format for FAKECLOCK: %v\n", err))
|
||||
|
||||
cl := clock.NewFake()
|
||||
cl.Set(targetTime)
|
||||
blog.GetAuditLogger().Notice(fmt.Sprintf("Time was set to %v via FAKECLOCK", targetTime))
|
||||
return cl
|
||||
}
|
||||
return clock.Default()
|
||||
}
|
||||
|
|
@ -335,7 +335,7 @@ func main() {
|
|||
emailTemplate: tmpl,
|
||||
nagTimes: nags,
|
||||
limit: c.Mailer.CertLimit,
|
||||
clk: clock.Default(),
|
||||
clk: cmd.Clock(),
|
||||
}
|
||||
|
||||
auditlogger.Info("expiration-mailer: Starting")
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ def install(race_detection):
|
|||
# BUILD_ID.
|
||||
cmd = "make GO_BUILD_FLAGS='' "
|
||||
if race_detection:
|
||||
cmd = "make GO_BUILD_FLAGS=-race"
|
||||
cmd = "make GO_BUILD_FLAGS='-race -tags integration'"
|
||||
|
||||
return subprocess.call(cmd, shell=True) == 0
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue