1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"github.com/juju/errors"
10
// ActionHook holds the values for the hook context.
11
type ActionHook struct {
12
ActionParams map[string]interface{}
15
// ContextActionHook is a test double for jujuc.ActionHookContext.
16
type ContextActionHook struct {
21
// ActionParams implements jujuc.ActionHookContext.
22
func (c *ContextActionHook) ActionParams() (map[string]interface{}, error) {
23
c.stub.AddCall("ActionParams")
24
if err := c.stub.NextErr(); err != nil {
25
return nil, errors.Trace(err)
28
if c.info.ActionParams == nil {
29
return nil, errors.Errorf("not running an action")
31
return c.info.ActionParams, nil
34
// UpdateActionResults implements jujuc.ActionHookContext.
35
func (c *ContextActionHook) UpdateActionResults(keys []string, value string) error {
36
c.stub.AddCall("UpdateActionResults", keys, value)
37
if err := c.stub.NextErr(); err != nil {
38
return errors.Trace(err)
41
if c.info.ActionParams == nil {
42
return errors.Errorf("not running an action")
47
// SetActionMessage implements jujuc.ActionHookContext.
48
func (c *ContextActionHook) SetActionMessage(message string) error {
49
c.stub.AddCall("SetActionMessage", message)
50
if err := c.stub.NextErr(); err != nil {
51
return errors.Trace(err)
54
if c.info.ActionParams == nil {
55
return errors.Errorf("not running an action")
60
// SetActionFailed implements jujuc.ActionHookContext.
61
func (c *ContextActionHook) SetActionFailed() error {
62
c.stub.AddCall("SetActionFailed")
63
if err := c.stub.NextErr(); err != nil {
64
return errors.Trace(err)
67
if c.info.ActionParams == nil {
68
return errors.Errorf("not running an action")