Skip to content

Commit 7a3bd09

Browse files
authored
Merge pull request #40 from gitpod-io/princerachit/add-docs-on-usage-39
Add test spec in the readme
2 parents 3f8f782 + 9c93713 commit 7a3bd09

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed

README.md

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,16 @@ combiner:
145145
- node
146146
```
147147
148-
### Testing layers and merged images
149-
During a dazzle build one can test the individual layers and the final image.
148+
## Testing Chunks and Combinations
149+
150+
During a dazzle build one can test the individual chunks and the combination images.
150151
During the build dazzle will execute the layer tests for each individual layer, as well as the final image.
151152
This makes finding and debugging issues created by the layer merge process tractable.
152153
153154
Each chunk gets its own set of tests found under `tests/chunk.yaml`.
154155

155156
For example:
157+
156158
```YAML
157159
- desc: "it should demonstrate tests"
158160
command: ["echo", "hello world"]
@@ -170,18 +172,63 @@ For example:
170172
- MESSAGE=foobar
171173
assert:
172174
- stdout.trim() == "foobar"
175+
- desc: "it should have right binary version"
176+
entrypoint: [bash, -i, -c]
177+
command: [foo -version]
178+
assert:
179+
- stderr.indexOf("1.8.0_312") != -1
180+
173181
```
174182

175-
### Assertions
183+
Following fields are available in the test spec.
184+
185+
### `assert`
186+
187+
Field `assert` is used to add assertions on the test.
188+
It accepts an array input.
176189
All test assertions are written in [ES5 Javascript](https://github.com/robertkrimen/otto).
177190
Three variables are available in an assertion:
191+
178192
- `stdout` contains the standard output produced by the command
179193
- `stderr` contains the standard error output produced by the command
180194
- `status` contains the exit code of the command/container.
181195

182196
The assertion itself must evaluate to a boolean value, otherwise the test fails.
183197

184-
### Testing approach
198+
### `desc`
199+
200+
Field `desc` is used to add description of the test.
201+
It accepts a string input.
202+
203+
### `command`
204+
205+
Field `command` contains the test command.
206+
It accepts an array of string.
207+
208+
### `entrypoint`
209+
210+
Field `entrypoint` defines the entrypoint in the image.
211+
This is especially handy when the default entrypoint of the image is not a shell.
212+
It accepts an array of string.
213+
214+
### `skip`
215+
216+
Field `skip` is used to decide if the test should run.
217+
It accepts a boolean input.
218+
219+
### `user`
220+
221+
Field `user` is used to define the user as whom the tests should run.
222+
It accepts a string input.
223+
224+
225+
### `env`
226+
227+
Field `env` is used to define the user as whom the tests should run.
228+
It accepts an array of string.
229+
Each string is a key value pair separated by `=`.
230+
231+
## Testing approach
185232
While the test runner is standalone, the linux+amd64 version is embedded into the dazzle binary using [go.rice](https://github.com/GeertJohan/go.rice) and go generate - see [build.sh](./pkg/test/runner/build.sh).
186233
TODO: use go:embed?
187234
Note that if you make changes to code in the test runner you will need to re-embed the runner into the binary in order to use it via dazzle.
@@ -205,7 +252,7 @@ $ go run pkg/test/runner/main.go eyJEZXNjIjoiaXQgc2hvdWxkIGhhdmUgR28gaW4gdmVyc2l
205252
go version go1.16.4 linux/amd64
206253
```
207254

208-
### Integration tests
255+
## Integration tests
209256
There is an integration test for the build command in pkg/dazzle/build_test.go - TestProjectChunk_test_integration and a shell script to run it.
210257
The integration test does an end-to-end check along with editing a test and re-running to ensure only the test image is updated.
211258

0 commit comments

Comments
 (0)