Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leverage gomega matchers, to allow for more complex asserts. #39

Merged
merged 1 commit into from
Feb 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ TRAVIS_TAG ?= "0.0.0"
all: test-all

install:
go install -v $(exe)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(TRAVIS_TAG)" -o release/$(cmd)-linux-amd64 $(exe)
cp release/$(cmd)-linux-amd64 $(GOPATH)/bin/goss
#CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install -v $(exe)

test:
go test $(pkgs)
Expand Down
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* [Attributes](#attributes-9)
* [render, r - Render gossfile after importing all referenced gossfiles](#render-r---render-gossfile-after-importing-all-referenced-gossfiles)
* [Patterns](#patterns)
* [Advanced Matchers](#advanced-matchers)


## Introduction
Expand Down Expand Up @@ -611,6 +612,8 @@ For the attributes that use patterns (ex. file, command output), each pattern is
* "/regex/" - verifies that line contains regex
* "!/regex/" - inverse of above, checks that no line contains regex

**NOTE:** Pattern attrubutes do not support [Advanced Matchers](#advanced-matchers)

```bash
$ cat /tmp/test.txt
foo
Expand Down Expand Up @@ -644,3 +647,42 @@ $ goss validate

Count: 2 failed: 1
```

### Advanced Matchers
Goss supports advanced matchers by converting json input to [gomega](https://onsi.github.io/gomega/) matchers. Here are some examples:

Validate that user "nobody" has a uid that is less than 500 and that they are ONLY a member of the "nobody" group.
```json
{
"user": {
"nobody": {
"exists": true,
"uid": {"lt": 500},
"gid": 99,
"groups": {"consist-of": ["nobody"]},
"home": "/"
}
}
}
```

Matchers can be nested for more complex logic, Ex:
Ensure that we have 3 kernel versions installed and none of them are "4.1.0":
```json
{
"package": {
"kernel": {
"installed": true,
"versions": {"and": [
{"have-len": 3},
{"not": {"contain-element": "4.1.0"}}
]}
}
}
}

```

For more information see:
* [gomega_test.go](https://github.com/aelsabbahy/goss/blob/master/resource/gomega_test.go) - For a complete set of supported json -> Gomega mapping
* [gomega](https://onsi.github.io/gomega/) - Gomega matchers reference
2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ import:
ref: 4e6893b05a6aa723daa5f9194361032c6beaca25
subpackages:
- /libcontainer/user
- package: github.com/onsi/gomega
ref: c72df929b80ef4930aaa75d5e486887ff2f3e06a
4 changes: 2 additions & 2 deletions integration-tests/Dockerfile_centos6
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM centos:centos6
FROM centos:6.6
MAINTAINER Ahmed

RUN yum install -y httpd-2.2.15 && yum clean all
RUN yum -y --disablerepo='*' --enablerepo=base install httpd && yum clean all

RUN chkconfig httpd on
4 changes: 2 additions & 2 deletions integration-tests/goss/alpine3/goss-expected-q.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@
},
"command": {
"apache2 -v": {
"exit-status": "127",
"exit-status": 127,
"stdout": [],
"stderr": [],
"timeout": 10000
},
"foobar": {
"exit-status": "127",
"exit-status": 127,
"stdout": [],
"stderr": [],
"timeout": 10000
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/goss/alpine3/goss-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@
},
"www-data": {
"exists": true,
"gid": "82"
"gid": 82
}
},
"command": {
"apache2 -v": {
"exit-status": "127",
"exit-status": 127,
"stdout": [],
"stderr": [
"sh: apache2: not found"
],
"timeout": 10000
},
"foobar": {
"exit-status": "127",
"exit-status": 127,
"stdout": [],
"stderr": [
"sh: foobar: not found"
Expand All @@ -114,4 +114,4 @@
"running": false
}
}
}
}
10 changes: 5 additions & 5 deletions integration-tests/goss/alpine3/goss.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"user": {
"apache": {
"exists": true,
"uid": "1000",
"gid": "1000",
"uid": 1000,
"gid": 1000,
"groups": [
"apache"
],
Expand All @@ -31,20 +31,20 @@
"group": {
"apache": {
"exists": true,
"gid": "1000"
"gid": 1000
}
},
"command": {
"httpd -v": {
"exit-status": "0",
"exit-status": 0,
"stdout": [
"Server version: Apache/2.4.17 (Unix)",
"Server built: Dec 15 2015 12:01:18"
],
"stderr": []
},
"foobar": {
"exit-status": "127",
"exit-status": 127,
"stdout": [],
"stderr": [
"foobar: not found"
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/goss/centos6/goss-expected-q.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@
},
"command": {
"foobar": {
"exit-status": "127",
"exit-status": 127,
"stdout": [],
"stderr": [],
"timeout": 10000
},
"httpd -v": {
"exit-status": "0",
"exit-status": 0,
"stdout": [],
"stderr": [],
"timeout": 10000
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/goss/centos6/goss-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
"user": {
"apache": {
"exists": true,
"uid": "48",
"gid": "48",
"uid": 48,
"gid": 48,
"groups": [
"apache"
],
Expand All @@ -78,26 +78,26 @@
"group": {
"apache": {
"exists": true,
"gid": "48"
"gid": 48
},
"foobar": {
"exists": false
}
},
"command": {
"foobar": {
"exit-status": "127",
"exit-status": 127,
"stdout": [],
"stderr": [
"sh: foobar: command not found"
],
"timeout": 10000
},
"httpd -v": {
"exit-status": "0",
"exit-status": 0,
"stdout": [
"Server version: Apache/2.2.15 (Unix)",
"Server built: Dec 15 2015 15:50:14"
"Server built: Jul 24 2015 11:52:28"
],
"stderr": [],
"timeout": 10000
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/goss/centos6/goss.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"user": {
"apache": {
"exists": true,
"uid": "48",
"gid": "48",
"uid": 48,
"gid": 48,
"groups": [
"apache"
],
Expand All @@ -31,20 +31,20 @@
"group": {
"apache": {
"exists": true,
"gid": "48"
"gid": 48
}
},
"command": {
"httpd -v": {
"exit-status": "0",
"exit-status": 0,
"stdout": [
"Server version: Apache/2.2.15 (Unix)",
"Server built: Dec 15 2015 15:50:14"
"Server built: Jul 24 2015 11:52:28"
],
"stderr": []
},
"foobar": {
"exit-status": "127",
"exit-status": 127,
"stdout": [],
"stderr": [
"sh: foobar: command not found"
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/goss/precise/goss-expected-q.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@
},
"command": {
"apache2 -v": {
"exit-status": "0",
"exit-status": 0,
"stdout": [],
"stderr": [],
"timeout": 10000
},
"foobar": {
"exit-status": "127",
"exit-status": 127,
"stdout": [],
"stderr": [],
"timeout": 10000
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/goss/precise/goss-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
},
"www-data": {
"exists": true,
"uid": "33",
"gid": "33",
"uid": 33,
"gid": 33,
"groups": [
"www-data"
],
Expand All @@ -81,12 +81,12 @@
},
"www-data": {
"exists": true,
"gid": "33"
"gid": 33
}
},
"command": {
"apache2 -v": {
"exit-status": "0",
"exit-status": 0,
"stdout": [
"Server version: Apache/2.2.22 (Ubuntu)",
"Server built: Jul 24 2015 17:25:54"
Expand All @@ -95,7 +95,7 @@
"timeout": 10000
},
"foobar": {
"exit-status": "127",
"exit-status": 127,
"stdout": [],
"stderr": [
"sh: 1: foobar: not found"
Expand All @@ -121,4 +121,4 @@
"running": false
}
}
}
}
10 changes: 5 additions & 5 deletions integration-tests/goss/precise/goss.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"user": {
"www-data": {
"exists": true,
"uid": "33",
"gid": "33",
"uid": 33,
"gid": 33,
"groups": [
"www-data"
],
Expand All @@ -31,20 +31,20 @@
"group": {
"www-data": {
"exists": true,
"gid": "33"
"gid": 33
}
},
"command": {
"apache2 -v": {
"exit-status": "0",
"exit-status": 0,
"stdout": [
"Server version: Apache/2.2.22 (Ubuntu)",
"Server built: Jul 24 2015 17:25:54"
],
"stderr": []
},
"foobar": {
"exit-status": "127",
"exit-status": 127,
"stdout": [],
"stderr": [
"sh: 1: foobar: not found"
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/goss/wheezy/goss-expected-q.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@
},
"command": {
"apache2 -v": {
"exit-status": "0",
"exit-status": 0,
"stdout": [],
"stderr": [],
"timeout": 10000
},
"foobar": {
"exit-status": "127",
"exit-status": 127,
"stdout": [],
"stderr": [],
"timeout": 10000
Expand Down
Loading