本文整理汇总了Golang中github.com/juju/juju/state.NowToTheSecond函数的典型用法代码示例。如果您正苦于以下问题:Golang NowToTheSecond函数的具体用法?Golang NowToTheSecond怎么用?Golang NowToTheSecond使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NowToTheSecond函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestAddEnvironmentUser
func (s *EnvUserSuite) TestAddEnvironmentUser(c *gc.C) {
now := state.NowToTheSecond()
user := s.Factory.MakeUser(c, &factory.UserParams{Name: "validusername", NoEnvUser: true})
createdBy := s.Factory.MakeUser(c, &factory.UserParams{Name: "createdby"})
envUser, err := s.State.AddEnvironmentUser(state.EnvUserSpec{
User: user.UserTag(), CreatedBy: createdBy.UserTag()})
c.Assert(err, jc.ErrorIsNil)
c.Assert(envUser.ID(), gc.Equals, fmt.Sprintf("%s:[email protected]", s.envTag.Id()))
c.Assert(envUser.EnvironmentTag(), gc.Equals, s.envTag)
c.Assert(envUser.UserName(), gc.Equals, "[email protected]")
c.Assert(envUser.DisplayName(), gc.Equals, user.DisplayName())
c.Assert(envUser.ReadOnly(), jc.IsFalse)
c.Assert(envUser.CreatedBy(), gc.Equals, "[email protected]")
c.Assert(envUser.DateCreated().Equal(now) || envUser.DateCreated().After(now), jc.IsTrue)
when, err := envUser.LastConnection()
c.Assert(err, jc.Satisfies, state.IsNeverConnectedError)
c.Assert(when.IsZero(), jc.IsTrue)
envUser, err = s.State.EnvironmentUser(user.UserTag())
c.Assert(err, jc.ErrorIsNil)
c.Assert(envUser.ID(), gc.Equals, fmt.Sprintf("%s:[email protected]", s.envTag.Id()))
c.Assert(envUser.EnvironmentTag(), gc.Equals, s.envTag)
c.Assert(envUser.UserName(), gc.Equals, "[email protected]")
c.Assert(envUser.DisplayName(), gc.Equals, user.DisplayName())
c.Assert(envUser.ReadOnly(), jc.IsFalse)
c.Assert(envUser.CreatedBy(), gc.Equals, "[email protected]")
c.Assert(envUser.DateCreated().Equal(now) || envUser.DateCreated().After(now), jc.IsTrue)
when, err = envUser.LastConnection()
c.Assert(err, jc.Satisfies, state.IsNeverConnectedError)
c.Assert(when.IsZero(), jc.IsTrue)
}
示例2: TestAddMetricDeadUnit
func (s *MetricSuite) TestAddMetricDeadUnit(c *gc.C) {
assertUnitDead(c, s.unit)
now := state.NowToTheSecond()
m := state.Metric{"pings", "5", now}
_, err := s.unit.AddMetrics(utils.MustNewUUID().String(), now, "", []state.Metric{m})
c.Assert(err, gc.ErrorMatches, `metered/0 not found`)
}
示例3: TestAddMetric
func (s *MetricSuite) TestAddMetric(c *gc.C) {
now := state.NowToTheSecond()
envUUID := s.State.EnvironUUID()
m := state.Metric{"pings", "5", now}
metricBatch, err := s.unit.AddMetrics(utils.MustNewUUID().String(), now, "", []state.Metric{m})
c.Assert(err, jc.ErrorIsNil)
c.Assert(metricBatch.Unit(), gc.Equals, "metered/0")
c.Assert(metricBatch.EnvUUID(), gc.Equals, envUUID)
c.Assert(metricBatch.CharmURL(), gc.Equals, "cs:quantal/metered")
c.Assert(metricBatch.Sent(), jc.IsFalse)
c.Assert(metricBatch.Created(), gc.Equals, now)
c.Assert(metricBatch.Metrics(), gc.HasLen, 1)
metric := metricBatch.Metrics()[0]
c.Assert(metric.Key, gc.Equals, "pings")
c.Assert(metric.Value, gc.Equals, "5")
c.Assert(metric.Time.Equal(now), jc.IsTrue)
saved, err := s.State.MetricBatch(metricBatch.UUID())
c.Assert(err, jc.ErrorIsNil)
c.Assert(saved.Unit(), gc.Equals, "metered/0")
c.Assert(metricBatch.CharmURL(), gc.Equals, "cs:quantal/metered")
c.Assert(saved.Sent(), jc.IsFalse)
c.Assert(saved.Metrics(), gc.HasLen, 1)
metric = saved.Metrics()[0]
c.Assert(metric.Key, gc.Equals, "pings")
c.Assert(metric.Value, gc.Equals, "5")
c.Assert(metric.Time.Equal(now), jc.IsTrue)
}
示例4: TestAddEnvironmentUser
func (s *EnvUserSuite) TestAddEnvironmentUser(c *gc.C) {
now := state.NowToTheSecond()
user := s.factory.MakeUser(c, &factory.UserParams{Name: "validusername", NoEnvUser: true})
createdBy := s.factory.MakeUser(c, &factory.UserParams{Name: "createdby"})
envUser, err := s.State.AddEnvironmentUser(user.UserTag(), createdBy.UserTag())
c.Assert(err, gc.IsNil)
c.Assert(envUser.ID(), gc.Equals, fmt.Sprintf("%s:[email protected]", s.envTag.Id()))
c.Assert(envUser.EnvironmentTag(), gc.Equals, s.envTag)
c.Assert(envUser.UserName(), gc.Equals, "[email protected]")
c.Assert(envUser.DisplayName(), gc.Equals, user.DisplayName())
c.Assert(envUser.CreatedBy(), gc.Equals, "[email protected]")
c.Assert(envUser.DateCreated().Equal(now) || envUser.DateCreated().After(now), jc.IsTrue)
c.Assert(envUser.LastConnection(), gc.IsNil)
envUser, err = s.State.EnvironmentUser(user.UserTag())
c.Assert(err, gc.IsNil)
c.Assert(envUser.ID(), gc.Equals, fmt.Sprintf("%s:[email protected]", s.envTag.Id()))
c.Assert(envUser.EnvironmentTag(), gc.Equals, s.envTag)
c.Assert(envUser.UserName(), gc.Equals, "[email protected]")
c.Assert(envUser.DisplayName(), gc.Equals, user.DisplayName())
c.Assert(envUser.CreatedBy(), gc.Equals, "[email protected]")
c.Assert(envUser.DateCreated().Equal(now) || envUser.DateCreated().After(now), jc.IsTrue)
c.Assert(envUser.LastConnection(), gc.IsNil)
}
示例5: TestUnitMetricBatchesReturnsJustLocal
func (s *MetricLocalCharmSuite) TestUnitMetricBatchesReturnsJustLocal(c *gc.C) {
now := state.NowToTheSecond()
m := state.Metric{"pings", "5", now}
_, err := s.State.AddMetrics(
state.BatchParam{
UUID: utils.MustNewUUID().String(),
Created: now,
CharmURL: s.meteredCharm.URL().String(),
Metrics: []state.Metric{m},
Unit: s.unit.UnitTag(),
},
)
c.Assert(err, jc.ErrorIsNil)
csMeteredCharm := s.Factory.MakeCharm(c, &factory.CharmParams{Name: "metered", URL: "cs:quantal/metered"})
service := s.Factory.MakeService(c, &factory.ServiceParams{Name: "csmetered", Charm: csMeteredCharm})
unit := s.Factory.MakeUnit(c, &factory.UnitParams{Service: service, SetCharmURL: true})
_, err = s.State.AddMetrics(
state.BatchParam{
UUID: utils.MustNewUUID().String(),
Created: now,
CharmURL: csMeteredCharm.URL().String(),
Metrics: []state.Metric{m},
Unit: unit.UnitTag(),
},
)
c.Assert(err, jc.ErrorIsNil)
metricBatches, err := s.State.MetricBatchesForUnit("metered/0")
c.Assert(metricBatches, gc.HasLen, 1)
metricBatches, err = s.State.MetricBatchesForUnit("csmetered/0")
c.Assert(metricBatches, gc.HasLen, 0)
}
示例6: TestAddMetricDuplicateUUID
func (s *MetricSuite) TestAddMetricDuplicateUUID(c *gc.C) {
now := state.NowToTheSecond()
mUUID := utils.MustNewUUID().String()
_, err := s.State.AddMetrics(
state.BatchParam{
UUID: mUUID,
Created: now,
CharmURL: s.meteredCharm.URL().String(),
Metrics: []state.Metric{{"pings", "5", now}},
Unit: s.unit.UnitTag(),
},
)
c.Assert(err, jc.ErrorIsNil)
_, err = s.State.AddMetrics(
state.BatchParam{
UUID: mUUID,
Created: now,
CharmURL: s.meteredCharm.URL().String(),
Metrics: []state.Metric{{"pings", "10", now}},
Unit: s.unit.UnitTag(),
},
)
c.Assert(err, gc.ErrorMatches, "metrics batch .* already exists")
}
示例7: TestAddMetric
func (s *MetricSuite) TestAddMetric(c *gc.C) {
unit := s.assertAddUnit(c)
now := state.NowToTheSecond()
m := state.NewMetric("item", "5", now, []byte("creds"))
metricBatch, err := unit.AddMetrics([]*state.Metric{m})
c.Assert(err, gc.IsNil)
c.Assert(metricBatch.Unit(), gc.Equals, "wordpress/0")
c.Assert(metricBatch.CharmURL(), gc.Equals, "local:quantal/quantal-wordpress-3")
c.Assert(metricBatch.Sent(), gc.Equals, false)
c.Assert(metricBatch.Metrics(), gc.HasLen, 1)
metric := metricBatch.Metrics()[0]
c.Assert(metric.Key(), gc.Equals, "item")
c.Assert(metric.Value(), gc.Equals, "5")
c.Assert(metric.Time().Equal(now), jc.IsTrue)
c.Assert(metric.Credentials(), gc.DeepEquals, []byte("creds"))
saved, err := s.State.MetricBatch(metricBatch.UUID())
c.Assert(err, gc.IsNil)
c.Assert(saved.Unit(), gc.Equals, "wordpress/0")
c.Assert(metricBatch.CharmURL(), gc.Equals, "local:quantal/quantal-wordpress-3")
c.Assert(saved.Sent(), gc.Equals, false)
c.Assert(saved.Metrics(), gc.HasLen, 1)
metric = saved.Metrics()[0]
c.Assert(metric.Key(), gc.Equals, "item")
c.Assert(metric.Value(), gc.Equals, "5")
c.Assert(metric.Time().Equal(now), jc.IsTrue)
c.Assert(metric.Credentials(), gc.DeepEquals, []byte("creds"))
}
示例8: TestModelUsers
func (s *MigrationImportSuite) TestModelUsers(c *gc.C) {
// To be sure with this test, we create three env users, and remove
// the owner.
err := s.State.RemoveUserAccess(s.Owner, s.modelTag)
c.Assert(err, jc.ErrorIsNil)
lastConnection := state.NowToTheSecond()
bravo := s.newModelUser(c, "[email protected]", false, lastConnection)
charlie := s.newModelUser(c, "[email protected]", true, lastConnection)
delta := s.newModelUser(c, "[email protected]", true, time.Time{})
newModel, newSt := s.importModel(c)
// Check the import values of the users.
for _, user := range []permission.UserAccess{bravo, charlie, delta} {
newUser, err := newSt.UserAccess(user.UserTag, newModel.Tag())
c.Assert(err, jc.ErrorIsNil)
s.AssertUserEqual(c, newUser, user)
}
// Also make sure that there aren't any more.
allUsers, err := newModel.Users()
c.Assert(err, jc.ErrorIsNil)
c.Assert(allUsers, gc.HasLen, 3)
}
示例9: TestMetricsAcrossEnvironments
func (s *MetricSuite) TestMetricsAcrossEnvironments(c *gc.C) {
now := state.NowToTheSecond().Add(-48 * time.Hour)
m := state.Metric{"pings", "5", now}
m1, err := s.State.AddMetrics(
state.BatchParam{
UUID: utils.MustNewUUID().String(),
Created: now,
CharmURL: s.meteredCharm.URL().String(),
Metrics: []state.Metric{m},
Unit: s.unit.UnitTag(),
},
)
c.Assert(err, jc.ErrorIsNil)
st := s.Factory.MakeEnvironment(c, nil)
defer st.Close()
f := factory.NewFactory(st)
meteredCharm := f.MakeCharm(c, &factory.CharmParams{Name: "metered", URL: "cs:quantal/metered"})
service := f.MakeService(c, &factory.ServiceParams{Charm: meteredCharm})
unit := f.MakeUnit(c, &factory.UnitParams{Service: service, SetCharmURL: true})
m2, err := s.State.AddMetrics(
state.BatchParam{
UUID: utils.MustNewUUID().String(),
Created: now,
CharmURL: s.meteredCharm.URL().String(),
Metrics: []state.Metric{m},
Unit: unit.UnitTag(),
},
)
c.Assert(err, jc.ErrorIsNil)
batches, err := s.State.MetricBatches()
c.Assert(err, jc.ErrorIsNil)
c.Assert(batches, gc.HasLen, 2)
unsent, err := s.State.CountOfUnsentMetrics()
c.Assert(err, jc.ErrorIsNil)
c.Assert(unsent, gc.Equals, 2)
toSend, err := s.State.MetricsToSend(10)
c.Assert(err, jc.ErrorIsNil)
c.Assert(toSend, gc.HasLen, 2)
err = m1.SetSent(time.Now().Add(-25 * time.Hour))
c.Assert(err, jc.ErrorIsNil)
err = m2.SetSent(time.Now().Add(-25 * time.Hour))
c.Assert(err, jc.ErrorIsNil)
sent, err := s.State.CountOfSentMetrics()
c.Assert(err, jc.ErrorIsNil)
c.Assert(sent, gc.Equals, 2)
err = s.State.CleanupOldMetrics()
c.Assert(err, jc.ErrorIsNil)
batches, err = s.State.MetricBatches()
c.Assert(err, jc.ErrorIsNil)
c.Assert(batches, gc.HasLen, 0)
}
示例10: TestAddMetricDeadUnit
func (s *MetricSuite) TestAddMetricDeadUnit(c *gc.C) {
unit := s.assertAddUnit(c)
assertUnitDead(c, unit)
now := state.NowToTheSecond()
m := state.NewMetric("item", "5", now, []byte{})
_, err := unit.AddMetrics([]*state.Metric{m})
c.Assert(err, gc.ErrorMatches, `wordpress/0 not found`)
}
示例11: TestAddMetricNonExitentUnit
func (s *MetricSuite) TestAddMetricNonExitentUnit(c *gc.C) {
unit := s.assertAddUnit(c)
assertUnitRemoved(c, unit)
now := state.NowToTheSecond()
m := state.Metric{"item", "5", now, []byte{}}
_, err := unit.AddMetrics(now, []state.Metric{m})
c.Assert(err, gc.ErrorMatches, `wordpress/0 not found`)
}
示例12: TestAddMetricDuplicateUUID
func (s *MetricSuite) TestAddMetricDuplicateUUID(c *gc.C) {
now := state.NowToTheSecond()
mUUID := utils.MustNewUUID().String()
_, err := s.unit.AddMetrics(mUUID, now, "", []state.Metric{{"pings", "5", now}})
c.Assert(err, jc.ErrorIsNil)
_, err = s.unit.AddMetrics(mUUID, now, "", []state.Metric{{"pings", "10", now}})
c.Assert(err, gc.ErrorMatches, "metrics batch .* already exists")
}
示例13: TestMetricsToSend
func (s *MetricSuite) TestMetricsToSend(c *gc.C) {
now := state.NowToTheSecond()
m := []state.Metric{{Key: "pings", Value: "123", Time: now}}
s.Factory.MakeMetric(c, &factory.MetricParams{Unit: s.unit, Sent: false, Time: &now, Metrics: m})
s.Factory.MakeMetric(c, &factory.MetricParams{Unit: s.unit, Sent: false, Time: &now, Metrics: m})
s.Factory.MakeMetric(c, &factory.MetricParams{Unit: s.unit, Sent: true, Time: &now, Metrics: m})
result, err := s.State.MetricsToSend(5)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.HasLen, 2)
}
示例14: TestAddNoMetrics
func (s *MetricSuite) TestAddNoMetrics(c *gc.C) {
now := state.NowToTheSecond()
_, err := s.State.AddMetrics(state.BatchParam{
UUID: utils.MustNewUUID().String(),
CharmURL: s.meteredCharm.URL().String(),
Created: now,
Metrics: []state.Metric{},
Unit: s.unit.UnitTag(),
})
c.Assert(err, gc.ErrorMatches, "cannot add a batch of 0 metrics")
}
示例15: TestMetricCredentials
func (s *MetricSuite) TestMetricCredentials(c *gc.C) {
now := state.NowToTheSecond()
m := state.Metric{"pings", "5", now}
err := s.service.SetMetricCredentials([]byte("hello there"))
c.Assert(err, gc.IsNil)
_, err = s.unit.AddMetrics(utils.MustNewUUID().String(), now, "", []state.Metric{m})
c.Assert(err, jc.ErrorIsNil)
metricBatches, err := s.State.MetricBatches()
c.Assert(err, jc.ErrorIsNil)
c.Assert(metricBatches, gc.HasLen, 1)
c.Assert(metricBatches[0].Credentials(), gc.DeepEquals, []byte("hello there"))
}