Skip to content

Commit 8c95c05

Browse files
committed
Move nodes config from root to config property and add inhereitance support
1 parent c030b61 commit 8c95c05

6 files changed

Lines changed: 50 additions & 24 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ config: # Config for all executed tests
137137
KEY: global
138138
timeout: 50s # Define a timeout for a command under test
139139
retries: 2 # Define retries for each test
140+
nodes:
141+
- ssh-host1 # define default hosts
140142

141143
tests:
142144
echo hello: # Define command as title
@@ -164,7 +166,7 @@ tests:
164166
command: echo hello
165167
stdout:
166168
contains:
167-
- hello #See test "it should fail"
169+
- hello #See test "it should fail"
168170
exactly: hello
169171
line-count: 1
170172
config:
@@ -175,6 +177,9 @@ tests:
175177
ANOTHER: yeah # Add another env variable
176178
timeout: 1s # Overwrite timeout
177179
retries: 5
180+
nodes: # overwrite default nodes
181+
- docker-host1
182+
- docker-host2
178183
exit-code: 0
179184
```
180185

commander_unix.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ tests:
7272
contains:
7373
- ✓ [ssh-host] it should test ssh host
7474
- ✓ [ssh-host] it should set env variable
75-
- ✗ [local] it should test ssh host
76-
- ✗ [ssh-host] it should fail if env could not be set
77-
- "Failed setting env variables, maybe ssh server is configured to only accept LC_ prefixed env variables. Error: ssh: setenv failed"
78-
exit-code: 1
75+
- ✓ [ssh-host-default] it should be executed on ssh-host-default
76+
- ✓ [ssh-host] it should test multiple hosts
77+
- ✓ [ssh-host-default] it should test multiple hosts
78+
- ✓ [local] it should test multiple hosts
79+
exit-code: 0

integration/unix/nodes.yaml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ nodes:
55
identity-file: integration/containers/ssh/id_rsa
66
addr: localhost:2222
77

8+
ssh-host-default:
9+
type: ssh
10+
user: root
11+
identity-file: integration/containers/ssh/id_rsa
12+
addr: localhost:2222
13+
14+
config:
15+
nodes:
16+
- ssh-host-default
17+
818
tests:
919
it should test ssh host:
10-
nodes:
11-
- ssh-host
12-
- local
1320
command: cat /root/int-test && whoami && pwd
21+
config:
22+
nodes:
23+
- ssh-host
1424
stdout:
1525
contains:
1626
- test file ssh
@@ -19,19 +29,23 @@ tests:
1929
exit-code: 0
2030

2131
it should set env variable:
22-
nodes:
23-
- ssh-host
2432
config:
33+
nodes:
34+
- ssh-host
2535
env:
2636
LC_TEST_ENV: env var
2737
command: echo $LC_TEST_ENV
2838
stdout: env var
2939

30-
it should fail if env could not be set:
31-
nodes:
32-
- ssh-host
40+
it should be executed on ssh-host-default:
41+
command: whoami
42+
stdout: root
43+
44+
it should test multiple hosts:
45+
command: echo hello
46+
stdout: hello
3347
config:
34-
env:
35-
TEST_ENV: env var
36-
command: echo $TEST_ENV
37-
stdout: env var
48+
nodes:
49+
- ssh-host-default
50+
- ssh-host
51+
- local

pkg/runtime/runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type TestConfig struct {
7272
Retries int
7373
Interval string
7474
InheritEnv bool
75+
Nodes []string
7576
}
7677

7778
// ResultStatus represents the status code of a test result
@@ -115,7 +116,6 @@ type CommandUnderTest struct {
115116
Timeout string
116117
Retries int
117118
Interval string
118-
Executors []Executor
119119
}
120120

121121
// TestResult represents the TestCase and the ValidationResult

pkg/suite/yaml_suite.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type YAMLTestConfig struct {
2323
Timeout string `yaml:"timeout,omitempty"`
2424
Retries int `yaml:"retries,omitempty"`
2525
Interval string `yaml:"interval,omitempty"`
26+
Nodes []string `yaml:"nodes,omitempty"`
2627
}
2728

2829
type NodeConf struct {
@@ -55,7 +56,6 @@ type YAMLTest struct {
5556
Stdout interface{} `yaml:"stdout,omitempty"`
5657
Stderr interface{} `yaml:"stderr,omitempty"`
5758
Config YAMLTestConfig `yaml:"config,omitempty"`
58-
Nodes []string `yaml:"nodes,omitempty"`
5959
}
6060

6161
// ParseYAML parses the Suite from a yaml byte slice
@@ -76,6 +76,7 @@ func ParseYAML(content []byte) Suite {
7676
Timeout: yamlConfig.Config.Timeout,
7777
Retries: yamlConfig.Config.Retries,
7878
Interval: yamlConfig.Config.Interval,
79+
Nodes: yamlConfig.Config.Nodes,
7980
},
8081
Nodes: convertNodes(yamlConfig.Nodes),
8182
}
@@ -117,7 +118,7 @@ func convertYAMLConfToTestCases(conf YAMLConfig) []runtime.TestCase {
117118
Stdout: t.Stdout.(runtime.ExpectedOut),
118119
Stderr: t.Stderr.(runtime.ExpectedOut),
119120
},
120-
Nodes: t.Nodes,
121+
Nodes: t.Config.Nodes,
121122
})
122123
}
123124

@@ -152,7 +153,6 @@ func (y *YAMLConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
152153
Stdout: y.convertToExpectedOut(v.Stdout),
153154
Stderr: y.convertToExpectedOut(v.Stderr),
154155
Config: y.mergeConfigs(v.Config, params.Config),
155-
Nodes: v.Nodes,
156156
}
157157

158158
// Set key as command, if command property was empty
@@ -185,6 +185,7 @@ func (y *YAMLConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
185185
Timeout: params.Config.Timeout,
186186
Retries: params.Config.Retries,
187187
Interval: params.Config.Interval,
188+
Nodes: params.Config.Nodes,
188189
}
189190

190191
return nil
@@ -299,6 +300,10 @@ func (y *YAMLConfig) mergeConfigs(local YAMLTestConfig, global YAMLTestConfig) Y
299300
conf.InheritEnv = local.InheritEnv
300301
}
301302

303+
if len(local.Nodes) != 0 {
304+
conf.Nodes = local.Nodes
305+
}
306+
302307
return conf
303308
}
304309

pkg/suite/yaml_suite_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,10 @@ nodes:
336336
image: ubuntu:18.04
337337
tests:
338338
echo hello:
339-
nodes:
340-
- docker-host
341-
- ssh-host1
339+
config:
340+
nodes:
341+
- docker-host
342+
- ssh-host1
342343
exit-code: 0
343344
`)
344345

0 commit comments

Comments
 (0)