Skip to content

Commit 3970764

Browse files
committed
Add command action
1 parent 674c663 commit 3970764

File tree

23 files changed

+989
-39
lines changed

23 files changed

+989
-39
lines changed

.mockery.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ packages:
5858
dir: mocks/generated/run/actions/action/bench
5959
interfaces:
6060
Maker: {}
61+
github.com/wstool/wst/run/actions/action/command:
62+
config:
63+
dir: mocks/generated/run/actions/action/command
64+
interfaces:
65+
Maker: {}
6166
github.com/wstool/wst/run/actions/action/expect:
6267
config:
6368
dir: mocks/generated/run/actions/action/expect

TODO.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ in the future.
4949

5050
#### Structure - Instances, Actions, Servers, Services
5151

52-
- introduce new command action and make it work with output
52+
- add command expectation for checking its output
5353
- look into doing some partial expectation
5454
- some sort of contains mode rather than full match
5555
- introduce action parameter `on_failure` to set what to do when action fails
@@ -71,6 +71,8 @@ in the future.
7171
- support metrics server expectation
7272
- custom server actions for parallel and not action
7373
- this is mainly for completeness with sequential and might be also useful in some cases
74+
- add command action custom environment variables support
75+
- should be an action map parameter
7476
- look into default action service integration
7577
- it should be basically service defined in parent (e.g. sequential service) and used if no service is defined for the action
7678
- it could be then used in the string form like `expect//name`

conf/parser/factory/functions.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ func (f *FuncProvider) GetFactoryFunc(funcName string) (Func, error) {
5757
return f.createAction, nil
5858
case "createActions":
5959
return f.createActions, nil
60+
case "createCommand":
61+
return f.createCommand, nil
6062
case "createContainerImage":
6163
return f.createContainerImage, nil
6264
case "createEnvironments":
@@ -104,6 +106,26 @@ func (f *FuncProvider) createActions(data interface{}, fieldValue reflect.Value,
104106
return nil
105107
}
106108

109+
func (f *FuncProvider) createCommand(data interface{}, fieldValue reflect.Value, path string) error {
110+
var command types.Command
111+
switch v := data.(type) {
112+
case string:
113+
command = types.ShellCommand{
114+
Command: v,
115+
}
116+
case []string:
117+
command = types.ArgsCommand{
118+
Args: v,
119+
}
120+
default:
121+
return errors.Errorf("unsupported type for command data at %s", f.loc.String())
122+
}
123+
124+
fieldValue.Set(reflect.ValueOf(command))
125+
126+
return nil
127+
}
128+
107129
func (f *FuncProvider) createContainerImage(data interface{}, fieldValue reflect.Value, path string) error {
108130
img := types.ContainerImage{}
109131
switch v := data.(type) {

conf/types/action.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,26 @@ type MetricsExpectationAction struct {
8181
Metrics MetricsExpectation `wst:"metrics"`
8282
}
8383

84+
type ShellCommand struct {
85+
Command string
86+
}
87+
88+
type ArgsCommand struct {
89+
Args []string
90+
}
91+
92+
type Command interface{}
93+
94+
type CommandAction struct {
95+
Service string `wst:"service"`
96+
Timeout int `wst:"timeout"`
97+
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
98+
Id string `wst:"id,default=last"`
99+
Command Command `wst:"command,factory=createCommand"`
100+
Shell string `wst:"shell,default=/bin/sh"`
101+
Env map[string]string `wst:"env"`
102+
}
103+
84104
type RequestAction struct {
85105
Service string `wst:"service"`
86106
Timeout int `wst:"timeout"`

mocks/generated/run/actions/action/command/mock_Maker.go

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/generated/run/environments/environment/mock_Environment.go

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/generated/run/services/mock_Service.go

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)