Permalink
Browse files

Add glob pattern support to gossfile (#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 #222

* Convert tests to use glob patterns for gossfiles

This is done with the exception of 'arch', which only includes
'goss-shared.yaml'.
  • Loading branch information...
AlexandreCarlton authored and aelsabbahy committed Apr 23, 2017
1 parent fc1bc88 commit 12d355ae79a163c28c08bae00674db4048d3ecf3
View
@@ -529,11 +529,12 @@ file:
### gossfile
-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.
+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.
```yaml
gossfile:
goss_httpd.yaml: {}
+ /etc/goss.d/*.yaml: {}
```
@@ -24,5 +24,4 @@ port:
ip:
- "::"
gossfile:
- "../goss-shared.yaml": {}
- "../goss-service.yaml": {}
+ "../goss-s*.yaml": {}
@@ -24,5 +24,4 @@ port:
ip:
- "::"
gossfile:
- "../goss-shared.yaml": {}
- "../goss-service.yaml": {}
+ "../goss-s*.yaml": {}
@@ -24,5 +24,4 @@ port:
ip:
- 0.0.0.0
gossfile:
- "../goss-shared.yaml": {}
- "../goss-service.yaml": {}
+ "../goss-s*.yaml": {}
@@ -24,5 +24,4 @@ port:
ip:
- "::"
gossfile:
- "../goss-shared.yaml": {}
- "../goss-service.yaml": {}
+ "../goss-s*.yaml": {}
View
@@ -158,9 +158,16 @@ func mergeJSONData(gossConfig GossConfig, depth int, path string) GossConfig {
} else {
fpath = filepath.Join(path, g.ID())
}
- fdir := filepath.Dir(fpath)
- j := mergeJSONData(ReadJSON(fpath), depth, fdir)
- ret = mergeGoss(ret, j)
+ matches, err := filepath.Glob(fpath)
+ if err != nil {
+ fmt.Printf("Error in expanding glob pattern: \"%s\"\n", err.Error())
+ os.Exit(1)
+ }
+ for _, match := range matches {
+ fdir := filepath.Dir(match)
+ j := mergeJSONData(ReadJSON(match), depth, fdir)
+ ret = mergeGoss(ret, j)
+ }
}
return ret
}

0 comments on commit 12d355a

Please sign in to comment.