Skip to content

Commit d2db150

Browse files
committed
Add retry interval
1 parent 6e5d39b commit d2db150

File tree

3 files changed

+40
-26
lines changed

3 files changed

+40
-26
lines changed

pkg/runtime/runtime.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ type TestCase struct {
3636

3737
//TestConfig represents the configuration for a test
3838
type TestConfig struct {
39-
Env map[string]string
40-
Dir string
41-
Timeout string
42-
Retries int
39+
Env map[string]string
40+
Dir string
41+
Timeout string
42+
Retries int
43+
Interval string
4344
}
4445

4546
// ResultStatus represents the status code of a test result
@@ -74,11 +75,12 @@ type ExpectedOut struct {
7475

7576
// CommandUnderTest represents the command under test
7677
type CommandUnderTest struct {
77-
Cmd string
78-
Env map[string]string
79-
Dir string
80-
Timeout string
81-
Retries int
78+
Cmd string
79+
Env map[string]string
80+
Dir string
81+
Timeout string
82+
Retries int
83+
Interval string
8284
}
8385

8486
// TestResult represents the TestCase and the ValidationResult

pkg/suite/yaml_suite.go

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ type YAMLConfig struct {
1515

1616
// YAMLTestConfig is a struct to represent the test config
1717
type YAMLTestConfig struct {
18-
Env map[string]string `yaml:"env,omitempty"`
19-
Dir string `yaml:"dir,omitempty"`
20-
Timeout string `yaml:"timeout,omitempty"`
21-
Retries int `yaml:"retries,omitempty"`
18+
Env map[string]string `yaml:"env,omitempty"`
19+
Dir string `yaml:"dir,omitempty"`
20+
Timeout string `yaml:"timeout,omitempty"`
21+
Retries int `yaml:"retries,omitempty"`
22+
Interval string `yaml:"interval,omitempty"`
2223
}
2324

2425
// YAMLTest represents a test in the yaml test suite
@@ -69,10 +70,11 @@ func ParseYAML(content []byte) Suite {
6970
return YAMLSuite{
7071
TestCases: convertYAMLConfToTestCases(yamlConfig),
7172
Config: runtime.TestConfig{
72-
Env: yamlConfig.Config.Env,
73-
Dir: yamlConfig.Config.Dir,
74-
Timeout: yamlConfig.Config.Timeout,
75-
Retries: yamlConfig.Config.Retries,
73+
Env: yamlConfig.Config.Env,
74+
Dir: yamlConfig.Config.Dir,
75+
Timeout: yamlConfig.Config.Timeout,
76+
Retries: yamlConfig.Config.Retries,
77+
Interval: yamlConfig.Config.Interval,
7678
},
7779
}
7880
}
@@ -84,11 +86,12 @@ func convertYAMLConfToTestCases(conf YAMLConfig) []runtime.TestCase {
8486
tests = append(tests, runtime.TestCase{
8587
Title: t.Title,
8688
Command: runtime.CommandUnderTest{
87-
Cmd: t.Command,
88-
Env: t.Config.Env,
89-
Dir: t.Config.Dir,
90-
Timeout: t.Config.Timeout,
91-
Retries: t.Config.Retries,
89+
Cmd: t.Command,
90+
Env: t.Config.Env,
91+
Dir: t.Config.Dir,
92+
Timeout: t.Config.Timeout,
93+
Retries: t.Config.Retries,
94+
Interval: t.Config.Interval,
9295
},
9396
Expected: runtime.Expected{
9497
ExitCode: t.ExitCode,
@@ -140,10 +143,11 @@ func (y *YAMLConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
140143

141144
//Parse global configuration
142145
y.Config = YAMLTestConfig{
143-
Env: params.Config.Env,
144-
Dir: params.Config.Dir,
145-
Timeout: params.Config.Timeout,
146-
Retries: params.Config.Retries,
146+
Env: params.Config.Env,
147+
Dir: params.Config.Dir,
148+
Timeout: params.Config.Timeout,
149+
Retries: params.Config.Retries,
150+
Interval: params.Config.Interval,
147151
}
148152

149153
return nil
@@ -239,6 +243,10 @@ func (y *YAMLConfig) mergeConfigs(local YAMLTestConfig, global YAMLTestConfig) Y
239243
conf.Retries = local.Retries
240244
}
241245

246+
if local.Interval != "" {
247+
conf.Interval = local.Interval
248+
}
249+
242250
return conf
243251
}
244252

pkg/suite/yaml_suite_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ config:
184184
dir: /home/commander/
185185
timeout: 10ms
186186
retries: 2
187+
interval: 500ms
187188
188189
tests:
189190
echo hello:
@@ -194,18 +195,21 @@ tests:
194195
dir: /home/test
195196
timeout: 1s
196197
retries: 10
198+
interval: 5s
197199
`)
198200

199201
got := ParseYAML(yaml)
200202
assert.Equal(t, map[string]string{"KEY": "global", "ANOTHER_KEY": "another_global"}, got.GetGlobalConfig().Env)
201203
assert.Equal(t, "/home/commander/", got.GetGlobalConfig().Dir)
202204
assert.Equal(t, "10ms", got.GetGlobalConfig().Timeout)
203205
assert.Equal(t, 2, got.GetGlobalConfig().Retries)
206+
assert.Equal(t, "500ms", got.GetGlobalConfig().Interval)
204207

205208
assert.Equal(t, map[string]string{"KEY": "local", "ANOTHER_KEY": "another_global"}, got.GetTests()[0].Command.Env)
206209
assert.Equal(t, "/home/test", got.GetTests()[0].Command.Dir)
207210
assert.Equal(t, "1s", got.GetTests()[0].Command.Timeout)
208211
assert.Equal(t, 10, got.GetTests()[0].Command.Retries)
212+
assert.Equal(t, "5s", got.GetTests()[0].Command.Interval)
209213
}
210214

211215
func TestYAMLSuite_ShouldThrowAnErrorIfFieldIsNotRegistered(t *testing.T) {

0 commit comments

Comments
 (0)