本文整理汇总了Golang中github.com/juju/juju/state.NowToTheSecond函数的典型用法代码示例。如果您正苦于以下问题:Golang NowToTheSecond函数的具体用法?Golang NowToTheSecond怎么用?Golang NowToTheSecond使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NowToTheSecond函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:imoapps,项目名称:juju,代码行数:32,代码来源:envuser_test.go
示例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`)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:7,代码来源:metrics_test.go
示例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)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:29,代码来源:metrics_test.go
示例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)
}
开发者ID:zhouqt,项目名称:juju,代码行数:25,代码来源:envuser_test.go
示例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)
}
开发者ID:exekias,项目名称:juju,代码行数:32,代码来源:metrics_test.go
示例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")
}
开发者ID:imoapps,项目名称:juju,代码行数:25,代码来源:metrics_test.go
示例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"))
}
开发者ID:kapilt,项目名称:juju,代码行数:29,代码来源:metrics_test.go
示例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)
}
开发者ID:kat-co,项目名称:juju,代码行数:26,代码来源:migration_import_test.go
示例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)
}
开发者ID:imoapps,项目名称:juju,代码行数:59,代码来源:metrics_test.go
示例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`)
}
开发者ID:kapilt,项目名称:juju,代码行数:8,代码来源:metrics_test.go
示例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`)
}
开发者ID:zhouqt,项目名称:juju,代码行数:8,代码来源:metrics_test.go
示例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")
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:9,代码来源:metrics_test.go
示例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)
}
开发者ID:imoapps,项目名称:juju,代码行数:10,代码来源:metrics_test.go
示例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")
}
开发者ID:imoapps,项目名称:juju,代码行数:11,代码来源:metrics_test.go
示例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"))
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:12,代码来源:metrics_test.go
示例16: TestUpdateLastConnection
func (s *EnvUserSuite) TestUpdateLastConnection(c *gc.C) {
now := state.NowToTheSecond()
createdBy := s.factory.MakeUser(c, &factory.UserParams{Name: "createdby"})
user := s.factory.MakeUser(c, &factory.UserParams{Name: "validusername", Creator: createdBy.Name()})
envUser, err := s.State.EnvironmentUser(user.UserTag())
c.Assert(err, gc.IsNil)
err = envUser.UpdateLastConnection()
c.Assert(err, gc.IsNil)
// It is possible that the update is done over a second boundary, so we need
// to check for after now as well as equal.
c.Assert(envUser.LastConnection().After(now) ||
envUser.LastConnection().Equal(now), jc.IsTrue)
}
开发者ID:zhouqt,项目名称:juju,代码行数:13,代码来源:envuser_test.go
示例17: TestMetricBatches
func (s *MetricSuite) TestMetricBatches(c *gc.C) {
now := state.NowToTheSecond()
m := state.Metric{"pings", "5", now}
_, 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].Unit(), gc.Equals, "metered/0")
c.Assert(metricBatches[0].CharmURL(), gc.Equals, "cs:quantal/metered")
c.Assert(metricBatches[0].Sent(), jc.IsFalse)
c.Assert(metricBatches[0].Metrics(), gc.HasLen, 1)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:13,代码来源:metrics_test.go
示例18: TestSetMetricSent
func (s *MetricSuite) TestSetMetricSent(c *gc.C) {
now := state.NowToTheSecond()
m := state.Metric{"pings", "5", now}
added, err := s.unit.AddMetrics(utils.MustNewUUID().String(), now, "", []state.Metric{m})
c.Assert(err, jc.ErrorIsNil)
saved, err := s.State.MetricBatch(added.UUID())
c.Assert(err, jc.ErrorIsNil)
err = saved.SetSent()
c.Assert(err, jc.ErrorIsNil)
c.Assert(saved.Sent(), jc.IsTrue)
saved, err = s.State.MetricBatch(added.UUID())
c.Assert(err, jc.ErrorIsNil)
c.Assert(saved.Sent(), jc.IsTrue)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:14,代码来源:metrics_test.go
示例19: TestUpdateLastConnection
func (s *ModelUserSuite) TestUpdateLastConnection(c *gc.C) {
now := state.NowToTheSecond()
createdBy := s.Factory.MakeUser(c, &factory.UserParams{Name: "createdby"})
user := s.Factory.MakeUser(c, &factory.UserParams{Name: "validusername", Creator: createdBy.Tag()})
modelUser, err := s.State.ModelUser(user.UserTag())
c.Assert(err, jc.ErrorIsNil)
err = modelUser.UpdateLastConnection()
c.Assert(err, jc.ErrorIsNil)
when, err := modelUser.LastConnection()
c.Assert(err, jc.ErrorIsNil)
// It is possible that the update is done over a second boundary, so we need
// to check for after now as well as equal.
c.Assert(when.After(now) || when.Equal(now), jc.IsTrue)
}
开发者ID:exekias,项目名称:juju,代码行数:14,代码来源:modeluser_test.go
示例20: TestSetMetricSent
func (s *MetricSuite) TestSetMetricSent(c *gc.C) {
unit := s.assertAddUnit(c)
now := state.NowToTheSecond()
m := state.NewMetric("item", "5", now, []byte{})
added, err := unit.AddMetrics([]*state.Metric{m})
c.Assert(err, gc.IsNil)
saved, err := s.State.MetricBatch(added.UUID())
c.Assert(err, gc.IsNil)
err = saved.SetSent()
c.Assert(err, gc.IsNil)
c.Assert(saved.Sent(), jc.IsTrue)
saved, err = s.State.MetricBatch(added.UUID())
c.Assert(err, gc.IsNil)
c.Assert(saved.Sent(), jc.IsTrue)
}
开发者ID:kapilt,项目名称:juju,代码行数:15,代码来源:metrics_test.go
注:本文中的github.com/juju/juju/state.NowToTheSecond函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论