Exemplo n.º 1
0
func (payloads) registerHookContextCommands() {
	if !markRegistered(payload.ComponentName, "hook-context-commands") {
		return
	}

	jujuc.RegisterCommand(context.RegisterCmdName, func(ctx jujuc.Context) (cmd.Command, error) {
		compCtx := payloadsHookContext{ctx}
		cmd, err := context.NewRegisterCmd(compCtx)
		if err != nil {
			return nil, errors.Trace(err)
		}
		return cmd, nil
	})

	jujuc.RegisterCommand(context.StatusSetCmdName, func(ctx jujuc.Context) (cmd.Command, error) {
		compCtx := payloadsHookContext{ctx}
		cmd, err := context.NewStatusSetCmd(compCtx)
		if err != nil {
			return nil, errors.Trace(err)
		}
		return cmd, nil
	})

	jujuc.RegisterCommand(context.UnregisterCmdName, func(ctx jujuc.Context) (cmd.Command, error) {
		compCtx := payloadsHookContext{ctx}
		cmd, err := context.NewUnregisterCmd(compCtx)
		if err != nil {
			return nil, errors.Trace(err)
		}
		return cmd, nil
	})
}
Exemplo n.º 2
0
func (s *unregisterSuite) TestHelp(c *gc.C) {
	unregister, err := context.NewUnregisterCmd(s)
	c.Assert(err, jc.ErrorIsNil)
	code := cmd.Main(unregister, s.ctx, []string{"--help"})
	c.Assert(code, gc.Equals, 0)

	c.Check(s.ctx.Stdout.(*bytes.Buffer).String(), gc.Equals, `
usage: payload-unregister <class> <id>
purpose: stop tracking a payload

"payload-unregister" is used while a hook is running to let Juju know
that a payload has been manually stopped. The <class> and <id> provided
must match a payload that has been previously registered with juju using
payload-register.
`[1:])
}
Exemplo n.º 3
0
func (s *unregisterSuite) TestRunOkay(c *gc.C) {
	unregister, err := context.NewUnregisterCmd(s)
	c.Assert(err, jc.ErrorIsNil)
	err = unregister.Init([]string{"spam", "eggs"})
	c.Assert(err, jc.ErrorIsNil)
	err = unregister.Run(s.ctx)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCalls(c, []testing.StubCall{{
		FuncName: "Component",
		Args: []interface{}{
			payload.ComponentName,
		},
	}, {
		FuncName: "Untrack",
		Args: []interface{}{
			"spam",
			"eggs",
		},
	}, {
		FuncName: "Flush",
	}})
}