1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package testing
import (
"github.com/juju/errors"
)
// ActionHook holds the values for the hook context.
type ActionHook struct {
ActionParams map[string]interface{}
}
// ContextActionHook is a test double for jujuc.ActionHookContext.
type ContextActionHook struct {
contextBase
info *ActionHook
}
// ActionParams implements jujuc.ActionHookContext.
func (c *ContextActionHook) ActionParams() (map[string]interface{}, error) {
c.stub.AddCall("ActionParams")
if err := c.stub.NextErr(); err != nil {
return nil, errors.Trace(err)
}
if c.info.ActionParams == nil {
return nil, errors.Errorf("not running an action")
}
return c.info.ActionParams, nil
}
// UpdateActionResults implements jujuc.ActionHookContext.
func (c *ContextActionHook) UpdateActionResults(keys []string, value string) error {
c.stub.AddCall("UpdateActionResults", keys, value)
if err := c.stub.NextErr(); err != nil {
return errors.Trace(err)
}
if c.info.ActionParams == nil {
return errors.Errorf("not running an action")
}
return nil
}
// SetActionMessage implements jujuc.ActionHookContext.
func (c *ContextActionHook) SetActionMessage(message string) error {
c.stub.AddCall("SetActionMessage", message)
if err := c.stub.NextErr(); err != nil {
return errors.Trace(err)
}
if c.info.ActionParams == nil {
return errors.Errorf("not running an action")
}
return nil
}
// SetActionFailed implements jujuc.ActionHookContext.
func (c *ContextActionHook) SetActionFailed() error {
c.stub.AddCall("SetActionFailed")
if err := c.stub.NextErr(); err != nil {
return errors.Trace(err)
}
if c.info.ActionParams == nil {
return errors.Errorf("not running an action")
}
return nil
}
|