Skip to content

Commit 83effd2

Browse files
committed
Added acceptance tests demonstraing configuration file usage
1 parent 00b9b83 commit 83effd2

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

acceptance.bats

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,25 @@
1414
run conftest test --fail-on-warn -p examples/kubernetes/policy examples/kubernetes/service.yaml
1515
[ "$status" -eq 1 ]
1616
}
17+
18+
@test "Pass when testing a blank namespace" {
19+
run conftest test --namespace notpresent -p examples/kubernetes/policy examples/kubernetes/deployment.yaml
20+
[ "$status" -eq 0 ]
21+
}
22+
23+
@test "Fail due to picking up settings from configuration file" {
24+
cd examples/configfile
25+
run conftest test deployment.yaml
26+
[ "$status" -eq 1 ]
27+
[[ "$output" =~ "Containers must not run as root" ]]
28+
}
29+
30+
@test "Has version flag" {
31+
run conftest --version
32+
[ "$status" -eq 0 ]
33+
}
34+
35+
@test "Has help flag" {
36+
run conftest --help
37+
[ "$status" -eq 0 ]
38+
}

examples/configfile/conftest.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
policy = "test"
2+
namespace = "conftest"

examples/configfile/deployment.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: hello-kubernetes
5+
spec:
6+
replicas: 3
7+
selector:
8+
matchLabels:
9+
app: hello-kubernetes
10+
template:
11+
metadata:
12+
labels:
13+
app: hello-kubernetes
14+
spec:
15+
containers:
16+
- name: hello-kubernetes
17+
image: paulbouwer/hello-kubernetes:1.5
18+
ports:
19+
- containerPort: 8080

examples/configfile/test/deny.rego

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package conftest
2+
3+
import data.kubernetes
4+
5+
6+
deny[msg] {
7+
kubernetes.is_deployment
8+
not input.spec.template.spec.securityContext.runAsNonRoot = true
9+
msg = "Containers must not run as root"
10+
}
11+
12+
deny[msg] {
13+
kubernetes.is_deployment
14+
not input.spec.selector.matchLabels.app
15+
not input.spec.selector.matchLabels.release
16+
msg = "Containers must provide app/release labls for pod selectors"
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package kubernetes
2+
3+
is_service {
4+
input.kind = "Service"
5+
}
6+
7+
is_deployment {
8+
input.kind = "Deployment"
9+
}

0 commit comments

Comments
 (0)