-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.bats
151 lines (132 loc) · 4.37 KB
/
test.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bats
setup() {
if [ -z ${ver+x} ]; then
echo 'ver environment variable does not exist'
exit 1
fi
tag=${ver}
}
@test "alpine version is correct" {
run docker run --rm --entrypoint=/bin/sh graze/bats:$tag -c 'cat /etc/os-release'
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
[[ "${lines[2]}" == "VERSION_ID=3.18."* ]]
}
@test "bats version is correct" {
run docker run --rm graze/bats:$tag --version
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
[[ "$output" == "Bats ${ver}"* ]]
[[ "$output" != *"-dev"* ]]
[[ "$output" != *"-alpha"* ]]
[[ "$output" != *"-beta"* ]]
}
@test "entrypoint is bats" {
run bash -c "docker inspect graze/bats:$tag | jq -r '.[].Config.Entrypoint[]'"
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
[ "$output" = "/usr/local/bin/bats" ]
}
@test "image has docker installed" {
run docker run --rm --entrypoint="/bin/sh" graze/bats:$tag -c '[ -x /usr/bin/docker ]'
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
}
@test "image has make installed" {
run docker run --rm --entrypoint="/bin/sh" graze/bats:$tag -c '[ -x /usr/bin/make ]'
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
}
@test "image has curl installed" {
run docker run --rm --entrypoint="/bin/sh" graze/bats:$tag -c '[ -x /usr/bin/curl ]'
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
}
@test "image has jq installed" {
run docker run --rm --entrypoint="/bin/sh" graze/bats:$tag -c '[ -x /usr/bin/jq ]'
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
}
@test "image has git installed" {
run docker run --rm --entrypoint="/bin/sh" graze/bats:$tag -c '[ -x /usr/bin/git ]'
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
}
@test "the image has a MIT license" {
run bash -c "docker inspect graze/bats:$tag | jq -r '.[].Config.Labels.license'"
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
[ "$output" = "MIT" ]
}
@test "the image has a maintainer" {
run bash -c "docker inspect graze/bats:$tag | jq -r '.[].Config.Labels.maintainer'"
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
[ "$output" = "[email protected]" ]
}
@test "the image uses label-schema.org" {
run bash -c "docker inspect graze/bats:$tag | jq -r '.[].Config.Labels.\"org.label-schema.schema-version\"'"
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
[ "$output" = "1.0" ]
}
@test "the image has a vcs-url label" {
run bash -c "docker inspect graze/bats:$tag | jq -r '.[].Config.Labels.\"org.label-schema.vcs-url\"'"
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
[ "$output" = "https://github.com/graze/docker-bats" ]
}
@test "the image has a vcs-ref label set to the current head commit in github" {
run bash -c "docker inspect graze/bats:$tag | jq -r '.[].Config.Labels.\"org.label-schema.vcs-ref\"'"
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
[ "$output" = `git rev-parse --short HEAD` ]
}
@test "the image has a build-date label" {
run bash -c "docker inspect graze/bats:$tag | jq -r '.[].Config.Labels.\"org.label-schema.build-date\"'"
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
[ "$output" != "null" ]
}
@test "the image has a vendor label" {
run bash -c "docker inspect graze/bats:$tag | jq -r '.[].Config.Labels.\"org.label-schema.vendor\"'"
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
[ "$output" = "graze" ]
}
@test "the image has a name label" {
run bash -c "docker inspect graze/bats:$tag | jq -r '.[].Config.Labels.\"org.label-schema.name\"'"
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
[ "$output" = "bats" ]
}
@test "the image has a version label" {
run bash -c "docker inspect graze/bats:$tag | jq -r '.[].Config.Labels.\"org.label-schema.version\"'"
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
[ "$output" = "$tag" ]
}
@test "the image has a docker.cmd label" {
run bash -c "docker inspect graze/bats:$tag | jq -r '.[].Config.Labels.\"org.label-schema.docker.cmd\"'"
echo 'status:' $status
echo 'output:' $output
[ "$status" -eq 0 ]
[ "$output" = "docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v \$(pwd):/app graze/bats" ]
}