1
- GCP Structure Tests
1
+ Container Structure Tests
2
2
====================
3
3
4
- The GCP Structure Tests provide a powerful framework to validate the structure
5
- of a container image. These tests can be used to check the output of commands
4
+ The Container Structure Tests provide a powerful framework to validate the structure
5
+ of a container image. These tests can be used to check the output of commands
6
6
in an image, as well as verify metadata and contents of the filesystem.
7
7
8
- Tests can be run either through a standalone binary, or through a Docker image as part of a cloudbuild. Download the binary
9
- [ here] ( https://storage.googleapis.com/container-structure-test/latest/container-structure-test ) ,
8
+ Tests can be run either through a standalone binary, or through a Docker image.
9
+
10
+ ## Installation
11
+ Download the latest binary release [ here] ( https://storage.googleapis.com/container-structure-test/latest/container-structure-test ) ,
10
12
or pull the image at ` gcr.io/gcp-runtimes/container-structure-test ` .
11
13
** Please note that at this time the binary is only compatible with Linux.**
12
14
15
+ ## Setup
16
+ To use container structure tests to validate your containers, you need the following:
17
+ - The container structure test binary or docker image
18
+ - A container image to test against
19
+ - A test .yaml or .json file with user defined structure tests to run inside of the specified container image
20
+
13
21
## Example Run
14
22
An example run of the test framework:
15
23
``` shell
16
24
./structure-test -test.v -image gcr.io/google-appengine/python \
17
25
python_test_config.yaml
18
26
```
19
- This command will run the tests on the GAE Python image, with verbose logging,
27
+ This command will run the tests on the Google App Engine Python image, with verbose logging,
20
28
using the python_test_config.yaml test config.
21
29
22
- Tests within this framework are specified through a YAML or JSON config file,
23
- which is provided to the test driver as the last positional argument of the
24
- command. Multiple config files may be specified in a single test run. The
25
- config file will be loaded in by the test driver, which will execute the tests
30
+ Tests within this framework are specified through a YAML or JSON config file,
31
+ which is provided to the test driver as the last positional argument of the
32
+ command. Multiple config files may be specified in a single test run. The
33
+ config file will be loaded in by the test driver, which will execute the tests
26
34
in order. Within this config file, four types of tests can be written:
27
35
28
36
- Command Tests (testing output/error of a specific command issued)
29
- - File Existence Tests (making sure a file is, or isn't, present in the
37
+ - File Existence Tests (making sure a file is, or isn't, present in the
30
38
file system of the image)
31
- - File Content Tests (making sure files in the file system of the image
39
+ - File Content Tests (making sure files in the file system of the image
32
40
contain, or do not contain, specific contents)
33
41
- Metadata Test, * singular* (making sure certain container metadata is correct)
34
42
35
43
## Command Tests
36
44
Command tests ensure that certain commands run properly in the target image.
37
- Regexes can be used to check for expected or excluded strings in both stdout
38
- and stderr. Additionally, any number of flags can be passed to the argument
45
+ Regexes can be used to check for expected or excluded strings in both stdout
46
+ and stderr. Additionally, any number of flags can be passed to the argument
39
47
as normal.
40
48
41
49
#### Supported Fields:
42
50
43
51
This is the current schema version (v2.0.0).
44
52
45
53
- Name (string, ** required** ): The name of the test
46
- - Setup ([ ] [ ] string, * optional* ): A list of commands
54
+ - Setup ([ ] [ ] string, * optional* ): A list of commands
47
55
(each with optional flags) to run before the actual command under test.
48
- - Teardown ([ ] [ ] string, * optional* ): A list of commands
56
+ - Teardown ([ ] [ ] string, * optional* ): A list of commands
49
57
(each with optional flags) to run after the actual command under test.
50
58
- Command (string, ** required** ): The command to run in the test.
51
59
- Args ([ ] string, * optional* ): The arguments to pass to the command.
52
- - EnvVars ([ ] EnvVar, * optional* ): A list of environment variables to set for
60
+ - EnvVars ([ ] EnvVar, * optional* ): A list of environment variables to set for
53
61
the individual test. See the ** Environment Variables** section for more info.
54
- - Expected Output ([ ] string, * optional* ): List of regexes that should
62
+ - Expected Output ([ ] string, * optional* ): List of regexes that should
55
63
match the stdout from running the command.
56
- - Excluded Output ([ ] string, * optional* ): List of regexes that should ** not**
64
+ - Excluded Output ([ ] string, * optional* ): List of regexes that should ** not**
57
65
match the stdout from running the command.
58
- - Expected Error ([ ] string, * optional* ): List of regexes that should
66
+ - Expected Error ([ ] string, * optional* ): List of regexes that should
59
67
match the stderr from running the command.
60
- - Excluded Error ([ ] string, * optional* ): List of regexes that should ** not**
68
+ - Excluded Error ([ ] string, * optional* ): List of regexes that should ** not**
61
69
match the stderr from running the command.
62
70
- Exit Code (int, * optional* ): Exit code that the command should exit with.
63
71
@@ -73,21 +81,21 @@ commandTests:
73
81
command : " apt-get"
74
82
args : ["-qqs", "upgrade"]
75
83
excludedOutput : [".*Inst.*Security.* | .*Security.*Inst.*"]
76
- excludedError : [".*Inst.*Security.* | .*Security.*Inst.*"]
84
+ excludedError : [".*Inst.*Security.* | .*Security.*Inst.*"]
77
85
` ` `
78
86
79
87
80
88
## File Existence Tests
81
- File existence tests check to make sure a specific file (or directory) exist
82
- within the file system of the image. No contents of the files or directories
83
- are checked. These tests can also be used to ensure a file or directory is
89
+ File existence tests check to make sure a specific file (or directory) exist
90
+ within the file system of the image. No contents of the files or directories
91
+ are checked. These tests can also be used to ensure a file or directory is
84
92
**not** present in the file system.
85
93
86
94
#### Supported Fields:
87
95
88
96
- Name (string, **required**): The name of the test
89
97
- Path (string, **required**): Path to the file or directory under test
90
- - ShouldExist (boolean, **required**): Whether or not the specified file or
98
+ - ShouldExist (boolean, **required**): Whether or not the specified file or
91
99
directory should exist in the file system
92
100
- Permissions (string, *optional*): The expected Unix permission string (e.g.
93
101
drwxrwxrwx) of the files or directory.
@@ -102,19 +110,19 @@ fileExistenceTests:
102
110
` ` `
103
111
104
112
## File Content Tests
105
- File content tests open a file on the file system and check its contents.
106
- These tests assume the specified file **is a file**, and that it **exists**
107
- (if unsure about either or these criteria, see the above
108
- **File Existence Tests** section). Regexes can again be used to check for
113
+ File content tests open a file on the file system and check its contents.
114
+ These tests assume the specified file **is a file**, and that it **exists**
115
+ (if unsure about either or these criteria, see the above
116
+ **File Existence Tests** section). Regexes can again be used to check for
109
117
expected or excluded content in the specified file.
110
118
111
119
#### Supported Fields:
112
120
113
121
- Name (string, **required**): The name of the test
114
122
- Path (string, **required**): Path to the file under test
115
- - ExpectedContents (string[], *optional*): List of regexes that
123
+ - ExpectedContents (string[], *optional*): List of regexes that
116
124
should match the contents of the file
117
- - ExcludedContents (string[], *optional*): List of regexes that
125
+ - ExcludedContents (string[], *optional*): List of regexes that
118
126
should **not** match the contents of the file
119
127
120
128
Example:
@@ -172,10 +180,10 @@ licenseTests:
172
180
` ` `
173
181
174
182
### Environment Variables
175
- A list of environment variables can optionally be specified as part of the
176
- test setup. They can either be set up globally (for all test runs), or
177
- test-local as part of individual command test runs (see the **Command Tests**
178
- section above). Each environment variable is specified as a key-value pair.
183
+ A list of environment variables can optionally be specified as part of the
184
+ test setup. They can either be set up globally (for all test runs), or
185
+ test-local as part of individual command test runs (see the **Command Tests**
186
+ section above). Each environment variable is specified as a key-value pair.
179
187
Unix-style environment variable substitution is supported.
180
188
181
189
To specify, add a section like this to your config:
@@ -188,17 +196,21 @@ globalEnvVars:
188
196
value : " /env/bin:$PATH"
189
197
` ` `
190
198
199
+ ## Running File Tests On Cloudbuild
200
+
201
+ TODO
202
+
191
203
192
204
## Running File Tests Without Docker
193
205
194
- Container images can be represented in multiple formats, and the Docker image
195
- is just one of them. At their core, images are just a series of layers, each
196
- of which is a tarball, and so can be interacted with without a working Docker
197
- daemon. While running command tests currently requires a functioning Docker
198
- daemon on the host machine, File Existence/Content tests do not. This can be
199
- particularly useful when dealing with images which have been ` docker export`ed
200
- or saved in a different image format than the Docker format. To run tests
201
- without using a Docker daemon, a user can specify a different "driver" to use
206
+ Container images can be represented in multiple formats, and the Docker image
207
+ is just one of them. At their core, images are just a series of layers, each
208
+ of which is a tarball, and so can be interacted with without a working Docker
209
+ daemon. While running command tests currently requires a functioning Docker
210
+ daemon on the host machine, File Existence/Content tests do not. This can be
211
+ particularly useful when dealing with images which have been ` docker export`ed
212
+ or saved in a different image format than the Docker format. To run tests
213
+ without using a Docker daemon, a user can specify a different "driver" to use
202
214
in the tests, with the `-driver` flag.
203
215
204
216
An example test run with a different driver looks like :
@@ -208,21 +220,21 @@ python_test_config.yaml
208
220
` ` `
209
221
210
222
The currently supported drivers in the framework are :
211
- - `docker` : the default driver.
223
+ - `docker` : the default driver.
212
224
Supports all tests, and uses the Docker daemon on the host to run them.
213
- - `tar` : a tar driver, which converts an image to a single tarball before
225
+ - `tar` : a tar driver, which converts an image to a single tarball before
214
226
interacting with it. Does *not* support command tests.
215
227
216
228
217
229
# ## Running Structure Tests Through Bazel
218
- Structure tests can also be run through bazel.
230
+ Structure tests can also be run through bazel.
219
231
To do so, include the rule definitions in your BUILD file :
220
232
221
233
` ` ` BUILD
222
234
load("@container-structure-test//:tests.bzl", "structure_test")
223
235
` ` `
224
236
225
- and create a `structure_test` rule, passing in your image and config
237
+ and create a `structure_test` rule, passing in your image and config
226
238
file as parameters :
227
239
228
240
` ` ` BUILD
@@ -240,4 +252,4 @@ structure_test(
240
252
config = "testdata/hello.yaml",
241
253
image = ":hello",
242
254
)
243
- ` ` `
255
+ ` ` `
0 commit comments