Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Implemented from scratch integration tests
Browse files Browse the repository at this point in the history
I've also fixed a couple of small nitpicks in the current testing setup.

Fixes #1667

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Mar 13, 2018
1 parent 32a4d08 commit f297fd7
Show file tree
Hide file tree
Showing 29 changed files with 1,185 additions and 34 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ vagrant
packaging
log/*
.DS_Store
.bundle/config
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/public/assets
/config/config-local.yml
/bin/portus
/bin/integration/init
/docker-compose.overlay.yml
/spec/integration/fixtures/config.yml
/spec/integration/fixtures/data
Expand Down
31 changes: 7 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ before_install:
- sudo apt-get install yarn
- yarn install

# Install bats.
- git clone https://github.com/sstephenson/bats.git
- cd bats
- sudo ./install.sh /usr/local
- cd .. && rm -rf bats

# Intall Go, which is needed for git-validation
- eval "$(curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | GIMME_GO_VERSION=1.8 bash)"
- go get -u github.com/vbatts/git-validation
Expand All @@ -40,30 +46,7 @@ before_script:
- psql -c 'create database portus_test' -U postgres

script:
# Compile assets
- bundle exec rake portus:assets:compile

# Ruby tests
- bundle exec rspec spec

# Style and security checks
- bundle exec rubocop -V
- bundle exec rubocop -F

# Note: it ignores a couple of files which use ruby 2.5 syntax which brakeman
# does not know how to handle...
- bundle exec brakeman --skip-files lib/portus/background/sync.rb,lib/portus/registry_client.rb

- bundle exec rake portus:annotate_and_exit

# JavaScript tests
- yarn test

# JavaScript style
- yarn eslint

# Test commit messages
- bundle exec rake test:git
- chmod +x bin/ci.sh && ./bin/ci.sh

env:
global:
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ RUN zypper ref && \
update-alternatives --install /usr/bin/bundler bundler /usr/bin/bundler.ruby2.5 3 && \
bundle install --retry=3 && \
go get -u github.com/vbatts/git-validation && \
go get -u github.com/openSUSE/portusctl && \
mv /root/go/bin/git-validation /usr/local/bin/ && \
mv /root/go/bin/portusctl /usr/local/bin/ && \
zypper -n rm wicked wicked-service autoconf automake \
binutils bison cpp cvs flex gdbm-devel gettext-tools \
libtool m4 make makeinfo && \
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ GEM
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
brakeman (4.1.1)
brakeman (4.2.0)
builder (3.2.3)
byebug (9.1.0)
capybara (2.14.4)
Expand Down
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,73 @@ For more information on development environments, check our
feel free to explore the `examples` directory for a variety of ways in which you
can deploy Portus.

### Testing

#### Unit tests

Unit tests are located in the `spec` directory. To run them, simply:

$ bundle exec rspec spec

Make sure to install [phantomjs](http://phantomjs.org/) from your Linux
distribution before running unit tests, since feature tests rely on PhantomJS
being installed. All the other ruby dependencies are already covered by our
`Gemfile`.

We also have tests in the frontend. For this, you have to install
[yarn](https://yarnpkg.com/) from your Linux distribution and run:

$ yarn test

#### Integration tests

Check [this
document](https://github.com/SUSE/Portus/blob/master/spec/integration/README.md)
in order to better understand how integration tests work. For development,
though, if you have already installed Docker, docker-composer and
[bats](https://github.com/sstephenson/bats), running the following should just
work:

```
$ chmod +x bin/test-integration.sh
$ ./bin/test-integration.sh
```

#### Other checks

A common pitfall for developers is to forget about code style. For that, make
sure to run [rubocop](https://github.com/bbatsov/rubocop):

$ bundle exec rubocop -a

Note that the command above includes the `-a` flag. This flag will automatically
fix small issues for you. We also run a code style check for the frontend code:

$ yarn eslint

We also run [brakeman](https://brakemanscanner.org/) in order to detect security
vulnerabilities:

$ bundle exec brakeman

Last but not least, make sure that your git commit follows a proper style. To
ensure this, you can run the following task:

$ bundle exec rake test:git

#### The CI

We use [Travis CI](https://travis-ci.org/) for continuous integration. You can
run what we run in Travis locally:

```
$ chmod +x bin/ci.sh
$ ./bin/ci.sh
```

This script simply executes all the tests and checks that we have presented
above.

## Supported versions

Docker technologies have a fast iteration pace. This is a good thing, but it
Expand Down
7 changes: 3 additions & 4 deletions app/models/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ class Registry < ActiveRecord::Base
# On create, make sure that all the needed namespaces are in place.
after_create :create_namespaces!

# Today the data model supports many registries
# however Portus just supports on Registry
# therefore to avoid confusion, define just one way
# to ask for the registy
# Today the data model supports many registries however Portus just supports
# on Registry therefore to avoid confusion, define just one way to ask for the
# registy
def self.get
Registry.first
end
Expand Down
83 changes: 83 additions & 0 deletions bin/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env bash

set -e

##
# Auxiliar functions

PORTUS_DB_ADAPTER=${PORTUS_DB_ADAPTER:-mysql2}

# Interacts with a daemon by taking two arguments:
# 1. The action (e.g. "start").
# 2. The service (e.g. "mysql").
# We do this to abstract the fact that Travis CI does not use systemd and we do.
function __daemon() {
if [[ -z "$CI" ]]; then
sudo systemctl $1 $2
else
sudo service $2 $1
fi
}

# Performs systemctl calls to the current database adapter when used outside of
# a container.
function __database() {
if [[ -f /.dockerenv ]]; then
return
fi

if [[ "$PORTUS_DB_ADAPTER" == "mysql2" ]]; then
__daemon $1 mysql
else
__daemon $1 postgresql
fi
}

# Setup an insecure registry for the local docker.
function __docker_insecure() {
if [[ ! -z "$CI" ]]; then
sudo tee /etc/docker/daemon.json > /dev/null <<EOF
{
"insecure-registries" : ["172.17.0.1:5000"]
}
EOF
fi
__daemon restart docker

# Show version info
docker --version
docker-compose --version
}

##
# The actual run

# Test commit messages
bundle exec rake test:git

# Style and security checks
bundle exec rubocop -V
bundle exec rubocop -F

# Compile assets
bundle exec rake portus:assets:compile

# Ruby tests
__database restart
bundle exec rspec spec
__database stop
if [[ ! -f /.dockerenv ]]; then
__docker_insecure
bundle exec rake test:integration
fi

# Note: it ignores a couple of files which use ruby 2.5 syntax which brakeman
# does not know how to handle...
bundle exec brakeman --skip-files lib/portus/background/sync.rb,lib/portus/registry_client.rb

# Make sure that there are no annotations needed.
bundle exec rake portus:annotate_and_exit

# JavaScript tests and style.
yarn test
yarn eslint
Loading

0 comments on commit f297fd7

Please sign in to comment.