dockerspec 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +92 -58
- data/README.md +159 -15
- data/TODO.md +1 -0
- data/lib/dockerspec/builder.rb +4 -1
- data/lib/dockerspec/builder/config_helpers.rb +1 -1
- data/lib/dockerspec/builder/logger.rb +1 -1
- data/lib/dockerspec/engine/specinfra/backend.rb +6 -19
- data/lib/dockerspec/helper/rspec_example_helpers.rb +5 -25
- data/lib/dockerspec/rspec/configuration.rb +6 -2
- data/lib/dockerspec/rspec/resources.rb +13 -5
- data/lib/dockerspec/rspec/resources/its_container.rb +35 -15
- data/lib/dockerspec/runner/base.rb +3 -0
- data/lib/dockerspec/runner/config_helpers.rb +97 -0
- data/lib/dockerspec/version.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 396a46490a394c6af6d52bd16850e4b6a0ccd909
|
4
|
+
data.tar.gz: d9c0eb9d9244bcb92b59615711a769cee935e3ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36b1beb9af0e95ffaadf1577d26c20789b2fea94df4d821746b1cfbcfd0771861ce681587ba97f641d27e95a135d6e22d71a896798fb2262a6c05d8c92b30537
|
7
|
+
data.tar.gz: 20d681f61e9d27b03c694d907408763e45272a4303590f0a48f04a2a2a68070f28e53cf6d7e4e7736ef37e82cee3f1bb9a0f5f1929ce4572f2bdf0e7c9009535
|
data/CHANGELOG.md
CHANGED
@@ -1,60 +1,94 @@
|
|
1
1
|
# CHANGELOG for Dockerspec
|
2
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
|
-
|
3
|
+
All notable changes to the [`dockerspec`](https://rubygems.org/gems/dockerspec/) RubyGem will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
|
+
|
7
|
+
## [0.4.0] - 2017-03-20
|
8
|
+
[](https://travis-ci.org/zuazo/dockerspec)
|
9
|
+
|
10
|
+
### Added in 0.4.0
|
11
|
+
- Integrate with [rspec-retry](https://github.com/NoRedInk/rspec-retry) gem.
|
12
|
+
- Docker logs support ([issue #3](https://github.com/zuazo/dockerspec/issues/3), thanks [@axi43](https://github.com/axi43) for the idea).
|
13
|
+
|
14
|
+
### Changed in 0.4.0
|
15
|
+
- Let user choose RSpec formatter ([issue #4](https://github.com/zuazo/dockerspec/issues/4), thanks [Luis Sagastume](https://github.com/zuazo/dockerspec/pull/4) for the help).
|
16
|
+
|
17
|
+
### Removed in 0.4.0
|
18
|
+
- Drop Ruby `< 2.2` support.
|
19
|
+
|
20
|
+
### Fixed in 0.4.0
|
21
|
+
- Be able to use os detection within test blocks ([issue #2](https://github.com/zuazo/dockerspec/issues/2), **special thanks to [Nan Liu](https://github.com/nanliu)** for his help and [his astonishing presentation](https://www.slideshare.net/NanLiu1/trust-but-verify-testing-with-docker-containers)).
|
22
|
+
- Use `Integer` instead of `Fixnum`.
|
23
|
+
|
24
|
+
### Improved in 0.4.0
|
25
|
+
- `ItsContainer`: rename container_name variable to avoid confussion.
|
26
|
+
|
27
|
+
### Documentation Changes in 0.4.0
|
28
|
+
- Document `dir` parameter in `Builder#build_from_string`.
|
29
|
+
- CHANGELOG: Follow "Keep a CHANGELOG".
|
30
|
+
- Add GitHub templates.
|
31
|
+
- README:
|
32
|
+
- Document how to require the gem.
|
33
|
+
- Add Presentations section.
|
34
|
+
- Add a TOC.
|
35
|
+
- Add documentation links.
|
36
|
+
|
37
|
+
## [0.3.0] - 2016-02-28
|
38
|
+
[](https://travis-ci.org/zuazo/dockerspec)
|
39
|
+
|
40
|
+
### Breaking Changes in 0.3.0
|
41
|
+
- Enable `options[:rm]` by default.
|
42
|
+
|
43
|
+
### Added in 0.3.0
|
44
|
+
- Add Docker Compose support.
|
45
|
+
- Add Infrataster and Capybara support.
|
46
|
+
- Add `:wait` option to `docker_run` and `docker_compose`.
|
47
|
+
- Add `described_image` helper for `docker_run`.
|
48
|
+
- Support integer values with `have_expose` matcher.
|
49
|
+
- Make `require 'dockerspec'` optional.
|
50
|
+
- Add support for multiple testing engines.
|
51
|
+
- Add a `Configuration` class to setup the internal modularization.
|
52
|
+
|
53
|
+
### Fixed in 0.3.0
|
54
|
+
- Fix `:env` in `docker_run` with Serverspec.
|
55
|
+
- Fix *Must have id* error when building images from IDs with tags.
|
56
|
+
|
57
|
+
### Improved in 0.3.0
|
58
|
+
- Update RuboCop to `0.37`, fix new offenses.
|
59
|
+
- `Runner` classes split into `Engine::Base` and `Runner::Base`.
|
60
|
+
- Rename many classes.
|
61
|
+
|
62
|
+
### Documentation Changes in 0.3.0
|
63
|
+
- README:
|
64
|
+
- Move the documentation below examples.
|
65
|
+
- Add many examples.
|
66
|
+
|
67
|
+
## [0.2.0] - 2015-12-11
|
68
|
+
[](https://travis-ci.org/zuazo/dockerspec)
|
69
|
+
|
70
|
+
### Added in 0.2.0
|
71
|
+
- Print Docker errors in a more readable format.
|
72
|
+
|
73
|
+
### Changed in 0.2.0
|
74
|
+
- Set some opinionated RSpec configurations.
|
75
|
+
|
76
|
+
### Fixed in 0.2.0
|
77
|
+
- Fix *undefined method* error in the outermost examples.
|
78
|
+
|
79
|
+
### Documentation Changes in 0.2.0
|
80
|
+
- Add examples for `#have_cmd` using string format.
|
81
|
+
- README:
|
82
|
+
- Improve Ruby documentation.
|
83
|
+
- Change gem badge to point to RubyGems.
|
84
|
+
- Add Real-world examples section.
|
85
|
+
|
86
|
+
## 0.1.0 - 2015-12-09
|
87
|
+
[](https://travis-ci.org/zuazo/dockerspec)
|
88
|
+
|
89
|
+
- Initial release of `dockerspec`.
|
90
|
+
|
91
|
+
[Unreleased]: https://github.com/zuazo/dockerspec/compare/0.4.0...HEAD
|
92
|
+
[0.4.0]: https://github.com/zuazo/dockerspec/compare/0.3.0...0.4.0
|
93
|
+
[0.3.0]: https://github.com/zuazo/dockerspec/compare/0.2.0...0.3.0
|
94
|
+
[0.2.0]: https://github.com/zuazo/dockerspec/compare/0.1.0...0.2.0
|
data/README.md
CHANGED
@@ -6,20 +6,42 @@
|
|
6
6
|
[](https://rubygems.org/gems/dockerspec)
|
7
7
|
[](https://gemnasium.com/zuazo/dockerspec)
|
8
8
|
[](https://codeclimate.com/github/zuazo/dockerspec)
|
9
|
-
[](https://travis-ci.org/zuazo/dockerspec)
|
10
10
|
[](https://circleci.com/gh/zuazo/dockerspec/tree/master)
|
11
|
-
[](https://coveralls.io/github/zuazo/dockerspec?branch=0.4.0)
|
12
12
|
[](http://inch-ci.org/github/zuazo/dockerspec)
|
13
13
|
|
14
|
-
## Description
|
15
|
-
|
16
14
|
A small Ruby Gem to run RSpec, [Serverspec](http://serverspec.org/), [Infrataster](https://github.com/ryotarai/infrataster) and [Capybara](http://jnicklas.github.io/capybara/) tests against Dockerfiles or Docker images easily.
|
17
15
|
|
18
16
|
This gem is designed to work out of the box on [Travis CI](https://travis-ci.org/), [CircleCI](https://circleci.com/) and other similar CI environments.
|
19
17
|
|
18
|
+
## Table of Contents
|
19
|
+
|
20
|
+
- [Requirements](#requirements)
|
21
|
+
- [Installation](#installation)
|
22
|
+
- [Documentation](#documentation)
|
23
|
+
- [Presentations](#presentations)
|
24
|
+
- [Usage Examples](#usage-examples)
|
25
|
+
- [Run Tests Against a Dockerfile in the Current Directory](#run-tests-against-a-dockerfile-in-the-current-directory)
|
26
|
+
- [Run Tests Against Docker Compose](#run-tests-against-docker-compose)
|
27
|
+
- [Checking Container Logs](#checking-container-logs)
|
28
|
+
- [Retrying Tests That Fail Temporarily](#retrying-tests-that-fail-temporarily)
|
29
|
+
- [Run HTTP Tests Using Infrataster](#run-http-tests-using-infrataster)
|
30
|
+
- [Run HTTP Tests Using Capybara](#run-http-tests-using-capybara)
|
31
|
+
- [Run Database Tests Using `infrataster-plugin-mysql` Gem with Docker Compose](#run-database-tests-using-infrataster-plugin-mysql-gem-with-docker-compose)
|
32
|
+
- [Run Different Tests on Each Platform](#run-different-tests-on-each-platform)
|
33
|
+
- [Real-world Examples](#real-world-examples)
|
34
|
+
- [Prepare Your Ruby Environment](#prepare-your-ruby-environment)
|
35
|
+
- [Travis CI Configuration Example](#travis-ci-configuration-example)
|
36
|
+
- [CircleCI Configuration Example](#circleci-configuration-example)
|
37
|
+
- [Testing](#testing)
|
38
|
+
- [Contributing](#contributing)
|
39
|
+
- [TODO](#todo)
|
40
|
+
- [License and Author](#license-and-author)
|
41
|
+
|
20
42
|
## Requirements
|
21
43
|
|
22
|
-
* Ruby `2` or higher.
|
44
|
+
* Ruby `2.2` or higher.
|
23
45
|
* Recommended Docker `1.7` or higher.
|
24
46
|
|
25
47
|
## Installation
|
@@ -44,6 +66,33 @@ $ bundle
|
|
44
66
|
|
45
67
|
**Warning:** As the gem is in its early development stages, [the API is very likely to break between minor versions](http://semver.org/).
|
46
68
|
|
69
|
+
## Documentation
|
70
|
+
|
71
|
+
- Latest release documentation: http://www.rubydoc.info/gems/dockerspec
|
72
|
+
- Master unreleased documentation: http://www.rubydoc.info/github/zuazo/dockerspec
|
73
|
+
|
74
|
+
Specific documentation sections for resources or functions that can be used to generate test cases:
|
75
|
+
|
76
|
+
- [`docker_build`](http://www.rubydoc.info/gems/dockerspec/Dockerspec/RSpec/Resources#docker_build-instance_method)
|
77
|
+
- [*Docker Build* helpers](http://www.rubydoc.info/gems/dockerspec/Dockerspec/Builder/ConfigHelpers)
|
78
|
+
- [`docker_run`](http://www.rubydoc.info/gems/dockerspec/Dockerspec/RSpec/Resources#docker_run-instance_method)
|
79
|
+
- [*Docker Run* helpers](http://www.rubydoc.info/gems/dockerspec/Dockerspec/Runner/ConfigHelpers)
|
80
|
+
- [*Docker Run* Serverspec resource types](http://serverspec.org/resource_types.html)
|
81
|
+
- [Infrataster Resources](http://www.rubydoc.info/gems/infrataster#Resources)
|
82
|
+
- [Capybara DSL](http://www.rubydoc.info/gems/capybara#The_DSL)
|
83
|
+
- [`docker_compose`](http://www.rubydoc.info/gems/dockerspec/Dockerspec/RSpec/Resources#docker_compose-instance_method)
|
84
|
+
- [`its_container`](http://www.rubydoc.info/gems/dockerspec/Dockerspec/RSpec/Resources#its_container-instance_method)
|
85
|
+
|
86
|
+
### Presentations
|
87
|
+
|
88
|
+
Apart from the official documentation, [Nan Liu](https://github.com/nanliu) presented a talk for [Portland Docker user group](https://www.meetup.com/Docker-Portland-OR/events/236739986/) regarding how to use Dockerspec in a container:
|
89
|
+
|
90
|
+
- [Trust, but verify | Testing with Docker Containers](http://www.slideshare.net/NanLiu1/trust-but-verify-testing-with-docker-containers)
|
91
|
+
|
92
|
+
<a href="https://www.slideshare.net/NanLiu1/trust-but-verify-testing-with-docker-containers">
|
93
|
+
<img src="https://i.gyazo.com/fe45a36c2e329af317482c280a09dfab.png" alt="Trust, but verify | Testing with Docker Containers" width="300px">
|
94
|
+
</a>
|
95
|
+
|
47
96
|
## Usage Examples
|
48
97
|
|
49
98
|
### Run Tests Against a Dockerfile in the Current Directory
|
@@ -75,7 +124,7 @@ describe 'My Dockerfile' do
|
|
75
124
|
end
|
76
125
|
```
|
77
126
|
|
78
|
-
See the documentation above for more examples.
|
127
|
+
See [the documentation above](#documentation) for more examples.
|
79
128
|
|
80
129
|
### Run Tests Against Docker Compose
|
81
130
|
|
@@ -93,6 +142,8 @@ describe docker_compose('.', wait: 30) do
|
|
93
142
|
end
|
94
143
|
|
95
144
|
its_container(:db) do
|
145
|
+
its(:stdout) { should include 'MySQL init process done.' }
|
146
|
+
|
96
147
|
describe process('mysqld') do
|
97
148
|
it { should be_running }
|
98
149
|
end
|
@@ -104,6 +155,54 @@ end
|
|
104
155
|
|
105
156
|
**Important Warning:** The `docker_compose` resource uses the [`docker-compose-api`](https://rubygems.org/gems/docker-compose-api) Ruby gem to emulate Docker Compose. So, some *docker-compose.yml* configuration options may not be supported yet or may not work exactly the same. Let us know if you find any bug or you need a missing feature. And thanks to [Mauricio Klein](https://github.com/mauricioklein) for all his work by the way!
|
106
157
|
|
158
|
+
### Checking Container Logs
|
159
|
+
|
160
|
+
To check the running container logs content, you can use [the `stdout` and `stderr` helpers](http://www.rubydoc.info/gems/dockerspec/Dockerspec/Runner/ConfigHelpers) inside `docker_run` or `its_container` blocks.
|
161
|
+
|
162
|
+
For example:
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
require 'dockerspec/serverspec'
|
166
|
+
|
167
|
+
describe 'My Dockerfile' do
|
168
|
+
describe docker_build('.') do
|
169
|
+
describe docker_run(described_image) do
|
170
|
+
its(:stdout) { should include 'Successfully Started.' }
|
171
|
+
its(:stderr) { should eq '' }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
```
|
176
|
+
|
177
|
+
### Retrying Tests That Fail Temporarily
|
178
|
+
|
179
|
+
This gem includes the [`rspec-retry`](https://github.com/NoRedInk/rspec-retry) gem. So, you can add `:retry` to the RSpec metadata in order to retry some tests multiple times.
|
180
|
+
|
181
|
+
For example:
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
describe docker_run('mariadb') do
|
185
|
+
its(:stdout, retry: 30) { should include 'MySQL init process done.' }
|
186
|
+
end
|
187
|
+
```
|
188
|
+
|
189
|
+
By default, it will do a sleep of 1 second between each retry. You can adjust it with `:retry_wait`. See [`rspec-retry` documentation](http://www.rubydoc.info/gems/rspec-retry/0.4.5) for more details.
|
190
|
+
|
191
|
+
You can also make all tests within a block retry:
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
describe docker_run('mariadb'), retry: 30 do
|
195
|
+
its(:stdout) { should include 'MySQL init process done.' }
|
196
|
+
its(:stderr) { should include 'MySQL init process done.' }
|
197
|
+
|
198
|
+
describe command('mysqld -V'), retry: 1 do # disable retries here
|
199
|
+
its(:stdout) { should match(/^mysqld .*MariaDB/i) }
|
200
|
+
end
|
201
|
+
end
|
202
|
+
```
|
203
|
+
|
204
|
+
The same applies for `its_container` blocks.
|
205
|
+
|
107
206
|
### Run HTTP Tests Using Infrataster
|
108
207
|
|
109
208
|
```ruby
|
@@ -241,16 +340,38 @@ describe docker_compose('docker-compose.yml', wait: 60) do
|
|
241
340
|
end
|
242
341
|
```
|
243
342
|
|
244
|
-
|
343
|
+
### Run Different Tests on Each Platform
|
245
344
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
345
|
+
Sometimes, you may want to be able to run different tests depending on the platform. You can use Serverspec's `os` helper method for that:
|
346
|
+
|
347
|
+
```ruby
|
348
|
+
require 'dockerspec/serverspec'
|
349
|
+
|
350
|
+
describe docker_build('.', tag: 'mywebapp') do
|
351
|
+
describe docker_run('mywebapp') do
|
352
|
+
case os[:family]
|
353
|
+
when 'debian'
|
354
|
+
|
355
|
+
describe file('/etc/debian_version') do
|
356
|
+
it { should exist }
|
357
|
+
end
|
358
|
+
|
359
|
+
# [...]
|
360
|
+
|
361
|
+
when 'alpine'
|
362
|
+
|
363
|
+
describe file('/etc/alpine-release') do
|
364
|
+
it { should exist }
|
365
|
+
end
|
366
|
+
|
367
|
+
# [...]
|
368
|
+
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
```
|
373
|
+
|
374
|
+
For more details, see [Serverspec documenation on how to get OS information](http://serverspec.org/advanced_tips.html#how-to-get-os-information).
|
254
375
|
|
255
376
|
### Real-world Examples
|
256
377
|
|
@@ -282,6 +403,29 @@ $ mkdir spec
|
|
282
403
|
|
283
404
|
#### 3. Add your tests to a file with the *spec/myapp_spec.rb* format:
|
284
405
|
|
406
|
+
With this gem, you can use both [Serverspec](http://serverspec.org/) and [Infrataster](https://github.com/ryotarai/infrataster) tests.
|
407
|
+
|
408
|
+
If you just want to use [Serverspec](http://serverspec.org/) tests:
|
409
|
+
|
410
|
+
```ruby
|
411
|
+
require 'dockerspec/serverspec'
|
412
|
+
```
|
413
|
+
|
414
|
+
If you just want to use [Infrataster](https://github.com/ryotarai/infrataster) tests:
|
415
|
+
|
416
|
+
```ruby
|
417
|
+
require 'dockerspec/infrataster'
|
418
|
+
```
|
419
|
+
|
420
|
+
But, of course, you can use both types of tests if you want:
|
421
|
+
|
422
|
+
```ruby
|
423
|
+
require 'dockerspec/serverspec'
|
424
|
+
require 'dockerspec/infrataster'
|
425
|
+
```
|
426
|
+
|
427
|
+
For example, you can create a file in *spec/myapp_spec.rb* with the following content:
|
428
|
+
|
285
429
|
```ruby
|
286
430
|
# spec/myapp_spec.rb
|
287
431
|
|
data/TODO.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# TODO for Dockerspec
|
2
2
|
|
3
|
+
* [ ] Log parsing contains `"\x00"` chars.
|
3
4
|
* [ ] Integrate with [Inspec](https://www.chef.io/inspec/).
|
4
5
|
* [ ] Test resources for built images supported inside `docker_compose`.
|
5
6
|
* [ ] Add `docker_context`, `docker_describe` to avoid starting all containers at the same time.
|
data/lib/dockerspec/builder.rb
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
|
20
20
|
require 'rspec'
|
21
21
|
require 'rspec/its'
|
22
|
+
require 'rspec/retry'
|
22
23
|
require 'tmpdir'
|
23
24
|
require 'erubis'
|
24
25
|
require 'dockerspec/docker_gem'
|
@@ -75,7 +76,7 @@ module Dockerspec
|
|
75
76
|
# used when the `:template` source is used.
|
76
77
|
# @option opts [String] :tag Repository tag to be applied to the resulting
|
77
78
|
# image.
|
78
|
-
# @option opts [
|
79
|
+
# @option opts [Integer, Symbol] :log_level Sets the docker library
|
79
80
|
# verbosity level. Possible values:
|
80
81
|
# `:silent` or `0` (no output),
|
81
82
|
# `:ci` or `1` (enables some outputs recommended for CI environments),
|
@@ -272,6 +273,8 @@ module Dockerspec
|
|
272
273
|
# generates the temporary Dockerfile.
|
273
274
|
#
|
274
275
|
# @param string [String] The Dockerfile content.
|
276
|
+
# @param dir [String] The directory to copy the files from. Files that are
|
277
|
+
# required by the Dockerfile passed in *string*.
|
275
278
|
#
|
276
279
|
# @return void
|
277
280
|
#
|
@@ -31,7 +31,7 @@ module Dockerspec
|
|
31
31
|
#
|
32
32
|
# Creates a logger object.
|
33
33
|
#
|
34
|
-
# @param type [
|
34
|
+
# @param type [Integer, Symbol] The logger to create. Possible values:
|
35
35
|
# `:silent` or `0` (no output),
|
36
36
|
# `:ci` or `1` (enables some outputs recommended for CI environments),
|
37
37
|
# `:info` or `2` (gives information about main build steps),
|
@@ -66,8 +66,11 @@ module Dockerspec
|
|
66
66
|
# @api public
|
67
67
|
#
|
68
68
|
def restore
|
69
|
-
instance_set(@saved_backend_instance)
|
70
|
-
::Specinfra.configuration.backend
|
69
|
+
backend_class.instance_set(@saved_backend_instance)
|
70
|
+
if ::Specinfra.configuration.backend != @saved_backend_name
|
71
|
+
backend_class.host_reset
|
72
|
+
::Specinfra.configuration.backend = @saved_backend_name
|
73
|
+
end
|
71
74
|
end
|
72
75
|
|
73
76
|
#
|
@@ -98,7 +101,7 @@ module Dockerspec
|
|
98
101
|
# @api public
|
99
102
|
#
|
100
103
|
def reset
|
101
|
-
instance_set(nil)
|
104
|
+
backend_class.instance_set(nil)
|
102
105
|
end
|
103
106
|
|
104
107
|
#
|
@@ -117,22 +120,6 @@ module Dockerspec
|
|
117
120
|
|
118
121
|
protected
|
119
122
|
|
120
|
-
#
|
121
|
-
# Sets the Specinfra backend.
|
122
|
-
#
|
123
|
-
# Used by {.load}.
|
124
|
-
#
|
125
|
-
# @param instance [Specinfra::Backend::Base] The Specinfra backend
|
126
|
-
# object.
|
127
|
-
#
|
128
|
-
# @return void
|
129
|
-
#
|
130
|
-
# @api private
|
131
|
-
#
|
132
|
-
def instance_set(instance)
|
133
|
-
backend_class.instance_set(instance)
|
134
|
-
end
|
135
|
-
|
136
123
|
#
|
137
124
|
# Returns the current Specinfra backend object.
|
138
125
|
#
|
@@ -53,46 +53,26 @@ module Dockerspec
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
#
|
57
|
-
# Searches for an object in the description of the parent RSpec examples.
|
58
|
-
#
|
59
|
-
# @param metadata [Hash] RSpec metadata.
|
60
|
-
# @param klass [Class] Type of object to search.
|
61
|
-
#
|
62
|
-
# @return [Object] Returns the object if found. `nil` if not found.
|
63
|
-
#
|
64
|
-
# @api public
|
65
|
-
#
|
66
|
-
def self.search_object(metadata, klass)
|
67
|
-
return nil if metadata.nil?
|
68
|
-
if metadata[:described_class].is_a?(klass)
|
69
|
-
metadata[:described_class]
|
70
|
-
elsif metadata_has_parent?(metadata)
|
71
|
-
search_object(metadata_parent(metadata), klass)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
56
|
#
|
76
57
|
# Searches for an object in the description of the parent RSpec examples
|
77
58
|
# that implements a specific method.
|
78
59
|
#
|
79
60
|
# @param metadata [Hash] RSpec metadata.
|
80
61
|
# @param meth [Symbol] The method name.
|
81
|
-
# @param arity [Integer] The arity of the method.
|
82
62
|
#
|
83
63
|
# @return [Array<Object>] Returns the objects list.
|
84
64
|
#
|
85
65
|
# @api public
|
86
66
|
#
|
87
|
-
def self.search_objects_with(metadata, meth
|
67
|
+
def self.search_objects_with(metadata, meth)
|
88
68
|
o_ary = []
|
89
69
|
return o_ary if metadata.nil?
|
90
70
|
if metadata[:described_class].respond_to?(meth) &&
|
91
|
-
metadata[:described_class]
|
71
|
+
metadata[:described_class] != self
|
92
72
|
o_ary << metadata[:described_class]
|
93
73
|
end
|
94
74
|
return o_ary unless metadata_has_parent?(metadata)
|
95
|
-
search_objects_with(metadata_parent(metadata), meth
|
75
|
+
(search_objects_with(metadata_parent(metadata), meth) + o_ary).uniq
|
96
76
|
end
|
97
77
|
|
98
78
|
#
|
@@ -105,7 +85,7 @@ module Dockerspec
|
|
105
85
|
# RSpec.configure do |c|
|
106
86
|
# c.before(:each) do
|
107
87
|
# metadata = RSpec.current_example.metadata
|
108
|
-
# Dockerspec::Runner::Base.
|
88
|
+
# Dockerspec::Runner::Base.restore_rspec_context(metadata)
|
109
89
|
# end
|
110
90
|
# end
|
111
91
|
#
|
@@ -120,7 +100,7 @@ module Dockerspec
|
|
120
100
|
def self.restore_rspec_context(metadata)
|
121
101
|
o_ary =
|
122
102
|
Helper::RSpecExampleHelpers
|
123
|
-
.search_objects_with(metadata, :restore_rspec_context
|
103
|
+
.search_objects_with(metadata, :restore_rspec_context)
|
124
104
|
o_ary.each(&:restore_rspec_context)
|
125
105
|
end
|
126
106
|
end
|
@@ -24,6 +24,10 @@
|
|
24
24
|
#
|
25
25
|
RSpec.configure do |config|
|
26
26
|
config.color = true
|
27
|
-
config.formatter = :documentation
|
28
|
-
config.tty =
|
27
|
+
config.formatter = :documentation if config.formatters.empty?
|
28
|
+
config.tty = $stdout.tty? if config.tty.nil?
|
29
|
+
|
30
|
+
# rspec-retry
|
31
|
+
config.verbose_retry = true if ENV['CI'] == 'true'
|
32
|
+
config.default_sleep_interval = 1
|
29
33
|
end
|
@@ -188,7 +188,7 @@ module Dockerspec
|
|
188
188
|
# used when the `:template` source is used.
|
189
189
|
# @option opts [String] :tag Repository tag to be applied to the resulting
|
190
190
|
# image.
|
191
|
-
# @option opts [
|
191
|
+
# @option opts [Integer, Symbol] :log_level Sets the docker library
|
192
192
|
# verbosity level. Possible values:
|
193
193
|
# `:silent` or `0` (no output),
|
194
194
|
# `:ci` or `1` (enables some outputs recommended for CI environments),
|
@@ -356,6 +356,7 @@ module Dockerspec
|
|
356
356
|
def docker_run(*opts)
|
357
357
|
runner = Dockerspec::Configuration.docker_runner.new(*opts)
|
358
358
|
runner.run
|
359
|
+
runner.restore_rspec_context
|
359
360
|
described_container(runner.container_name)
|
360
361
|
runner
|
361
362
|
end
|
@@ -418,7 +419,7 @@ module Dockerspec
|
|
418
419
|
# @option opts [Symbol] :backend (calculated) Docker backend to use:
|
419
420
|
# `:docker_compose`, `:docker_compose_lxc`.
|
420
421
|
#
|
421
|
-
# @return [
|
422
|
+
# @return [String] A description of the object.
|
422
423
|
#
|
423
424
|
# @raise [Dockerspec::DockerRunArgumentError] Raises this exception when
|
424
425
|
# some required fields are missing.
|
@@ -433,6 +434,10 @@ module Dockerspec
|
|
433
434
|
def docker_compose(*opts)
|
434
435
|
runner = Dockerspec::Configuration.compose_runner.new(*opts)
|
435
436
|
runner.run
|
437
|
+
# Disable storing Runner object on RSpec metadata, to avoid calling its
|
438
|
+
# {Runner#restore_rspec_context} method that it is also called in
|
439
|
+
# {ItsContainer#restore_rspec_context}:
|
440
|
+
runner.to_s
|
436
441
|
end
|
437
442
|
|
438
443
|
#
|
@@ -500,7 +505,9 @@ module Dockerspec
|
|
500
505
|
# `:alpine`, `:arch`, `:coreos`, `:debian`, `:gentoo`, `:nixos`,
|
501
506
|
# `:plamo`, `:poky`, `:redhat`, `:suse`.
|
502
507
|
#
|
503
|
-
# @
|
508
|
+
# @yield [] the block to run with the tests.
|
509
|
+
#
|
510
|
+
# @return void
|
504
511
|
#
|
505
512
|
# @raise [Dockerspec::DockerComposeError] Raises this exception when
|
506
513
|
# you call `its_container` without calling `docker_compose`.
|
@@ -513,9 +520,10 @@ module Dockerspec
|
|
513
520
|
raise ItsContainerError, ItsContainer::NO_DOCKER_COMPOSE_MESSAGE
|
514
521
|
end
|
515
522
|
container_opts = opts[0].is_a?(Hash) ? opts[0] : {}
|
516
|
-
|
523
|
+
its_container = ItsContainer.new(container, compose)
|
524
|
+
its_container.restore_rspec_context(container_opts)
|
517
525
|
described_container(compose.container_name)
|
518
|
-
describe(
|
526
|
+
describe(its_container, *opts, &block)
|
519
527
|
end
|
520
528
|
|
521
529
|
#
|
@@ -18,6 +18,7 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
require 'dockerspec/runner/compose'
|
21
|
+
require 'dockerspec/runner/config_helpers'
|
21
22
|
require 'dockerspec/helper/rspec_example_helpers'
|
22
23
|
require 'dockerspec/exceptions'
|
23
24
|
|
@@ -28,6 +29,8 @@ module Dockerspec
|
|
28
29
|
# This generates the object to use within `its_container` calls.
|
29
30
|
#
|
30
31
|
class ItsContainer
|
32
|
+
include Dockerspec::Runner::ConfigHelpers
|
33
|
+
|
31
34
|
#
|
32
35
|
# A message with description on how to avoid the error when you forget
|
33
36
|
# specifying the docker container you want to test with Docker Compose.
|
@@ -50,22 +53,27 @@ For example:
|
|
50
53
|
#
|
51
54
|
# Constructs a `its_container` object.
|
52
55
|
#
|
53
|
-
# @param
|
56
|
+
# @param container_name [String] The name of the container.
|
57
|
+
# @param compose [Dockerspec::Runner::Compose] The compose object we
|
58
|
+
# working with.
|
54
59
|
#
|
55
60
|
# @return [Dockerspec::RSpec::Resource::ItsContainer] The
|
56
61
|
# `its_container` object.
|
57
62
|
#
|
58
63
|
# @api public
|
59
64
|
#
|
60
|
-
def initialize(
|
61
|
-
@
|
65
|
+
def initialize(container_name, compose)
|
66
|
+
@container_name = container_name
|
67
|
+
@compose = compose
|
62
68
|
end
|
63
69
|
|
64
70
|
#
|
65
|
-
# Restores the testing context
|
71
|
+
# Restores the testing context.
|
66
72
|
#
|
67
|
-
#
|
68
|
-
#
|
73
|
+
# This is required for tests to run correctly if we are testing
|
74
|
+
# different containers within the same tests. That is because RSpec has
|
75
|
+
# two stages, one in which it generates the tests and another in which
|
76
|
+
# it runs them.
|
69
77
|
#
|
70
78
|
# This is called from the `before` block in the
|
71
79
|
# *lib/dockerspec/runner/base.rb* file:
|
@@ -84,14 +92,26 @@ For example:
|
|
84
92
|
#
|
85
93
|
# @api public
|
86
94
|
#
|
87
|
-
def restore_rspec_context
|
88
|
-
|
89
|
-
compose
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
+
def restore_rspec_context(opts = nil)
|
96
|
+
@compose.select_container(@container_name, opts)
|
97
|
+
@compose.restore_rspec_context
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Gets the selected container object.
|
102
|
+
#
|
103
|
+
# This method is used in {Dockerspec::Runner::ConfigHelpers} to get
|
104
|
+
# information from the selected container.
|
105
|
+
#
|
106
|
+
# @return [Docker::Container] The container object.
|
107
|
+
#
|
108
|
+
# @raise [Dockerspec::RunnerError] When cannot select the container to
|
109
|
+
# test.
|
110
|
+
#
|
111
|
+
# @api public
|
112
|
+
#
|
113
|
+
def container
|
114
|
+
@compose.container
|
95
115
|
end
|
96
116
|
|
97
117
|
#
|
@@ -102,7 +122,7 @@ For example:
|
|
102
122
|
# @api public
|
103
123
|
#
|
104
124
|
def to_s
|
105
|
-
"\"#{@
|
125
|
+
"\"#{@container_name}\" container"
|
106
126
|
end
|
107
127
|
end
|
108
128
|
end
|
@@ -19,6 +19,7 @@
|
|
19
19
|
|
20
20
|
require 'dockerspec/exceptions'
|
21
21
|
require 'dockerspec/engine_list'
|
22
|
+
require 'dockerspec/runner/config_helpers'
|
22
23
|
require 'dockerspec/helper/rspec_example_helpers'
|
23
24
|
|
24
25
|
module Dockerspec
|
@@ -28,6 +29,8 @@ module Dockerspec
|
|
28
29
|
# start docker containers.
|
29
30
|
#
|
30
31
|
class Base
|
32
|
+
include Dockerspec::Runner::ConfigHelpers
|
33
|
+
|
31
34
|
#
|
32
35
|
# The option key to set when you pass a string instead of a hash of
|
33
36
|
# options.
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Author:: Xabier de Zuazo (<xabier@zuazo.org>)
|
4
|
+
# Copyright:: Copyright (c) 2017 Xabier de Zuazo
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
module Dockerspec
|
21
|
+
module Runner
|
22
|
+
#
|
23
|
+
# Some helpers to get information from a running container.
|
24
|
+
#
|
25
|
+
module ConfigHelpers
|
26
|
+
#
|
27
|
+
# Parse the stdout/stderr log binary stream.
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# parse_log("String1") #=> "String1"
|
31
|
+
# parse_log("\x02\x00\x00\x00\x00\x00\x00\aSTDERR") #=> "STDERR"
|
32
|
+
#
|
33
|
+
# @param log [String] log to parse in binary format.
|
34
|
+
# @return [String] parsed log.
|
35
|
+
#
|
36
|
+
# @api private
|
37
|
+
#
|
38
|
+
def parse_log(log)
|
39
|
+
log.sub(/^.*?\a/, '')
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Returns the container *stdout* logs.
|
44
|
+
#
|
45
|
+
# @example Docker Run Example
|
46
|
+
# describe docker_run('mysql') do
|
47
|
+
# its(:stdout) { should include 'MySQL init process done.' }
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# @example Docker Compose Example
|
51
|
+
# describe docker_compose('.', wait: 30) do
|
52
|
+
# describe its_container(:db) do
|
53
|
+
# its(:stdout) { should include 'MySQL init process done.' }
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
# @return [String] The *stdout* logs.
|
58
|
+
#
|
59
|
+
# @raise [Dockerspec::RunnerError] When cannot select the container to
|
60
|
+
# test.
|
61
|
+
#
|
62
|
+
# @api public
|
63
|
+
#
|
64
|
+
def stdout
|
65
|
+
log = container.logs(stdout: true)
|
66
|
+
parse_log(log)
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Returns the container *stderr* logs.
|
71
|
+
#
|
72
|
+
# @example Docker Run Example
|
73
|
+
# describe docker_run('mysql') do
|
74
|
+
# its(:stderr) { should include 'mysqld: ready for connections.' }
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# @example Docker Compose Example
|
78
|
+
# describe docker_compose('.', wait: 30) do
|
79
|
+
# describe its_container(:myapp) do
|
80
|
+
# its(:stderr) { should eq '' }
|
81
|
+
# end
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# @return [String] The *stderr* logs.
|
85
|
+
#
|
86
|
+
# @raise [Dockerspec::RunnerError] When cannot select the container to
|
87
|
+
# test.
|
88
|
+
#
|
89
|
+
# @api public
|
90
|
+
#
|
91
|
+
def stderr
|
92
|
+
log = container.logs(stderr: true).to_s
|
93
|
+
parse_log(log)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/dockerspec/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockerspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xabier de Zuazo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docker-api
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-retry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.5.3
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.5.3
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: serverspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -325,6 +339,7 @@ files:
|
|
325
339
|
- lib/dockerspec/runner.rb
|
326
340
|
- lib/dockerspec/runner/base.rb
|
327
341
|
- lib/dockerspec/runner/compose.rb
|
342
|
+
- lib/dockerspec/runner/config_helpers.rb
|
328
343
|
- lib/dockerspec/runner/docker.rb
|
329
344
|
- lib/dockerspec/runner/serverspec.rb
|
330
345
|
- lib/dockerspec/runner/serverspec/base.rb
|
@@ -355,10 +370,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
355
370
|
version: '0'
|
356
371
|
requirements: []
|
357
372
|
rubyforge_project:
|
358
|
-
rubygems_version: 2.
|
373
|
+
rubygems_version: 2.6.9
|
359
374
|
signing_key:
|
360
375
|
specification_version: 4
|
361
376
|
summary: Dockerspec
|
362
377
|
test_files:
|
363
378
|
- spec/spec_helper.rb
|
364
|
-
has_rdoc:
|