Skip to content

Commit a5e85b0

Browse files
committed
Add on_failure property for all actions
1 parent 28524d7 commit a5e85b0

40 files changed

+1051
-418
lines changed

TODO.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ in the future.
4949

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

52-
- introduce action parameter `on_failure` to set what to do when action fails
53-
- it should either fail (default) or skip the rest of sequence
54-
- this is to allow skipping the tests that are for example not applicable on certain configuration
5552
- add typed parameters substitution for integers
5653
- this is to be able to for example parameterize status code
5754
- alternatively it might be easier to allow automatic string to int conversion

conf/parser/factory/actions.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ func (f *NativeActionsFactory) parseExpectationAction(
8181
) (types.Action, error) {
8282
if meta.customName != "" {
8383
return &types.CustomExpectationAction{
84-
Service: meta.serviceName,
85-
When: "on_success",
84+
Service: meta.serviceName,
85+
When: "on_success",
86+
OnFailure: "fail",
8687
Custom: types.CustomExpectation{
8788
Name: meta.customName,
8889
Parameters: data,
@@ -101,6 +102,8 @@ func (f *NativeActionsFactory) parseExpectationAction(
101102
continue
102103
case "when":
103104
continue
105+
case "on_failure":
106+
continue
104107
case "custom":
105108
structure = &types.CustomExpectationAction{Service: meta.serviceName}
106109
case "metrics":

conf/parser/factory/actions_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ func TestNativeActionsFactory_ParseActions(t *testing.T) {
130130
mockParseCalls: nil,
131131
want: []types.Action{
132132
&types.CustomExpectationAction{
133-
Service: "serviceName",
134-
When: "on_success",
133+
Service: "serviceName",
134+
When: "on_success",
135+
OnFailure: "fail",
135136
Custom: types.CustomExpectation{
136137
Name: "customName",
137138
Parameters: map[string]interface{}{"response": "expectedResponse"},

conf/parser/parser_test.go

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,24 +1917,27 @@ func Test_ConfigParser_ParseConfig(t *testing.T) {
19171917
},
19181918
Actions: []types.Action{
19191919
&types.SequentialAction{
1920-
Service: "web_service",
1921-
Timeout: 0,
1922-
When: "on_success",
1923-
Name: "start",
1920+
Service: "web_service",
1921+
Timeout: 0,
1922+
When: "on_success",
1923+
OnFailure: "fail",
1924+
Name: "start",
19241925
},
19251926
&types.RequestAction{
19261927
Service: "web_service",
19271928
Timeout: 0,
19281929
When: "on_success",
1930+
OnFailure: "fail",
19291931
Id: "last",
19301932
Path: "/api/status",
19311933
EncodePath: true,
19321934
Method: "GET",
19331935
},
19341936
&types.CustomExpectationAction{
1935-
Service: "web_service",
1936-
Timeout: 0,
1937-
When: "on_success",
1937+
Service: "web_service",
1938+
Timeout: 0,
1939+
When: "on_success",
1940+
OnFailure: "fail",
19381941
Custom: types.CustomExpectation{
19391942
Name: "status",
19401943
Parameters: types.Parameters{
@@ -1944,9 +1947,10 @@ func Test_ConfigParser_ParseConfig(t *testing.T) {
19441947
},
19451948
},
19461949
&types.CustomExpectationAction{
1947-
Service: "web_service",
1948-
Timeout: 0,
1949-
When: "on_success",
1950+
Service: "web_service",
1951+
Timeout: 0,
1952+
When: "on_success",
1953+
OnFailure: "fail",
19501954
Custom: types.CustomExpectation{
19511955
Name: "status",
19521956
Parameters: types.Parameters{
@@ -1955,9 +1959,10 @@ func Test_ConfigParser_ParseConfig(t *testing.T) {
19551959
},
19561960
},
19571961
&types.ResponseExpectationAction{
1958-
Service: "web_service",
1959-
Timeout: 0,
1960-
When: "on_success",
1962+
Service: "web_service",
1963+
Timeout: 0,
1964+
When: "on_success",
1965+
OnFailure: "fail",
19611966
Response: types.ResponseExpectation{
19621967
Request: "last",
19631968
Body: types.ResponseBody{
@@ -2066,15 +2071,17 @@ func Test_ConfigParser_ParseConfig(t *testing.T) {
20662071
"start": {
20672072
Actions: []types.Action{
20682073
&types.StartAction{
2069-
Service: "svc",
2070-
Services: nil,
2071-
Timeout: 0,
2072-
When: "on_success",
2074+
Service: "svc",
2075+
Services: nil,
2076+
Timeout: 0,
2077+
When: "on_success",
2078+
OnFailure: "fail",
20732079
},
20742080
&types.CustomExpectationAction{
2075-
Service: "svc",
2076-
Timeout: 0,
2077-
When: "on_success",
2081+
Service: "svc",
2082+
Timeout: 0,
2083+
When: "on_success",
2084+
OnFailure: "fail",
20782085
Custom: types.CustomExpectation{
20792086
Name: "status",
20802087
Parameters: types.Parameters{},

conf/types/action.go

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ type CustomExpectation struct {
2020
}
2121

2222
type CustomExpectationAction struct {
23-
Service string `wst:"service"`
24-
Timeout int `wst:"timeout"`
25-
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
26-
Custom CustomExpectation `wst:"custom"`
23+
Service string `wst:"service"`
24+
Timeout int `wst:"timeout"`
25+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
26+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
27+
Custom CustomExpectation `wst:"custom"`
2728
}
2829

2930
type OutputExpectation struct {
@@ -36,10 +37,11 @@ type OutputExpectation struct {
3637
}
3738

3839
type OutputExpectationAction struct {
39-
Service string `wst:"service"`
40-
Timeout int `wst:"timeout"`
41-
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
42-
Output OutputExpectation `wst:"output"`
40+
Service string `wst:"service"`
41+
Timeout int `wst:"timeout"`
42+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
43+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
44+
Output OutputExpectation `wst:"output"`
4345
}
4446

4547
type Headers map[string]string
@@ -58,10 +60,11 @@ type ResponseExpectation struct {
5860
}
5961

6062
type ResponseExpectationAction struct {
61-
Service string `wst:"service"`
62-
Timeout int `wst:"timeout"`
63-
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
64-
Response ResponseExpectation `wst:"response"`
63+
Service string `wst:"service"`
64+
Timeout int `wst:"timeout"`
65+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
66+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
67+
Response ResponseExpectation `wst:"response"`
6568
}
6669

6770
type MetricRule struct {
@@ -76,10 +79,11 @@ type MetricsExpectation struct {
7679
}
7780

7881
type MetricsExpectationAction struct {
79-
Service string `wst:"service"`
80-
Timeout int `wst:"timeout"`
81-
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
82-
Metrics MetricsExpectation `wst:"metrics"`
82+
Service string `wst:"service"`
83+
Timeout int `wst:"timeout"`
84+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
85+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
86+
Metrics MetricsExpectation `wst:"metrics"`
8387
}
8488

8589
type ShellCommand struct {
@@ -95,7 +99,8 @@ type Command interface{}
9599
type ExecuteAction struct {
96100
Service string `wst:"service"`
97101
Timeout int `wst:"timeout"`
98-
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
102+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
103+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
99104
Id string `wst:"id,default=last"`
100105
Command Command `wst:"command,factory=createCommand"`
101106
RenderTemplate bool `wst:"render_template,default=true"`
@@ -106,7 +111,8 @@ type ExecuteAction struct {
106111
type RequestAction struct {
107112
Service string `wst:"service"`
108113
Timeout int `wst:"timeout"`
109-
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
114+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
115+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
110116
Id string `wst:"id,default=last"`
111117
Path string `wst:"path"`
112118
EncodePath bool `wst:"encode_path,default=true"`
@@ -117,7 +123,8 @@ type RequestAction struct {
117123
type BenchAction struct {
118124
Service string `wst:"service"`
119125
Timeout int `wst:"timeout"`
120-
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
126+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
127+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
121128
Id string `wst:"id,default=last"`
122129
Path string `wst:"path"`
123130
Method string `wst:"method,enum=GET|HEAD|DELETE|POST|PUT|PATCH|PURGE,default=GET"`
@@ -127,51 +134,58 @@ type BenchAction struct {
127134
}
128135

129136
type ParallelAction struct {
130-
Actions []Action `wst:"actions,factory=createActions"`
131-
Timeout int `wst:"timeout"`
132-
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
137+
Actions []Action `wst:"actions,factory=createActions"`
138+
Timeout int `wst:"timeout"`
139+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
140+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
133141
}
134142

135143
type SequentialAction struct {
136-
Actions []Action `wst:"actions,factory=createActions"`
137-
Service string `wst:"service"`
138-
Timeout int `wst:"timeout"`
139-
Name string `wst:"name"`
140-
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
144+
Actions []Action `wst:"actions,factory=createActions"`
145+
Service string `wst:"service"`
146+
Timeout int `wst:"timeout"`
147+
Name string `wst:"name"`
148+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
149+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
141150
}
142151

143152
type NotAction struct {
144-
Action Action `wst:"action,factory=createAction"`
145-
Timeout int `wst:"timeout"`
146-
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
153+
Action Action `wst:"action,factory=createAction"`
154+
Timeout int `wst:"timeout"`
155+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
156+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
147157
}
148158

149159
type StartAction struct {
150-
Service string `wst:"service"`
151-
Services []string `wst:"services"`
152-
Timeout int `wst:"timeout"`
153-
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
160+
Service string `wst:"service"`
161+
Services []string `wst:"services"`
162+
Timeout int `wst:"timeout"`
163+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
164+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
154165
}
155166

156167
type ReloadAction struct {
157-
Service string `wst:"service"`
158-
Services []string `wst:"services"`
159-
Timeout int `wst:"timeout"`
160-
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
168+
Service string `wst:"service"`
169+
Services []string `wst:"services"`
170+
Timeout int `wst:"timeout"`
171+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
172+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
161173
}
162174

163175
type RestartAction struct {
164-
Service string `wst:"service"`
165-
Services []string `wst:"services"`
166-
Timeout int `wst:"timeout"`
167-
When string `wst:"when,enum=always|on_success|on_fail,default=on_success"`
176+
Service string `wst:"service"`
177+
Services []string `wst:"services"`
178+
Timeout int `wst:"timeout"`
179+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
180+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
168181
}
169182

170183
type StopAction struct {
171-
Service string `wst:"service"`
172-
Services []string `wst:"services"`
173-
Timeout int `wst:"timeout"`
174-
When string `wst:"when,enum=always|on_success|on_fail,default=always"`
184+
Service string `wst:"service"`
185+
Services []string `wst:"services"`
186+
Timeout int `wst:"timeout"`
187+
When string `wst:"when,enum=always|on_success|on_failure,default=always"`
188+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
175189
}
176190

177191
type Action interface {

mocks/generated/run/actions/action/mock_Action.go

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

run/actions/action/action.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Action interface {
2626
Execute(ctx context.Context, runData runtime.Data) (bool, error)
2727
Timeout() time.Duration
2828
When() When
29+
OnFailure() OnFailureType
2930
}
3031

3132
type Maker interface {
@@ -39,3 +40,11 @@ const (
3940
OnSuccess When = "on_success"
4041
OnFailure When = "on_failure"
4142
)
43+
44+
type OnFailureType string
45+
46+
const (
47+
Fail OnFailureType = "fail"
48+
Ignore OnFailureType = "ignore"
49+
Skip OnFailureType = "skip"
50+
)

0 commit comments

Comments
 (0)