本文整理汇总了Golang中github.com/juju/juju/cmd/juju/metricsdebug.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUnits
func (s *cmdMetricsCommandSuite) TestUnits(c *gc.C) {
meteredCharm := s.Factory.MakeCharm(c, &factory.CharmParams{Name: "metered", URL: "local:quantal/metered"})
meteredService := s.Factory.MakeApplication(c, &factory.ApplicationParams{Charm: meteredCharm})
unit := s.Factory.MakeUnit(c, &factory.UnitParams{Application: meteredService, SetCharmURL: true})
unit2 := s.Factory.MakeUnit(c, &factory.UnitParams{Application: meteredService, SetCharmURL: true})
newTime1 := time.Now().Round(time.Second)
newTime2 := newTime1.Add(time.Second)
metricA := state.Metric{"pings", "5", newTime1}
metricB := state.Metric{"pings", "10.5", newTime2}
s.Factory.MakeMetric(c, &factory.MetricParams{Unit: unit, Metrics: []state.Metric{metricA}})
s.Factory.MakeMetric(c, &factory.MetricParams{Unit: unit2, Metrics: []state.Metric{metricA, metricB}})
ctx, err := coretesting.RunCommand(c, metricsdebug.New(), "metered/1")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cmdtesting.Stdout(ctx), gc.Equals,
formatTabular(metric{
Unit: unit2.Name(),
Timestamp: newTime2,
Metric: "pings",
Value: "10.5",
}),
)
ctx, err = coretesting.RunCommand(c, metricsdebug.New(), "metered/0")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cmdtesting.Stdout(ctx), gc.Equals,
formatTabular(metric{
Unit: unit.Name(),
Timestamp: newTime1,
Metric: "pings",
Value: "5",
}),
)
}
示例2: TestUnitJsonOutput
func (s *DebugMetricsCommandSuite) TestUnitJsonOutput(c *gc.C) {
meteredCharm := s.Factory.MakeCharm(c, &factory.CharmParams{Name: "metered", URL: "local:quantal/metered"})
meteredService := s.Factory.MakeService(c, &factory.ServiceParams{Charm: meteredCharm})
unit := s.Factory.MakeUnit(c, &factory.UnitParams{Service: meteredService, SetCharmURL: true})
newTime := time.Now().Round(time.Second)
metricA := state.Metric{"pings", "5", newTime}
metricB := state.Metric{"pings", "10.5", newTime}
s.Factory.MakeMetric(c, &factory.MetricParams{Unit: unit, Metrics: []state.Metric{metricA}})
s.Factory.MakeMetric(c, &factory.MetricParams{Unit: unit, Metrics: []state.Metric{metricA, metricB}})
outputTime := newTime.Format(time.RFC3339)
expectedOutput := fmt.Sprintf(`[
{
"time": "%v",
"key": "pings",
"value": "5"
},
{
"time": "%v",
"key": "pings",
"value": "5"
},
{
"time": "%v",
"key": "pings",
"value": "10.5"
}
]`, outputTime, outputTime, outputTime)
ctx, err := coretesting.RunCommand(c, metricsdebug.New(), "metered/0", "--json")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cmdtesting.Stdout(ctx), gc.Equals, expectedOutput)
}
示例3: TestYAMLFormat
func (s *metricsSuite) TestYAMLFormat(c *gc.C) {
s.client.metrics = []params.MetricResult{{
Unit: "unit-metered-0",
Key: "pings",
Value: "5.0",
Time: time.Date(2016, 8, 22, 12, 02, 03, 0, time.UTC),
}, {
Unit: "unit-metered-0",
Key: "pongs",
Value: "15.0",
Time: time.Date(2016, 8, 22, 12, 02, 04, 0, time.UTC),
}}
ctx, err := coretesting.RunCommand(c, metricsdebug.New(), "metered", "--format", "yaml")
c.Assert(err, jc.ErrorIsNil)
s.client.CheckCall(c, 0, "GetMetrics", []string{"application-metered"})
c.Assert(cmdtesting.Stdout(ctx), gc.Equals, `- unit: unit-metered-0
timestamp: 2016-08-22T12:02:03Z
metric: pings
value: "5.0"
- unit: unit-metered-0
timestamp: 2016-08-22T12:02:04Z
metric: pongs
value: "15.0"
`)
}
示例4: TestNotValidServiceOrUnit
func (s *DebugMetricsMockSuite) TestNotValidServiceOrUnit(c *gc.C) {
client := MockGetMetricsClient{testing.Stub{}}
s.PatchValue(metricsdebug.NewClient, func(_ modelcmd.ModelCommandBase) (metricsdebug.GetMetricsClient, error) {
return &client, nil
})
_, err := coretesting.RunCommand(c, metricsdebug.New(), "!!!!!!")
c.Assert(err, gc.ErrorMatches, `"!!!!!!" is not a valid unit or service`)
}
示例5: TestNoMetrics
func (s *DebugMetricsCommandSuite) TestNoMetrics(c *gc.C) {
meteredCharm := s.Factory.MakeCharm(c, &factory.CharmParams{Name: "metered", URL: "local:quantal/metered"})
meteredService := s.Factory.MakeService(c, &factory.ServiceParams{Charm: meteredCharm})
s.Factory.MakeUnit(c, &factory.UnitParams{Service: meteredService, SetCharmURL: true})
ctx, err := coretesting.RunCommand(c, metricsdebug.New(), "metered", "-n", "2")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cmdtesting.Stdout(ctx), gc.Equals, "")
}
示例6: TestService
func (s *DebugMetricsMockSuite) TestService(c *gc.C) {
client := MockGetMetricsClient{testing.Stub{}}
s.PatchValue(metricsdebug.NewClient, func(_ modelcmd.ModelCommandBase) (metricsdebug.GetMetricsClient, error) {
return &client, nil
})
_, err := coretesting.RunCommand(c, metricsdebug.New(), "metered")
c.Assert(err, jc.ErrorIsNil)
client.CheckCall(c, 0, "GetMetrics", "service-metered")
}
示例7: TestDefaultTabulatFormat
func (s *metricsSuite) TestDefaultTabulatFormat(c *gc.C) {
s.client.metrics = []params.MetricResult{{
Unit: "unit-metered-0",
Key: "pings",
Value: "5.0",
Time: time.Date(2016, 8, 22, 12, 02, 03, 0, time.UTC),
}, {
Unit: "unit-metered-0",
Key: "pongs",
Value: "15.0",
Time: time.Date(2016, 8, 22, 12, 02, 04, 0, time.UTC),
}}
ctx, err := coretesting.RunCommand(c, metricsdebug.New(), "metered/0")
c.Assert(err, jc.ErrorIsNil)
s.client.CheckCall(c, 0, "GetMetrics", []string{"unit-metered-0"})
c.Assert(cmdtesting.Stdout(ctx), gc.Equals, `UNIT TIMESTAMP METRIC VALUE
unit-metered-0 2016-08-22T12:02:03Z pings 5.0
unit-metered-0 2016-08-22T12:02:04Z pongs 15.0
`)
}
示例8: TestUnits
func (s *DebugMetricsCommandSuite) TestUnits(c *gc.C) {
meteredCharm := s.Factory.MakeCharm(c, &factory.CharmParams{Name: "metered", URL: "local:quantal/metered"})
meteredService := s.Factory.MakeService(c, &factory.ServiceParams{Charm: meteredCharm})
unit := s.Factory.MakeUnit(c, &factory.UnitParams{Service: meteredService, SetCharmURL: true})
unit2 := s.Factory.MakeUnit(c, &factory.UnitParams{Service: meteredService, SetCharmURL: true})
newTime := time.Now().Round(time.Second)
metricA := state.Metric{"pings", "5", newTime}
metricB := state.Metric{"pings", "10.5", newTime}
s.Factory.MakeMetric(c, &factory.MetricParams{Unit: unit, Metrics: []state.Metric{metricA}})
s.Factory.MakeMetric(c, &factory.MetricParams{Unit: unit2, Metrics: []state.Metric{metricA, metricB}})
outputTime := newTime.Format(time.RFC3339)
expectedOutput := bytes.Buffer{}
tw := tabwriter.NewWriter(&expectedOutput, 0, 1, 1, ' ', 0)
fmt.Fprintf(tw, "TIME\tMETRIC\tVALUE\n")
fmt.Fprintf(tw, "%v\tpings\t5\n", outputTime)
fmt.Fprintf(tw, "%v\tpings\t10.5\n", outputTime)
tw.Flush()
ctx, err := coretesting.RunCommand(c, metricsdebug.New(), "metered/1")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cmdtesting.Stdout(ctx), gc.Equals, expectedOutput.String())
}
示例9: registerCommands
// registerCommands registers commands in the specified registry.
func registerCommands(r commandRegistry, ctx *cmd.Context) {
// Creation commands.
r.Register(newBootstrapCommand())
r.Register(application.NewAddRelationCommand())
// Destruction commands.
r.Register(application.NewRemoveRelationCommand())
r.Register(application.NewRemoveServiceCommand())
r.Register(application.NewRemoveUnitCommand())
// Reporting commands.
r.Register(status.NewStatusCommand())
r.Register(newSwitchCommand())
r.Register(status.NewStatusHistoryCommand())
// Error resolution and debugging commands.
r.Register(newRunCommand())
r.Register(newSCPCommand())
r.Register(newSSHCommand())
r.Register(newResolvedCommand())
r.Register(newDebugLogCommand())
r.Register(newDebugHooksCommand())
// Configuration commands.
r.Register(model.NewModelGetConstraintsCommand())
r.Register(model.NewModelSetConstraintsCommand())
r.Register(newSyncToolsCommand())
r.Register(newUpgradeJujuCommand(nil))
r.Register(application.NewUpgradeCharmCommand())
// Charm tool commands.
r.Register(newHelpToolCommand())
r.Register(charmcmd.NewSuperCommand())
// Manage backups.
r.Register(backups.NewCreateCommand())
r.Register(backups.NewDownloadCommand())
r.Register(backups.NewShowCommand())
r.Register(backups.NewListCommand())
r.Register(backups.NewRemoveCommand())
r.Register(backups.NewRestoreCommand())
r.Register(backups.NewUploadCommand())
// Manage authorized ssh keys.
r.Register(NewAddKeysCommand())
r.Register(NewRemoveKeysCommand())
r.Register(NewImportKeysCommand())
r.Register(NewListKeysCommand())
// Manage users and access
r.Register(user.NewAddCommand())
r.Register(user.NewChangePasswordCommand())
r.Register(user.NewShowUserCommand())
r.Register(user.NewListCommand())
r.Register(user.NewEnableCommand())
r.Register(user.NewDisableCommand())
r.Register(user.NewLoginCommand())
r.Register(user.NewLogoutCommand())
r.Register(user.NewRemoveCommand())
r.Register(user.NewWhoAmICommand())
// Manage cached images
r.Register(cachedimages.NewRemoveCommand())
r.Register(cachedimages.NewListCommand())
// Manage machines
r.Register(machine.NewAddCommand())
r.Register(machine.NewRemoveCommand())
r.Register(machine.NewListMachinesCommand())
r.Register(machine.NewShowMachineCommand())
// Manage model
r.Register(model.NewConfigCommand())
r.Register(model.NewDefaultsCommand())
r.Register(model.NewRetryProvisioningCommand())
r.Register(model.NewDestroyCommand())
r.Register(model.NewGrantCommand())
r.Register(model.NewRevokeCommand())
r.Register(model.NewShowCommand())
if featureflag.Enabled(feature.Migration) {
r.Register(newMigrateCommand())
}
if featureflag.Enabled(feature.DeveloperMode) {
r.Register(model.NewDumpCommand())
r.Register(model.NewDumpDBCommand())
}
// Manage and control actions
r.Register(action.NewStatusCommand())
r.Register(action.NewRunCommand())
r.Register(action.NewShowOutputCommand())
r.Register(action.NewListCommand())
// Manage controller availability
r.Register(newEnableHACommand())
// Manage and control services
r.Register(application.NewAddUnitCommand())
//.........这里部分代码省略.........
示例10: TestDebugNoArgs
func (s *DebugMetricsCommandSuite) TestDebugNoArgs(c *gc.C) {
_, err := coretesting.RunCommand(c, metricsdebug.New())
c.Assert(err, gc.ErrorMatches, "you need to specify a unit or service.")
}
示例11: TestDebugNoArgs
func (s *cmdMetricsCommandSuite) TestDebugNoArgs(c *gc.C) {
_, err := coretesting.RunCommand(c, metricsdebug.New())
c.Assert(err, gc.ErrorMatches, "you need to specify at least one unit or application")
}
示例12: registerCommands
// registerCommands registers commands in the specified registry.
func registerCommands(r commandRegistry, ctx *cmd.Context) {
// Creation commands.
r.Register(newBootstrapCommand())
r.Register(service.NewAddRelationCommand())
// Destruction commands.
r.Register(service.NewRemoveRelationCommand())
r.Register(service.NewRemoveServiceCommand())
r.Register(service.NewRemoveUnitCommand())
// Reporting commands.
r.Register(status.NewStatusCommand())
r.Register(newSwitchCommand())
r.Register(newEndpointCommand())
r.Register(newAPIInfoCommand())
r.Register(status.NewStatusHistoryCommand())
// Error resolution and debugging commands.
r.Register(newRunCommand())
r.Register(newSCPCommand())
r.Register(newSSHCommand())
r.Register(newResolvedCommand())
r.Register(newDebugLogCommand())
r.Register(newDebugHooksCommand())
// Configuration commands.
r.Register(newInitCommand())
r.Register(model.NewModelGetConstraintsCommand())
r.Register(model.NewModelSetConstraintsCommand())
r.Register(newSyncToolsCommand())
r.Register(newUpgradeJujuCommand(nil))
r.Register(service.NewUpgradeCharmCommand())
// Charm publishing commands.
r.Register(newPublishCommand())
// Charm tool commands.
r.Register(newHelpToolCommand())
r.Register(charmcmd.NewSuperCommand())
// Manage backups.
r.Register(backups.NewSuperCommand())
r.RegisterSuperAlias("create-backup", "backups", "create", nil)
r.RegisterSuperAlias("restore-backup", "backups", "restore", nil)
// Manage authorized ssh keys.
r.Register(NewAddKeysCommand())
r.Register(NewRemoveKeysCommand())
r.Register(NewImportKeysCommand())
r.Register(NewListKeysCommand())
// Manage users and access
r.Register(user.NewAddCommand())
r.Register(user.NewChangePasswordCommand())
r.Register(user.NewCredentialsCommand())
r.Register(user.NewShowUserCommand())
r.Register(user.NewListCommand())
r.Register(user.NewEnableCommand())
r.Register(user.NewDisableCommand())
// Manage cached images
r.Register(cachedimages.NewSuperCommand())
// Manage machines
r.Register(machine.NewAddCommand())
r.Register(machine.NewRemoveCommand())
r.Register(machine.NewListMachinesCommand())
r.Register(machine.NewShowMachineCommand())
// Manage model
r.Register(model.NewGetCommand())
r.Register(model.NewSetCommand())
r.Register(model.NewUnsetCommand())
r.Register(model.NewRetryProvisioningCommand())
r.Register(model.NewDestroyCommand())
r.Register(model.NewShareCommand())
r.Register(model.NewUnshareCommand())
r.Register(model.NewUsersCommand())
// Manage and control actions
r.Register(action.NewSuperCommand())
r.RegisterSuperAlias("run-action", "action", "do", nil)
r.RegisterSuperAlias("list-actions", "action", "defined", nil)
r.RegisterSuperAlias("show-action-output", "action", "fetch", nil)
r.RegisterSuperAlias("show-action-status", "action", "status", nil)
// Manage controller availability
r.Register(newEnableHACommand())
// Manage and control services
r.Register(service.NewAddUnitCommand())
r.Register(service.NewGetCommand())
r.Register(service.NewSetCommand())
r.Register(service.NewDeployCommand())
r.Register(service.NewExposeCommand())
r.Register(service.NewUnexposeCommand())
r.Register(service.NewServiceGetConstraintsCommand())
r.Register(service.NewServiceSetConstraintsCommand())
//.........这里部分代码省略.........
示例13: TestAPIClientError
func (s *metricsSuite) TestAPIClientError(c *gc.C) {
s.client.SetErrors(errors.New("a silly error"))
_, err := coretesting.RunCommand(c, metricsdebug.New(), "metered/0")
c.Assert(err, gc.ErrorMatches, `a silly error`)
}
示例14: TestInvalidUnitName
func (s *metricsSuite) TestInvalidUnitName(c *gc.C) {
_, err := coretesting.RunCommand(c, metricsdebug.New(), "metered-/0")
c.Assert(err, gc.ErrorMatches, `"metered-/0" is not a valid unit or application`)
}
示例15: TestAllWithExtraArgs
func (s *metricsSuite) TestAllWithExtraArgs(c *gc.C) {
_, err := coretesting.RunCommand(c, metricsdebug.New(), "--all", "metered")
c.Assert(err, gc.ErrorMatches, "cannot use --all with additional entities")
}