feat: use kitchen for run the tests

This commit is contained in:
Adrien Waksberg 2017-11-05 17:02:11 +01:00
parent 28977c152c
commit 4b8ad566b8
16 changed files with 160 additions and 96 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.kitchen/*

27
.kitchen.yml Normal file
View file

@ -0,0 +1,27 @@
driver:
name: docker_cli
transport:
name: docker_cli
provisioner:
name: ansible_playbook
hosts: localhost
require_ansible_repo: false
require_ansible_omnibus: true
require_chef_for_busser: true
ansible_verbose: false
ansible_version: <% if ENV['ANSIBLE_VERSION'] %><%= ENV['ANSIBLE_VERSION'] %><% else %><%= '2.2.3.0' %><% end %>
ansible_inventory: ./test/integration/inventory
platforms:
- name: debian-9
driver_config:
image: nishiki/ansible:stretch
command: /bin/systemd
volume:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
security_opt: seccomp=unconfined
suites:
- name: gitolite

View file

@ -1,14 +1,20 @@
sudo: required
language: ruby
env:
- ANSIBLE_VERSION=2.2.3.0
- ANSIBLE_VERSION=2.3.2.0
- ANSIBLE_VERSION=2.4.0.0
services:
- docker
before_install:
- docker pull nishiki/ansible:stretch
- bundle install
script:
- rake
- kitchen conv
- kitchen conv | grep changed=0
- kitchen verify
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View file

@ -1,7 +1,8 @@
source 'https://rubygems.org'
group :development do
gem 'rake'
gem 'kitchen-ansible'
gem 'kitchen-docker_cli'
gem 'rubocop', '0.50.0'
gem 'serverspec'
gem 'test-kitchen'
end

View file

@ -2,12 +2,36 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.3.0)
diff-lcs (1.3)
builder (3.2.3)
erubis (2.7.0)
ffi (1.9.18)
gssapi (1.2.0)
ffi (>= 1.0.1)
gyoku (1.3.1)
builder (>= 2.1.2)
httpclient (2.8.3)
kitchen-ansible (0.47.5)
net-ssh (>= 3)
test-kitchen (~> 1.4)
kitchen-docker_cli (0.18.0)
test-kitchen (>= 1.3)
little-plugger (1.1.4)
logging (2.2.2)
little-plugger (~> 1.1)
multi_json (~> 1.10)
mixlib-install (3.6.0)
mixlib-shellout
mixlib-versioning
thor
mixlib-shellout (2.3.2)
mixlib-versioning (1.2.2)
multi_json (1.12.2)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (4.2.0)
net-telnet (0.1.1)
net-ssh-gateway (1.3.0)
net-ssh (>= 2.6.5)
nori (2.6.0)
parallel (1.12.0)
parser (2.4.0.0)
ast (~> 2.2)
@ -15,22 +39,6 @@ GEM
rainbow (2.2.2)
rake
rake (12.1.0)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-its (1.2.0)
rspec-core (>= 3.0.0)
rspec-expectations (>= 3.0.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
rubocop (0.50.0)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
@ -39,26 +47,48 @@ GEM
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
serverspec (2.41.0)
multi_json
rspec (~> 3.0)
rspec-its
specinfra (~> 2.72)
sfl (2.3)
specinfra (2.72.0)
net-scp
net-ssh (>= 2.7, < 5.0)
net-telnet
sfl
rubyntlm (0.6.2)
rubyzip (1.2.1)
safe_yaml (1.0.4)
test-kitchen (1.18.0)
mixlib-install (~> 3.6)
mixlib-shellout (>= 1.2, < 3.0)
net-scp (~> 1.1)
net-ssh (>= 2.9, < 5.0)
net-ssh-gateway (~> 1.2)
safe_yaml (~> 1.0)
thor (~> 0.19, < 0.19.2)
winrm (~> 2.0)
winrm-elevated (~> 1.0)
winrm-fs (~> 1.0.2)
thor (0.19.1)
unicode-display_width (1.3.0)
winrm (2.2.3)
builder (>= 2.1.2)
erubis (~> 2.7)
gssapi (~> 1.2)
gyoku (~> 1.0)
httpclient (~> 2.2, >= 2.2.0.2)
logging (>= 1.6.1, < 3.0)
nori (~> 2.0)
rubyntlm (~> 0.6.0, >= 0.6.1)
winrm-elevated (1.1.0)
winrm (~> 2.0)
winrm-fs (~> 1.0)
winrm-fs (1.0.2)
erubis (~> 2.7)
logging (>= 1.6.1, < 3.0)
rubyzip (~> 1.1)
winrm (~> 2.0)
PLATFORMS
ruby
DEPENDENCIES
rake
kitchen-ansible
kitchen-docker_cli
rubocop (= 0.50.0)
serverspec
test-kitchen
BUNDLED WITH
1.14.6

View file

@ -43,5 +43,25 @@ None
### Tests with docker
* install [docker](https://docs.docker.com/engine/installation/)
* install ruby
* install bundler `gem install bundler`
* install dependencies `bundle install`
* run the tests `rake`
* run the tests `kitchen test`
## License
```
Copyright (c) 2017 Adrien Waksberg
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

View file

@ -1,32 +0,0 @@
require 'English'
ansible_role = 'gitolite'
def exec_cmd(cmd)
puts cmd
puts %x(#{cmd})
raise unless $CHILD_STATUS.success?
end
task :default do
exec_cmd(
"docker run -v $(pwd):/#{ansible_role}:ro -it nishiki/ansible:stretch bash -c " \
"'cd /#{ansible_role} && rake verify'"
)
end
task verify: %w[
install
purge
]
task :install do
exec_cmd('ansible-playbook -i tests/inventory tests/gitolite.yml')
exec_cmd('ansible-playbook -i tests/inventory tests/gitolite.yml | grep changed=0')
exec_cmd('cd spec && rspec gitolite.rb')
end
task :purge do
exec_cmd('ansible-playbook -i tests/inventory tests/purge.yml')
exec_cmd('cd spec && rspec purge.rb')
end

View file

@ -1,18 +0,0 @@
require 'serverspec'
set :backend, :exec
describe user('git') do
it { should_not exist }
end
%w[
/usr/src/gitolite
/usr/local/gitolite
/usr/local/bin/gitolite
/home/git
].each do |file|
describe file(file) do
it { should_not exist }
end
end

View file

@ -0,0 +1,32 @@
I, [2017-11-05T16:10:06.186237 #28372] INFO -- Kitchen: -----> Starting Kitchen (v1.18.0)
E, [2017-11-05T16:10:06.186610 #28372] ERROR -- Kitchen: ------Exception-------
E, [2017-11-05T16:10:06.186666 #28372] ERROR -- Kitchen: Class: Kitchen::UserError
E, [2017-11-05T16:10:06.186701 #28372] ERROR -- Kitchen: Message: Kitchen YAML file /home/nishiki/git/ansible-role-gitolite/test/integration/.kitchen.yml does not exist.
E, [2017-11-05T16:10:06.186730 #28372] ERROR -- Kitchen: ----------------------
E, [2017-11-05T16:10:06.186759 #28372] ERROR -- Kitchen: ------Backtrace-------
E, [2017-11-05T16:10:06.186784 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/loader/yaml.rb:65:in `read'
E, [2017-11-05T16:10:06.186811 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/config.rb:147:in `data'
E, [2017-11-05T16:10:06.186837 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/config.rb:126:in `suites'
E, [2017-11-05T16:10:06.186861 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/config.rb:177:in `filter_instances'
E, [2017-11-05T16:10:06.186906 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/config.rb:136:in `build_instances'
E, [2017-11-05T16:10:06.186935 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/config.rb:112:in `instances'
E, [2017-11-05T16:10:06.186962 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/command.rb:112:in `filtered_instances'
E, [2017-11-05T16:10:06.186989 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/command.rb:142:in `parse_subcommand'
E, [2017-11-05T16:10:06.187016 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/command/action.rb:35:in `block in call'
E, [2017-11-05T16:10:06.187043 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/benchmark.rb:293:in `measure'
E, [2017-11-05T16:10:06.187094 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/command/action.rb:34:in `call'
E, [2017-11-05T16:10:06.187125 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/cli.rb:53:in `perform'
E, [2017-11-05T16:10:06.187151 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/cli.rb:187:in `block (2 levels) in <class:CLI>'
E, [2017-11-05T16:10:06.187178 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
E, [2017-11-05T16:10:06.187205 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
E, [2017-11-05T16:10:06.187231 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/cli.rb:334:in `invoke_task'
E, [2017-11-05T16:10:06.187264 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
E, [2017-11-05T16:10:06.187291 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
E, [2017-11-05T16:10:06.187316 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/bin/kitchen:13:in `block in <top (required)>'
E, [2017-11-05T16:10:06.187338 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/lib/kitchen/errors.rb:171:in `with_friendly_errors'
E, [2017-11-05T16:10:06.187360 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/gems/test-kitchen-1.18.0/bin/kitchen:13:in `<top (required)>'
E, [2017-11-05T16:10:06.187384 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/bin/kitchen:22:in `load'
E, [2017-11-05T16:10:06.187408 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/bin/kitchen:22:in `<main>'
E, [2017-11-05T16:10:06.187442 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
E, [2017-11-05T16:10:06.187471 #28372] ERROR -- Kitchen: /home/nishiki/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'
E, [2017-11-05T16:10:06.187496 #28372] ERROR -- Kitchen: ----End Backtrace-----

View file

@ -0,0 +1,4 @@
- hosts: gitolite
connection: local
roles:
- ansible-role-gitolite

View file

@ -0,0 +1,2 @@
[gitolite]
localhost

View file

@ -1 +0,0 @@
..

View file

@ -1,4 +0,0 @@
- hosts: localhost
connection: local
roles:
- gitolite

View file

@ -1 +0,0 @@
localhost

View file

@ -1,4 +0,0 @@
- hosts: localhost
connection: local
roles:
- gitolite/purge