Skip to content

Commit

Permalink
Add glob pattern support to gossfile (#223)
Browse files Browse the repository at this point in the history
* 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 12d355a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
3 changes: 2 additions & 1 deletion docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
```


Expand Down
3 changes: 1 addition & 2 deletions integration-tests/goss/alpine3/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ port:
ip:
- "::"
gossfile:
"../goss-shared.yaml": {}
"../goss-service.yaml": {}
"../goss-s*.yaml": {}
3 changes: 1 addition & 2 deletions integration-tests/goss/centos7/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ port:
ip:
- "::"
gossfile:
"../goss-shared.yaml": {}
"../goss-service.yaml": {}
"../goss-s*.yaml": {}
3 changes: 1 addition & 2 deletions integration-tests/goss/precise/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ port:
ip:
- 0.0.0.0
gossfile:
"../goss-shared.yaml": {}
"../goss-service.yaml": {}
"../goss-s*.yaml": {}
3 changes: 1 addition & 2 deletions integration-tests/goss/wheezy/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ port:
ip:
- "::"
gossfile:
"../goss-shared.yaml": {}
"../goss-service.yaml": {}
"../goss-s*.yaml": {}
13 changes: 10 additions & 3 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 12d355a

Please sign in to comment.