diff --git a/cmd/clock_generic.go b/cmd/clock_generic.go new file mode 100644 index 000000000..f9f003a74 --- /dev/null +++ b/cmd/clock_generic.go @@ -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() +} diff --git a/cmd/clock_integration.go b/cmd/clock_integration.go new file mode 100644 index 000000000..a1029a564 --- /dev/null +++ b/cmd/clock_integration.go @@ -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() +} diff --git a/cmd/expiration-mailer/main.go b/cmd/expiration-mailer/main.go index abc3aa7df..3078843f8 100644 --- a/cmd/expiration-mailer/main.go +++ b/cmd/expiration-mailer/main.go @@ -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") diff --git a/test/startservers.py b/test/startservers.py index 8ae3cf76e..51d933486 100644 --- a/test/startservers.py +++ b/test/startservers.py @@ -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