Skip to content

Commit f56e038

Browse files
tancnlebethesque
authored andcommitted
chore: add docker image for development (pact-foundation#280)
* Refactor test to verify on general error case - Duplicate cert error is already verified in Ruby spec - Duplicate cert error does not always throw error (ie. for OpenSSL < 1.1.1) * Add Dockerfile for testing/development purposes * Update developer setup doc
1 parent ba0e03c commit f56e038

File tree

4 files changed

+75
-25
lines changed

4 files changed

+75
-25
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/.git
2+
tmp

DEVELOPER_SETUP.md

+40-20
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,55 @@
11
# Developer setup
22

3+
## Preparation
4+
5+
### With virtual battery
6+
7+
* Build an initial local image with Docker
8+
```sh
9+
docker build --rm -t pact_broker:dev .
10+
```
11+
12+
* Spin up a container with mounted volume and open an interactive shell session
13+
```sh
14+
docker run --rm -v $(PWD):/app -w /app -it pact_broker:dev bash
15+
```
16+
17+
### With native install
18+
319
* You will need to install Ruby 2.5, and preferably a ruby version manager. I recommend using [chruby][chruby] and [ruby-install][ruby-install].
420
* Install bundler (the Ruby gem dependency manager) `gem install bundler`
521
* Check out the pact_broker repository and cd into it.
622
* Run `bundle install`. If you have not got mysql or postgres installed locally, comment out the `mysql2` and `pg` development dependency lines in `pact_broker.gemspec`, as these are only really required on Travis.
7-
* Run `bundle exec rake pact_broker:dev:setup`. This will create an example application that you can run locally, that uses the local source code.
8-
* To run the example:
923

10-
cd dev
11-
bundle install
12-
bundle exec rackup
24+
## Running a local application
1325

26+
* Run `bundle exec rake pact_broker:dev:setup`. This will create an example application that you can run locally, that uses the local source code.
27+
* To run the example:
28+
```sh
29+
cd dev
30+
bundle install
31+
bundle exec rackup
32+
```
1433
* The application will be available on `http://localhost:9292`
1534

1635
## Running the tests
1736

18-
To run everything (specs, pact verifications, vulnerability scan...):
19-
20-
`bundle exec rake`
21-
22-
To run a smaller subset of the tests:
23-
24-
`bundle exec rake spec`
25-
26-
To run the "quick tests" (skip the lengthy migration specs)
27-
28-
`bundle exec rake spec:quick`
29-
30-
To run a single spec:
31-
32-
`bundle exec rspec path_to_your_spec.rb`
37+
* To run everything (specs, pact verifications, vulnerability scan...):
38+
```sh
39+
bundle exec rake
40+
```
41+
* To run a smaller subset of the tests:
42+
```sh
43+
bundle exec rake spec
44+
```
45+
* To run the "quick tests" (skip the lengthy migration specs)
46+
```sh
47+
bundle exec rake spec:quick
48+
```
49+
* To run a single spec:
50+
```sh
51+
bundle exec rspec path_to_your_spec.rb
52+
```
3353

3454
[chruby]: https://github.com/postmodern/chruby
3555
[ruby-install]: https://github.com/postmodern/ruby-install

Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM ruby:2.5.3-alpine
2+
3+
RUN apk update \
4+
&& apk --no-cache add \
5+
"build-base>=0.5" \
6+
"bash>=4.4" \
7+
"ca-certificates>=20190108" \
8+
"git>=2.20" \
9+
"postgresql-dev>=11.3" \
10+
"sqlite-dev>=3.28" \
11+
"sqlite>=3.28" \
12+
"tzdata>=2019" \
13+
&& rm -rf /var/cache/apk/*
14+
15+
WORKDIR /app
16+
17+
COPY . ./
18+
19+
RUN gem install bundler -v '~>2.0.0' \
20+
&& bundle install --jobs 3 --retry 3
21+
22+
CMD []

spec/lib/pact_broker/certificates/service_spec.rb

+11-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module PactBroker
44
module Certificates
55
describe Service do
66
let(:certificate_content) { File.read('spec/fixtures/certificate.pem') }
7-
let(:logger) { double('logger').as_null_object }
7+
let(:logger) { spy('logger') }
88

99
before do
1010
allow(Service).to receive(:logger).and_return(logger)
@@ -17,19 +17,25 @@ module Certificates
1717
expect(subject).to be_instance_of(OpenSSL::X509::Store)
1818
end
1919

20-
context "when there is a duplicate certificate" do
20+
context "when there is an error adding certificate" do
21+
let(:cert_store) { instance_spy(OpenSSL::X509::Store) }
22+
2123
before do
2224
Certificate.create(uuid: '1234', content: certificate_content)
23-
Certificate.create(uuid: '5678', content: certificate_content)
25+
26+
allow(cert_store).to receive(:add_cert).and_raise(StandardError)
27+
allow(OpenSSL::X509::Store).to receive(:new).and_return(cert_store)
2428
end
2529

2630
it "logs the error" do
27-
expect(Service).to receive(:log_error).with(anything, /Error adding certificate/).at_least(1).times
2831
subject
32+
33+
expect(logger).to have_received(:error)
34+
.with(/Error adding certificate/).at_least(1).times
2935
end
3036

3137
it "returns an OpenSSL::X509::Store" do
32-
expect(subject).to be_instance_of(OpenSSL::X509::Store)
38+
expect(subject).to be(cert_store)
3339
end
3440
end
3541
end

0 commit comments

Comments
 (0)