Skip to content

Commit

Permalink
Use the TestClock form juju/clock/testclock.
Browse files Browse the repository at this point in the history
  • Loading branch information
howbazaar committed Aug 19, 2018
1 parent 7df4722 commit 9e7986d
Show file tree
Hide file tree
Showing 66 changed files with 123 additions and 123 deletions.
10 changes: 5 additions & 5 deletions api/apiclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (s *apiclientSuite) TestDialWebsocketStopsOtherDialAttempts(c *gc.C) {
return r.conn, nil
}
conn0 := fakeConn{}
clock := testing.NewClock(time.Now())
clock := testclock.NewClock(time.Now())
openDone := make(chan struct{})
const dialAddressInterval = 50 * time.Millisecond
go func() {
Expand Down Expand Up @@ -742,7 +742,7 @@ func (s *apiclientSuite) TestOpenTimesOutOnLogin(c *gc.C) {
defer srv.Close()
defer close(unblock)

clk := testing.NewClock(time.Now())
clk := testclock.NewClock(time.Now())
done := make(chan error, 1)
go func() {
_, err := api.Open(&api.Info{
Expand Down Expand Up @@ -781,7 +781,7 @@ func (s *apiclientSuite) TestOpenTimeoutAffectsDial(c *gc.C) {
return nil, ctx.Err()
}

clk := testing.NewClock(time.Now())
clk := testclock.NewClock(time.Now())
done := make(chan error, 1)
go func() {
_, err := api.Open(&api.Info{
Expand Down Expand Up @@ -812,7 +812,7 @@ func (s *apiclientSuite) TestOpenDialTimeoutAffectsDial(c *gc.C) {
return nil, ctx.Err()
}

clk := testing.NewClock(time.Now())
clk := testclock.NewClock(time.Now())
done := make(chan error, 1)
go func() {
_, err := api.Open(&api.Info{
Expand Down Expand Up @@ -848,7 +848,7 @@ func (s *apiclientSuite) TestOpenDialTimeoutDoesNotAffectLogin(c *gc.C) {
defer srv.Close()
defer close(unblock)

clk := testing.NewClock(time.Now())
clk := testclock.NewClock(time.Now())
done := make(chan error, 1)
go func() {
_, err := api.Open(&api.Info{
Expand Down
14 changes: 7 additions & 7 deletions api/crossmodelrelations/macarooncache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ type MacaroonCacheSuite struct {
}

func (s *MacaroonCacheSuite) TestGetMacaroonMissing(c *gc.C) {
cache := crossmodelrelations.NewMacaroonCache(testing.NewClock(time.Now()))
cache := crossmodelrelations.NewMacaroonCache(testclock.NewClock(time.Now()))
_, ok := cache.Get("missing")
c.Assert(ok, jc.IsFalse)
}

func (s *MacaroonCacheSuite) TestGetMacaroon(c *gc.C) {
cache := crossmodelrelations.NewMacaroonCache(testing.NewClock(time.Now()))
cache := crossmodelrelations.NewMacaroonCache(testclock.NewClock(time.Now()))
mac, err := apitesting.NewMacaroon("id")
c.Assert(err, jc.ErrorIsNil)
cache.Upsert("token", macaroon.Slice{mac})
Expand All @@ -42,7 +42,7 @@ func (s *MacaroonCacheSuite) TestGetMacaroon(c *gc.C) {
}

func (s *MacaroonCacheSuite) TestGetMacaroonNotExpired(c *gc.C) {
clock := testing.NewClock(time.Now())
clock := testclock.NewClock(time.Now())
cache := crossmodelrelations.NewMacaroonCache(clock)

mac, err := apitesting.NewMacaroon("id")
Expand All @@ -59,7 +59,7 @@ func (s *MacaroonCacheSuite) TestGetMacaroonNotExpired(c *gc.C) {
}

func (s *MacaroonCacheSuite) TestGetMacaroonExpiredBeforeCleanup(c *gc.C) {
clock := testing.NewClock(time.Now())
clock := testclock.NewClock(time.Now())
cache := crossmodelrelations.NewMacaroonCache(clock)

mac, err := apitesting.NewMacaroon("id")
Expand All @@ -75,7 +75,7 @@ func (s *MacaroonCacheSuite) TestGetMacaroonExpiredBeforeCleanup(c *gc.C) {
}

func (s *MacaroonCacheSuite) TestGetMacaroonAfterCleanup(c *gc.C) {
clock := testing.NewClock(time.Now())
clock := testclock.NewClock(time.Now())
cache := crossmodelrelations.NewMacaroonCache(clock)

mac, err := apitesting.NewMacaroon("id")
Expand All @@ -92,7 +92,7 @@ func (s *MacaroonCacheSuite) TestGetMacaroonAfterCleanup(c *gc.C) {
}

func (s *MacaroonCacheSuite) TestMacaroonRemovedByCleanup(c *gc.C) {
clock := testing.NewClock(time.Now())
clock := testclock.NewClock(time.Now())
cache := crossmodelrelations.NewMacaroonCache(clock)

mac, err := apitesting.NewMacaroon("id")
Expand All @@ -108,7 +108,7 @@ func (s *MacaroonCacheSuite) TestMacaroonRemovedByCleanup(c *gc.C) {
}

func (s *MacaroonCacheSuite) TestCleanupIgnoresMacaroonsWithoutTimeBefore(c *gc.C) {
clock := testing.NewClock(time.Now())
clock := testclock.NewClock(time.Now())
cache := crossmodelrelations.NewMacaroonCache(clock)

mac, err := apitesting.NewMacaroon("id")
Expand Down
2 changes: 1 addition & 1 deletion api/monitor_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const testPingTimeout = time.Second

func (s *MonitorSuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
s.clock = testing.NewClock(time.Time{})
s.clock = testclock.NewClock(time.Time{})
s.closed = make(chan struct{})
s.dead = make(chan struct{})
s.broken = make(chan struct{})
Expand Down
4 changes: 2 additions & 2 deletions apiserver/authentication/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (s *userAuthenticatorSuite) TestValidMacaroonUserLogin(c *gc.C) {

func (s *userAuthenticatorSuite) TestCreateLocalLoginMacaroon(c *gc.C) {
service := mockBakeryService{}
clock := testing.NewClock(time.Time{})
clock := testclock.NewClock(time.Time{})
_, err := authentication.CreateLocalLoginMacaroon(
names.NewUserTag("bobbrown"), &service, clock,
)
Expand All @@ -181,7 +181,7 @@ func (s *userAuthenticatorSuite) TestCreateLocalLoginMacaroon(c *gc.C) {

func (s *userAuthenticatorSuite) TestAuthenticateLocalLoginMacaroon(c *gc.C) {
service := mockBakeryService{}
clock := testing.NewClock(time.Time{})
clock := testclock.NewClock(time.Time{})
authenticator := &authentication.UserAuthenticator{
Service: &service,
Clock: clock,
Expand Down
8 changes: 4 additions & 4 deletions apiserver/common/crossmodel/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (s *authSuite) TestCheckOfferMacaroonsNoUser(c *gc.C) {
func (s *authSuite) TestCheckOfferMacaroonsExpired(c *gc.C) {
authContext, err := crossmodel.NewAuthContext(s.mockStatePool, s.bakery, s.bakery)
c.Assert(err, jc.ErrorIsNil)
clock := testing.NewClock(time.Now().Add(-10 * time.Minute))
clock := testclock.NewClock(time.Now().Add(-10 * time.Minute))
authContext = authContext.WithClock(clock)
offer := &params.ApplicationOfferDetails{
SourceModelTag: coretesting.ModelTag.String(),
Expand All @@ -316,7 +316,7 @@ func (s *authSuite) TestCheckOfferMacaroonsExpired(c *gc.C) {
func (s *authSuite) TestCheckOfferMacaroonsDischargeRequired(c *gc.C) {
authContext, err := crossmodel.NewAuthContext(s.mockStatePool, s.bakery, s.bakery)
c.Assert(err, jc.ErrorIsNil)
clock := testing.NewClock(time.Now().Add(-10 * time.Minute))
clock := testclock.NewClock(time.Now().Add(-10 * time.Minute))
authContext = authContext.WithClock(clock)
authContext = authContext.WithDischargeURL("http://thirdparty")
offer := &params.ApplicationOfferDetails{
Expand Down Expand Up @@ -399,7 +399,7 @@ func (s *authSuite) TestCheckRelationMacaroonsNoUser(c *gc.C) {
func (s *authSuite) TestCheckRelationMacaroonsExpired(c *gc.C) {
authContext, err := crossmodel.NewAuthContext(s.mockStatePool, s.bakery, s.bakery)
c.Assert(err, jc.ErrorIsNil)
clock := testing.NewClock(time.Now().Add(-10 * time.Minute))
clock := testclock.NewClock(time.Now().Add(-10 * time.Minute))
authContext = authContext.WithClock(clock)
relationTag := names.NewRelationTag("mediawiki:db mysql:server")
mac, err := authContext.CreateRemoteRelationMacaroon(
Expand All @@ -417,7 +417,7 @@ func (s *authSuite) TestCheckRelationMacaroonsExpired(c *gc.C) {
func (s *authSuite) TestCheckRelationMacaroonsDischargeRequired(c *gc.C) {
authContext, err := crossmodel.NewAuthContext(s.mockStatePool, s.bakery, s.bakery)
c.Assert(err, jc.ErrorIsNil)
clock := testing.NewClock(time.Now().Add(-10 * time.Minute))
clock := testclock.NewClock(time.Now().Add(-10 * time.Minute))
authContext = authContext.WithClock(clock)
authContext = authContext.WithDischargeURL("http://thirdparty")
relationTag := names.NewRelationTag("mediawiki:db mysql:server")
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/agent/presence/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func run(c *gc.C, stub *testing.Stub, test FixtureTest) {
context := &context{
c: c,
stub: stub,
clock: testing.NewClock(time.Now()),
clock: testclock.NewClock(time.Now()),
timeout: time.After(time.Second),
starts: make(chan worker.Worker, 1000),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *CAASProvisionerSuite) SetUpTest(c *gc.C) {
Tag: names.NewMachineTag("0"),
Controller: true,
}
s.clock = testing.NewClock(time.Now())
s.clock = testclock.NewClock(time.Now())

facade, err := caasunitprovisioner.NewFacade(
s.resources, s.authorizer, s.st, s.storage, s.devices, s.storageProviderRegistry, s.storagePoolManager, s.clock)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *listenerSuite) SetUpTest(c *gc.C) {
s.lowerThreshold = 1000
s.upperThreshold = 10000

s.clock = testing.NewClock(time.Now())
s.clock = testclock.NewClock(time.Now())
s.listener = &mockListener{}
}

Expand Down
2 changes: 1 addition & 1 deletion apiserver/logsink/logsink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (s *logsinkSuite) TestReceiveErrorBreaksConn(c *gc.C) {
}

func (s *logsinkSuite) TestRateLimit(c *gc.C) {
testClock := testing.NewClock(time.Time{})
testClock := testclock.NewClock(time.Time{})
s.srv.Close()
s.srv = httptest.NewServer(logsink.NewHTTPHandler(
func(req *http.Request) (logsink.LogWriteCloser, error) {
Expand Down
2 changes: 1 addition & 1 deletion apiserver/observer/metricobserver/observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _ = gc.Suite(&observerSuite{})

func (s *observerSuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
s.clock = testing.NewClock(time.Time{})
s.clock = testclock.NewClock(time.Time{})
s.registry = prometheus.NewPedanticRegistry()

var err error
Expand Down
2 changes: 1 addition & 1 deletion apiserver/observer/metricobserver/observerfactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = gc.Suite(&observerFactorySuite{})

func (s *observerFactorySuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
s.clock = testing.NewClock(time.Time{})
s.clock = testclock.NewClock(time.Time{})
s.registerer = fakePrometheusRegisterer{}
}

Expand Down
8 changes: 4 additions & 4 deletions apiserver/observer/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var _ = gc.Suite(&recorderSuite{})
func (s *recorderSuite) TestServerRequest(c *gc.C) {
fake := &fakeobserver.Instance{}
log := &apitesting.FakeAuditLog{}
clock := testing.NewClock(time.Now())
clock := testclock.NewClock(time.Now())
auditRecorder, err := auditlog.NewRecorder(log, clock, auditlog.ConversationArgs{
ConnectionID: 4567,
})
Expand Down Expand Up @@ -66,7 +66,7 @@ func (s *recorderSuite) TestServerRequest(c *gc.C) {
func (s *recorderSuite) TestServerRequestNoArgs(c *gc.C) {
fake := &fakeobserver.Instance{}
log := &apitesting.FakeAuditLog{}
clock := testing.NewClock(time.Now())
clock := testclock.NewClock(time.Now())
auditRecorder, err := auditlog.NewRecorder(log, clock, auditlog.ConversationArgs{
ConnectionID: 4567,
})
Expand Down Expand Up @@ -99,7 +99,7 @@ func (s *recorderSuite) TestServerRequestNoArgs(c *gc.C) {
func (s *recorderSuite) TestServerReply(c *gc.C) {
fake := &fakeobserver.Instance{}
log := &apitesting.FakeAuditLog{}
clock := testing.NewClock(time.Now())
clock := testclock.NewClock(time.Now())
auditRecorder, err := auditlog.NewRecorder(log, clock, auditlog.ConversationArgs{
ConnectionID: 4567,
})
Expand Down Expand Up @@ -201,7 +201,7 @@ func (s *recorderSuite) TestReplyResultSlice(c *gc.C) {
func (s *recorderSuite) checkServerReplyErrors(c *gc.C, result interface{}, expected []*auditlog.Error) {
fake := &fakeobserver.Instance{}
log := &apitesting.FakeAuditLog{}
clock := testing.NewClock(time.Now())
clock := testclock.NewClock(time.Now())
auditRecorder, err := auditlog.NewRecorder(log, clock, auditlog.ConversationArgs{
ConnectionID: 4567,
})
Expand Down
2 changes: 1 addition & 1 deletion apiserver/observer/request_notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = gc.Suite(&RequestObserverSuite{})
func (*RequestObserverSuite) makeNotifier(c *gc.C) (*observer.RequestObserver, *connectionHub) {
hub := &connectionHub{c: c}
return observer.NewRequestObserver(observer.RequestObserverContext{
Clock: testing.NewClock(time.Now()),
Clock: testclock.NewClock(time.Now()),
Hub: hub,
Logger: loggo.GetLogger("test"),
}), hub
Expand Down
2 changes: 1 addition & 1 deletion apiserver/pinger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type pingerSuite struct {
var _ = gc.Suite(&pingerSuite{})

func (s *pingerSuite) newServerWithTestClock(c *gc.C) (*apiserver.Server, *testing.Clock) {
clock := testing.NewClock(time.Now())
clock := testclock.NewClock(time.Now())
config := s.config
config.PingClock = clock
server := s.newServer(c, config)
Expand Down
4 changes: 2 additions & 2 deletions cmd/juju/controller/kill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var _ = gc.Suite(&KillSuite{})

func (s *KillSuite) SetUpTest(c *gc.C) {
s.baseDestroySuite.SetUpTest(c)
s.clock = testing.NewClock(time.Now())
s.clock = testclock.NewClock(time.Now())
}

func (s *KillSuite) runKillCommand(c *gc.C, args ...string) (*cmd.Context, error) {
Expand All @@ -48,7 +48,7 @@ func (s *KillSuite) runKillCommand(c *gc.C, args ...string) (*cmd.Context, error
func (s *KillSuite) newKillCommand() cmd.Command {
clock := s.clock
if clock == nil {
clock = testing.NewClock(time.Now())
clock = testclock.NewClock(time.Now())
}
return controller.NewKillCommandForTest(
s.api, s.clientapi, s.store, s.apierror, clock, nil,
Expand Down
2 changes: 1 addition & 1 deletion container/kvm/sync_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (s *progressWriterSuite) TestOnlyPercentChanges(c *gc.C) {
loggingCB := func(msg string) {
cbLog = append(cbLog, msg)
}
clock := testing.NewClock(time.Date(2007, 1, 1, 10, 20, 30, 1234, time.UTC))
clock := testclock.NewClock(time.Date(2007, 1, 1, 10, 20, 30, 1234, time.UTC))
// We are using clock to actually measure time, not trigger an event, which
// causes the testing.Clock to think we're doing something wrong, so we
// just create one waiter that we'll otherwise ignore.
Expand Down
2 changes: 1 addition & 1 deletion core/auditlog/auditlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *AuditLogSuite) TestRecorder(c *gc.C) {
var log fakeLog
logTime, err := time.Parse(time.RFC3339, "2017-11-27T15:45:23Z")
c.Assert(err, jc.ErrorIsNil)
clock := testing.NewClock(logTime)
clock := testclock.NewClock(logTime)
rec, err := auditlog.NewRecorder(&log, clock, auditlog.ConversationArgs{
Who: "wildbirds and peacedrums",
What: "Doubt/Hope",
Expand Down
4 changes: 2 additions & 2 deletions core/presence/presence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (*suite) assertConnections(c *gc.C, connections presence.Connections, expec
}

func (s *suite) TestEmptyRecorder(c *gc.C) {
r := presence.New(testing.NewClock(time.Time{}))
r := presence.New(testclock.NewClock(time.Time{}))
c.Assert(r.IsEnabled(), jc.IsFalse)
r.Enable()
s.assertEmptyConnections(c, r.Connections())
Expand Down Expand Up @@ -272,7 +272,7 @@ func bootstrap(initialTime ...time.Time) (presence.Recorder, *testing.Clock) {
t = initialTime[0]
}
// By using a testing clock with a zero time, the times are always empty.
clock := testing.NewClock(t)
clock := testclock.NewClock(t)
r := presence.New(clock)
r.Enable()
connect(r, ha0)
Expand Down
6 changes: 3 additions & 3 deletions network/debinterfaces/activate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *BridgeSuite) TestActivateEth0(c *gc.C) {
filename := "testdata/TestInputSourceStanza/interfaces"

params := debinterfaces.ActivationParams{
Clock: testing.NewClock(time.Now()),
Clock: testclock.NewClock(time.Now()),
Devices: map[string]string{"eth0": "br-eth0", "eth1": "br-eth1"},
DryRun: true,
Filename: filename,
Expand All @@ -76,7 +76,7 @@ func (s *BridgeSuite) TestActivateEth0WithoutBackup(c *gc.C) {
filename := "testdata/TestInputSourceStanza/interfaces"

params := debinterfaces.ActivationParams{
Clock: testing.NewClock(time.Now()),
Clock: testclock.NewClock(time.Now()),
Devices: map[string]string{"eth0": "br-eth0", "eth1": "br-eth1"},
DryRun: true,
Filename: filename,
Expand Down Expand Up @@ -104,7 +104,7 @@ func (s *BridgeSuite) TestActivateWithNegativeReconfigureDelay(c *gc.C) {
filename := "testdata/TestInputSourceStanza/interfaces"

params := debinterfaces.ActivationParams{
Clock: testing.NewClock(time.Now()),
Clock: testclock.NewClock(time.Now()),
Devices: map[string]string{"eth0": "br-eth0", "eth1": "br-eth1"},
DryRun: true,
Filename: filename,
Expand Down
8 changes: 4 additions & 4 deletions network/scriptrunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ func (s *ScriptRunnerSuite) SetUpSuite(c *gc.C) {
}

func (*ScriptRunnerSuite) TestScriptRunnerFails(c *gc.C) {
clock := testing.NewClock(coretesting.ZeroTime())
clock := testclock.NewClock(coretesting.ZeroTime())
result, err := network.RunCommand("exit 1", os.Environ(), clock, 0)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.TimedOut, gc.Equals, false)
c.Assert(result.Code, gc.Equals, 1)
}

func (*ScriptRunnerSuite) TestScriptRunnerSucceeds(c *gc.C) {
clock := testing.NewClock(coretesting.ZeroTime())
clock := testclock.NewClock(coretesting.ZeroTime())
result, err := network.RunCommand("exit 0", os.Environ(), clock, 0)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.TimedOut, gc.Equals, false)
c.Assert(result.Code, gc.Equals, 0)
}

func (*ScriptRunnerSuite) TestScriptRunnerCheckStdout(c *gc.C) {
clock := testing.NewClock(coretesting.ZeroTime())
clock := testclock.NewClock(coretesting.ZeroTime())
result, err := network.RunCommand("echo -n 42", os.Environ(), clock, 0)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.TimedOut, gc.Equals, false)
Expand All @@ -57,7 +57,7 @@ func (*ScriptRunnerSuite) TestScriptRunnerCheckStdout(c *gc.C) {
}

func (*ScriptRunnerSuite) TestScriptRunnerCheckStderr(c *gc.C) {
clock := testing.NewClock(coretesting.ZeroTime())
clock := testclock.NewClock(coretesting.ZeroTime())
result, err := network.RunCommand(">&2 echo -n 3.141", os.Environ(), clock, 0)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.TimedOut, gc.Equals, false)
Expand Down
Loading

0 comments on commit 9e7986d

Please sign in to comment.