Skip to content

Commit 12d355a

Browse files
AlexandreCarltonaelsabbahy
authored andcommitted
Add glob pattern support to gossfile (goss-org#223)
* Add glob pattern support to gossfile This will ease the addition of tests to an existing goss test suite. All that is necessary is to drop in a file matching the existing pattern. References goss-org#222 * Convert tests to use glob patterns for gossfiles This is done with the exception of 'arch', which only includes 'goss-shared.yaml'.
1 parent fc1bc88 commit 12d355a

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

docs/manual.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,12 @@ file:
529529

530530

531531
### gossfile
532-
Import other gossfiles from this one. This is the best way to maintain a large mumber of tests, and/or create profiles. See [render](#render-r---render-gossfile-after-importing-all-referenced-gossfiles) for more examples.
532+
Import other gossfiles from this one. This is the best way to maintain a large mumber of tests, and/or create profiles. See [render](#render-r---render-gossfile-after-importing-all-referenced-gossfiles) for more examples. Glob patterns can be also be used to specify matching gossfiles.
533533

534534
```yaml
535535
gossfile:
536536
goss_httpd.yaml: {}
537+
/etc/goss.d/*.yaml: {}
537538
```
538539

539540

integration-tests/goss/alpine3/goss.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ port:
2424
ip:
2525
- "::"
2626
gossfile:
27-
"../goss-shared.yaml": {}
28-
"../goss-service.yaml": {}
27+
"../goss-s*.yaml": {}

integration-tests/goss/centos7/goss.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ port:
2424
ip:
2525
- "::"
2626
gossfile:
27-
"../goss-shared.yaml": {}
28-
"../goss-service.yaml": {}
27+
"../goss-s*.yaml": {}

integration-tests/goss/precise/goss.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ port:
2424
ip:
2525
- 0.0.0.0
2626
gossfile:
27-
"../goss-shared.yaml": {}
28-
"../goss-service.yaml": {}
27+
"../goss-s*.yaml": {}

integration-tests/goss/wheezy/goss.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ port:
2424
ip:
2525
- "::"
2626
gossfile:
27-
"../goss-shared.yaml": {}
28-
"../goss-service.yaml": {}
27+
"../goss-s*.yaml": {}

store.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,16 @@ func mergeJSONData(gossConfig GossConfig, depth int, path string) GossConfig {
158158
} else {
159159
fpath = filepath.Join(path, g.ID())
160160
}
161-
fdir := filepath.Dir(fpath)
162-
j := mergeJSONData(ReadJSON(fpath), depth, fdir)
163-
ret = mergeGoss(ret, j)
161+
matches, err := filepath.Glob(fpath)
162+
if err != nil {
163+
fmt.Printf("Error in expanding glob pattern: \"%s\"\n", err.Error())
164+
os.Exit(1)
165+
}
166+
for _, match := range matches {
167+
fdir := filepath.Dir(match)
168+
j := mergeJSONData(ReadJSON(match), depth, fdir)
169+
ret = mergeGoss(ret, j)
170+
}
164171
}
165172
return ret
166173
}

0 commit comments

Comments
 (0)