diff --git a/.gitignore b/.gitignore index 2f19f7d..fc0a67c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ Gemfile.lock /.rspec_system /.ruby-version /.bundle +/.kitchen diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..736020f --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,21 @@ +--- +driver: + name: docker + use_sudo: false + +provisioner: + name: puppet_apply + require_chef_for_busser: false + require_puppet_collections: true + modules_path: . + +verifier: + name: inspec + +platforms: + - name: centos-6.9 + +suites: + - name: default + provisioner: + manifests_path: test/integration/default diff --git a/.travis.yml b/.travis.yml index a488b42..8fce807 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,21 @@ +--- +sudo: false language: ruby -bundler_args: --without development +before_install: + - gem update bundler script: "bundle exec rake spec SPEC_OPTS='--format documentation'" -rvm: - - 1.8.7 - - 1.9.3 -env: - - PUPPET_GEM_VERSION="~> 3.0.0" - - PUPPET_GEM_VERSION="~> 3.1.0" - - PUPPET_GEM_VERSION="~> 3.2.0" - - PUPPET_GEM_VERSION="~> 3.3.0" - - PUPPET_GEM_VERSION="~> 3.4.0" - - PUPPET_GEM_VERSION="~> 3.5.0" - - PUPPET_GEM_VERSION="~> 3.6.0" - - PUPPET_GEM_VERSION="~> 3.7.0" +matrix: + fast_finish: true + include: + - rvm: 2.3.1 + script: bundle exec kitchen test + services: docker + sudo: required + - rvm: 1.9.3 + bundler_args: --without integration + env: PUPPET_GEM_VERSION="~> 3.0" + - rvm: 2.3.1 + bundler_args: --without integration + env: PUPPET_GEM_VERSION="~> 4.0" notifications: email: false diff --git a/Gemfile b/Gemfile index a9cc7ca..c66b261 100644 --- a/Gemfile +++ b/Gemfile @@ -12,12 +12,11 @@ group :development, :test do gem 'puppet-lint' end -group :development do - gem 'pry' - gem 'pry-debugger' - gem 'rb-readline' - gem 'awesome_print' - gem 'rspec-system-puppet', '~>2.0' +group :integration do + gem 'test-kitchen' + gem 'kitchen-docker' + gem 'kitchen-inspec' + gem 'kitchen-puppet' end # json/json_pure are transitive dependences of puppet. diff --git a/Rakefile b/Rakefile index 79d29df..a26649b 100644 --- a/Rakefile +++ b/Rakefile @@ -6,6 +6,11 @@ Bundler.require :default require 'rspec/core/rake_task' require 'puppetlabs_spec_helper/rake_tasks' +begin + require 'kitchen/rake_tasks' +rescue LoadError +end + task :default do sh %{rake -T} end diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb deleted file mode 100644 index cba2ad7..0000000 --- a/spec/spec_helper_system.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'rspec-system/spec_helper' -require 'rspec-system-puppet/helpers' - -include RSpecSystemPuppet::Helpers - -RSpec.configure do |c| - proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) - - # Enable colour in Jenkins - c.tty = true - - c.include RSpecSystemPuppet::Helpers - - c.before :suite do - puppet_install - puppet_master_install - - puppet_module_install(:source => proj_root, :module_name => 'datacat') - puppet_module_install(:source => proj_root + '/spec/fixtures/modules/demo1', :module_name => 'demo1') - puppet_module_install(:source => proj_root + '/spec/fixtures/modules/demo2', :module_name => 'demo2') - puppet_module_install(:source => proj_root + '/spec/fixtures/modules/demo3', :module_name => 'demo3') - end -end diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb deleted file mode 100644 index 627547a..0000000 --- a/spec/system/basic_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -require 'spec_helper_system' - -describe 'basic tests:' do - # Using puppet_apply as a subject - context puppet_apply 'notice("foo")' do - its(:stdout) { should =~ /foo/ } - its(:stderr) { should be_empty } - its(:exit_code) { should be_zero } - end - - # Using puppet_apply as a helper - it 'my class should work with no errors' do - pp = <<-EOS - datacat { "/tmp/demo1": - template_body => "<% @data.keys.sort.each do |k| %><%= k %>: <%= @data[k] %>, <% end %>", - } - - datacat_fragment { "foo": - target => '/tmp/demo1', - data => { foo => "one" }, - } - - datacat_fragment { "bar": - target => '/tmp/demo1', - data => { bar => "two" }, - } - - exec { '/bin/echo I have changed': - refreshonly => true, - subscribe => Datacat["/tmp/demo1"], - } - EOS - - # Run it twice and test for idempotency - puppet_apply(pp) do |r| - r.exit_code.should_not == 1 - r.refresh - r.exit_code.should be_zero - end - - shell('cat /tmp/demo1') do |r| - r.stdout.should =~ /^bar: two, foo: one/ - end - end - - it 'should run the example from the documentation via a master' do - shell 'sudo sh -c "echo include demo3 > /etc/puppet/manifests/site.pp"' - puppet_agent(:debug => true) do |r| - r.exit_code.should_not == 1 - r.refresh - r.exit_code.should be_zero - end - - shell('cat /tmp/demo3') do |r| - r.stdout.should =~ /\s+name device\n\s+members foo-ilo.example.com,foo.example.com/ - end - end -end diff --git a/test/integration/default/site.pp b/test/integration/default/site.pp new file mode 100644 index 0000000..51b94c0 --- /dev/null +++ b/test/integration/default/site.pp @@ -0,0 +1,13 @@ +datacat { "/tmp/demo1": + template_body => "<% @data.keys.sort.each do |k| %><%= k %>: <%= @data[k] %>, <% end %>", +} + +datacat_fragment { "foo": + target => '/tmp/demo1', + data => { foo => "one" }, +} + +datacat_fragment { "bar": + target => '/tmp/demo1', + data => { bar => "two" }, +} diff --git a/test/integration/default/test.rb b/test/integration/default/test.rb new file mode 100644 index 0000000..c218147 --- /dev/null +++ b/test/integration/default/test.rb @@ -0,0 +1,4 @@ +describe file('/tmp/demo1') do + it { should be_file } + its('content') { should match(%r{bar: two, foo: one}) } +end