Skip to content

Commit 8364e03

Browse files
aaron-prindlenkubala
authored andcommitted
added Installation heading, a section stated what encompasses a structure tests, additional small tweaks (#14)
1 parent 79e87d9 commit 8364e03

File tree

1 file changed

+61
-49
lines changed

1 file changed

+61
-49
lines changed

README.md

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,71 @@
1-
GCP Structure Tests
1+
Container Structure Tests
22
====================
33

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
66
in an image, as well as verify metadata and contents of the filesystem.
77

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),
1012
or pull the image at `gcr.io/gcp-runtimes/container-structure-test`.
1113
**Please note that at this time the binary is only compatible with Linux.**
1214

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+
1321
## Example Run
1422
An example run of the test framework:
1523
```shell
1624
./structure-test -test.v -image gcr.io/google-appengine/python \
1725
python_test_config.yaml
1826
```
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,
2028
using the python_test_config.yaml test config.
2129

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
2634
in order. Within this config file, four types of tests can be written:
2735

2836
- 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
3038
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
3240
contain, or do not contain, specific contents)
3341
- Metadata Test, *singular* (making sure certain container metadata is correct)
3442

3543
## Command Tests
3644
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
3947
as normal.
4048

4149
#### Supported Fields:
4250

4351
This is the current schema version (v2.0.0).
4452

4553
- Name (string, **required**): The name of the test
46-
- Setup ([][]string, *optional*): A list of commands
54+
- Setup ([][]string, *optional*): A list of commands
4755
(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
4957
(each with optional flags) to run after the actual command under test.
5058
- Command (string, **required**): The command to run in the test.
5159
- 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
5361
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
5563
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**
5765
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
5967
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**
6169
match the stderr from running the command.
6270
- Exit Code (int, *optional*): Exit code that the command should exit with.
6371

@@ -73,21 +81,21 @@ commandTests:
7381
command: "apt-get"
7482
args: ["-qqs", "upgrade"]
7583
excludedOutput: [".*Inst.*Security.* | .*Security.*Inst.*"]
76-
excludedError: [".*Inst.*Security.* | .*Security.*Inst.*"]
84+
excludedError: [".*Inst.*Security.* | .*Security.*Inst.*"]
7785
```
7886
7987
8088
## 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
8492
**not** present in the file system.
8593
8694
#### Supported Fields:
8795
8896
- Name (string, **required**): The name of the test
8997
- 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
9199
directory should exist in the file system
92100
- Permissions (string, *optional*): The expected Unix permission string (e.g.
93101
drwxrwxrwx) of the files or directory.
@@ -102,19 +110,19 @@ fileExistenceTests:
102110
```
103111
104112
## 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
109117
expected or excluded content in the specified file.
110118
111119
#### Supported Fields:
112120
113121
- Name (string, **required**): The name of the test
114122
- 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
116124
should match the contents of the file
117-
- ExcludedContents (string[], *optional*): List of regexes that
125+
- ExcludedContents (string[], *optional*): List of regexes that
118126
should **not** match the contents of the file
119127
120128
Example:
@@ -172,10 +180,10 @@ licenseTests:
172180
```
173181
174182
### 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.
179187
Unix-style environment variable substitution is supported.
180188
181189
To specify, add a section like this to your config:
@@ -188,17 +196,21 @@ globalEnvVars:
188196
value: "/env/bin:$PATH"
189197
```
190198
199+
## Running File Tests On Cloudbuild
200+
201+
TODO
202+
191203
192204
## Running File Tests Without Docker
193205
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
202214
in the tests, with the `-driver` flag.
203215

204216
An example test run with a different driver looks like:
@@ -208,21 +220,21 @@ python_test_config.yaml
208220
```
209221

210222
The currently supported drivers in the framework are:
211-
- `docker`: the default driver.
223+
- `docker`: the default driver.
212224
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
214226
interacting with it. Does *not* support command tests.
215227

216228

217229
### Running Structure Tests Through Bazel
218-
Structure tests can also be run through bazel.
230+
Structure tests can also be run through bazel.
219231
To do so, include the rule definitions in your BUILD file:
220232

221233
```BUILD
222234
load("@container-structure-test//:tests.bzl", "structure_test")
223235
```
224236

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
226238
file as parameters:
227239

228240
```BUILD
@@ -240,4 +252,4 @@ structure_test(
240252
config = "testdata/hello.yaml",
241253
image = ":hello",
242254
)
243-
```
255+
```

0 commit comments

Comments
 (0)