From 73701e913cfd7d2d037ea887894a522d0ed1fbb3 Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Sun, 15 Oct 2017 22:47:13 +0200 Subject: [PATCH] feat: use kitchen for tests --- .gitignore | 2 + .kitchen.yml | 36 +++++++ .travis.yml | 6 +- Gemfile | 5 +- Gemfile.lock | 94 ++++++++++++------- README.md | 2 +- Rakefile | 26 ----- .../integration/bind/default.yml | 3 +- .../integration/bind/serverspec/bind_spec.rb | 5 + {tests => test/integration}/inventory | 0 tests/bind | 1 - 11 files changed, 114 insertions(+), 66 deletions(-) create mode 100644 .gitignore create mode 100644 .kitchen.yml delete mode 100644 Rakefile rename tests/bind.yml => test/integration/bind/default.yml (97%) rename tests/spec/bind.rb => test/integration/bind/serverspec/bind_spec.rb (93%) rename {tests => test/integration}/inventory (100%) delete mode 120000 tests/bind diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9ca390c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.kitchen/* + diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..b41d74a --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,36 @@ +driver: + name: docker_cli + +transport: + name: docker_cli + +provisioner: + name: ansible_playbook + hosts: localhost +# roles_path: . + require_ansible_repo: false + require_ansible_omnibus: true + require_chef_for_busser: true + ansible_verbose: false + ansible_version: latest + 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 + +#verifier: +# name: serverspec +# bundler_path: '/usr/local/bin' +# rspec_path: '/usr/local/bin' +# +suites: + - name: bind +# verifier: +# patterns: +# - tests/spec/*.rb diff --git a/.travis.yml b/.travis.yml index 627c14a..3ce051d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,12 @@ 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/ diff --git a/Gemfile b/Gemfile index dae3d8f..0d96441 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 35b5105..c7c18e5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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.13.6 + 1.14.6 diff --git a/README.md b/README.md index 6770fb3..b91a385 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ bind_zones: * install ruby * install bundler `gem install bundler` * install dependencies `bundle install` - * run the tests `rake` + * run the tests `kitchen test` ## License diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 071afcc..0000000 --- a/Rakefile +++ /dev/null @@ -1,26 +0,0 @@ -require 'English' - -ansible_role = 'bind' - -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 -] - -task :install do - exec_cmd("ansible-playbook -i tests/inventory tests/#{ansible_role}.yml") - exec_cmd("ansible-playbook -i tests/inventory tests/#{ansible_role}.yml | grep changed=0") - exec_cmd("cd tests/spec && rspec #{ansible_role}.rb") -end diff --git a/tests/bind.yml b/test/integration/bind/default.yml similarity index 97% rename from tests/bind.yml rename to test/integration/bind/default.yml index 2362db8..5de4cea 100644 --- a/tests/bind.yml +++ b/test/integration/bind/default.yml @@ -32,5 +32,4 @@ - { name: hello, type: a, value: 4.3.2.1 } roles: - - bind - + - ansible-role-bind diff --git a/tests/spec/bind.rb b/test/integration/bind/serverspec/bind_spec.rb similarity index 93% rename from tests/spec/bind.rb rename to test/integration/bind/serverspec/bind_spec.rb index ddc6b57..7f84dfb 100644 --- a/tests/spec/bind.rb +++ b/test/integration/bind/serverspec/bind_spec.rb @@ -41,6 +41,11 @@ describe file('/etc/bind/named.conf.options') do it { should contain 'listen-on-v6 { none; };' } end +describe service('bind9') do + it { should be_enabled } + it { should be_running.under('systemd') } +end + describe port(53) do it { should be_listening.with('tcp') } it { should be_listening.with('udp') } diff --git a/tests/inventory b/test/integration/inventory similarity index 100% rename from tests/inventory rename to test/integration/inventory diff --git a/tests/bind b/tests/bind deleted file mode 120000 index a96aa0e..0000000 --- a/tests/bind +++ /dev/null @@ -1 +0,0 @@ -.. \ No newline at end of file