Skip to content

Commit

Permalink
chore: add docker image for development (#280)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tancnle authored and bethesque committed Jun 27, 2019
1 parent ba0e03c commit f56e038
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/.git
tmp
60 changes: 40 additions & 20 deletions DEVELOPER_SETUP.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
# Developer setup

## Preparation

### With virtual battery

* Build an initial local image with Docker
```sh
docker build --rm -t pact_broker:dev .
```

* Spin up a container with mounted volume and open an interactive shell session
```sh
docker run --rm -v $(PWD):/app -w /app -it pact_broker:dev bash
```

### With native install

* You will need to install Ruby 2.5, and preferably a ruby version manager. I recommend using [chruby][chruby] and [ruby-install][ruby-install].
* Install bundler (the Ruby gem dependency manager) `gem install bundler`
* Check out the pact_broker repository and cd into it.
* 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.
* 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.
* To run the example:

cd dev
bundle install
bundle exec rackup
## Running a local application

* 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.
* To run the example:
```sh
cd dev
bundle install
bundle exec rackup
```
* The application will be available on `http://localhost:9292`

## Running the tests

To run everything (specs, pact verifications, vulnerability scan...):

`bundle exec rake`

To run a smaller subset of the tests:

`bundle exec rake spec`

To run the "quick tests" (skip the lengthy migration specs)

`bundle exec rake spec:quick`

To run a single spec:

`bundle exec rspec path_to_your_spec.rb`
* To run everything (specs, pact verifications, vulnerability scan...):
```sh
bundle exec rake
```
* To run a smaller subset of the tests:
```sh
bundle exec rake spec
```
* To run the "quick tests" (skip the lengthy migration specs)
```sh
bundle exec rake spec:quick
```
* To run a single spec:
```sh
bundle exec rspec path_to_your_spec.rb
```

[chruby]: https://github.com/postmodern/chruby
[ruby-install]: https://github.com/postmodern/ruby-install
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ruby:2.5.3-alpine

RUN apk update \
&& apk --no-cache add \
"build-base>=0.5" \
"bash>=4.4" \
"ca-certificates>=20190108" \
"git>=2.20" \
"postgresql-dev>=11.3" \
"sqlite-dev>=3.28" \
"sqlite>=3.28" \
"tzdata>=2019" \
&& rm -rf /var/cache/apk/*

WORKDIR /app

COPY . ./

RUN gem install bundler -v '~>2.0.0' \
&& bundle install --jobs 3 --retry 3

CMD []
16 changes: 11 additions & 5 deletions spec/lib/pact_broker/certificates/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module PactBroker
module Certificates
describe Service do
let(:certificate_content) { File.read('spec/fixtures/certificate.pem') }
let(:logger) { double('logger').as_null_object }
let(:logger) { spy('logger') }

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

context "when there is a duplicate certificate" do
context "when there is an error adding certificate" do
let(:cert_store) { instance_spy(OpenSSL::X509::Store) }

before do
Certificate.create(uuid: '1234', content: certificate_content)
Certificate.create(uuid: '5678', content: certificate_content)

allow(cert_store).to receive(:add_cert).and_raise(StandardError)
allow(OpenSSL::X509::Store).to receive(:new).and_return(cert_store)
end

it "logs the error" do
expect(Service).to receive(:log_error).with(anything, /Error adding certificate/).at_least(1).times
subject

expect(logger).to have_received(:error)
.with(/Error adding certificate/).at_least(1).times
end

it "returns an OpenSSL::X509::Store" do
expect(subject).to be_instance_of(OpenSSL::X509::Store)
expect(subject).to be(cert_store)
end
end
end
Expand Down

0 comments on commit f56e038

Please sign in to comment.