From bf36088000e30802315817f0ef8a01778f5829d5 Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Tue, 13 Dec 2016 11:01:57 -0500 Subject: [PATCH 1/5] Added test-kitchen and rspec tests --- .gitignore | 19 ++++++ .kitchen.yml | 28 ++++++++ .rspec | 2 + Gemfile | 20 ++++++ chefignore | 1 + spec/spec_helper.rb | 10 +++ spec/unit/recipes/default_spec.rb | 45 +++++++++++++ test/Vagrantfile.erb | 66 +++++++++++++++++++ test/environments/integration_test_env.json | 16 +++++ .../debian/serverspec/debian_spec.rb | 23 +++++++ .../helpers/serverspec/spec_helper.rb | 4 ++ 11 files changed, 234 insertions(+) create mode 100644 .gitignore create mode 100644 .kitchen.yml create mode 100644 .rspec create mode 100644 Gemfile create mode 100644 chefignore create mode 100644 spec/spec_helper.rb create mode 100644 spec/unit/recipes/default_spec.rb create mode 100644 test/Vagrantfile.erb create mode 100644 test/environments/integration_test_env.json create mode 100644 test/integration/debian/serverspec/debian_spec.rb create mode 100644 test/integration/helpers/serverspec/spec_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ace0306 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +.DS_Store +.vagrant +Berksfile.lock +Gemfile.lock +*~ +*# +.#* +\#*# +.*.sw[a-z] +*.un~ + +# Bundler +bin/* +.bundle/* + +# Test-Kitchen +.kitchen/ +.kitchen.local.yml + diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..285e67a --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,28 @@ +--- +driver: + name: vagrant + +provisioner: + name: chef_zero + environments_path: test/environments + chef_client_path: /usr/bin/chef-client + client_rb: + environment: integration_test_env + +platforms: + - name: deb8 + driver: + box: lh-debian + box_url: http://repos.home.ld/vagrant/box/lh-debian.json + vm_hostname: integration.deb.test + vagrantfile_erb: test/Vagrantfile.erb + require_chef_omnibus: false + +suites: + - name: deb8 + run_list: + - recipe[apt-zabbix::default] + attributes: + includes: + - deb8 + diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..83e16f8 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..5e6bc98 --- /dev/null +++ b/Gemfile @@ -0,0 +1,20 @@ +source 'https://rubygems.org' + +gem 'berkshelf' + +# Uncomment these lines if you want to live on the Edge: +# +# group :development do +# gem "berkshelf", github: "berkshelf/berkshelf" +# gem "vagrant", github: "mitchellh/vagrant", tag: "v1.6.3" +# end +# +# group :plugins do +# gem "vagrant-berkshelf", github: "berkshelf/vagrant-berkshelf" +# gem "vagrant-omnibus", github: "schisamo/vagrant-omnibus" +# end + +gem "test-kitchen" +gem "kitchen-vagrant" +gem "hitimes" +gem "ffi" diff --git a/chefignore b/chefignore new file mode 100644 index 0000000..7be3c6d --- /dev/null +++ b/chefignore @@ -0,0 +1 @@ +.kitchen diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..c3a9d1a --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,10 @@ +require 'chefspec' +require 'chefspec/berkshelf' + +RSpec.configure do |config| + config.color = true + config.log_level = :error +end + +ChefSpec::Coverage.start! + diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb new file mode 100644 index 0000000..01fac6c --- /dev/null +++ b/spec/unit/recipes/default_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +describe 'apt-zabbix::default' do + #context 'Creates Zabbix APT repository' do + # let(:chef_run) do + # ChefSpec::SoloRunner.new do |node| + # # Create a new environment (you could also use a different :let block or :before block) + # env = Chef::Environment.new + # env.name 'unit_test' + # + # # Stub the node to return this environment + # allow(node).to receive(:chef_environment).and_return(env.name) + # + # # Stub any calls to Environment.load to return this environment + # allow(Chef::Environment).to receive(:load).and_return(env) + # + # # Stubbing out fqdn node attribute + # node.automatic['fqdn'] = 'unit.testing.stub' + # end.converge(described_recipe) + # end + virtual_box_version = '5.0' + + let(:runner) { ChefSpec::ServerRunner.new(platform: 'debian', version: '8.6') } + let(:chef_run) { runner.converge('apt-zabbix::default') } + #let(:chef_run) do + # ChefSpec::SoloRunner.new do |node| + # node.set['virtualbox']['version'] = virtual_box_version + # end.converge(described_recipe) + #end + + #before do + # allow(::File).to receive(:executable?).and_return(true) + #end + + it 'installs the apt repository' do + expect(chef_run).to add_apt_repository('zabbix').with( + :uri => 'http://repo.zabbix.com/zabbix/3.0/debian', + :key => 'zabbix-official-repo.key', + :distribution => 'jessie', + :components => ['main'] + ) + #expect(chef_run).to render_file('/etc/apt/sources.list.d/zabbix.list').with_content('deb "http://repo.zabbix.com/zabbix/3.0/debian" jessie main') + end +end + diff --git a/test/Vagrantfile.erb b/test/Vagrantfile.erb new file mode 100644 index 0000000..9095033 --- /dev/null +++ b/test/Vagrantfile.erb @@ -0,0 +1,66 @@ +Vagrant.configure("2") do |c| + c.vm.box = "<%= config[:box] %>" + c.vm.box_url = "<%= config[:box_url] %>" + + if Vagrant.has_plugin?("vagrant-cachier") + c.cache.auto_detect = true + c.cache.scope = :box + end + + #if Vagrant.has_plugin?("vagrant-omnibus") + # c.omnibus.cache_packages = true + # c.omnibus.chef_version = <%= config[:chef_version] %> + #end + + if Vagrant.has_plugin?("vagrant-libvirt") + c.vm.provider :libvirt do |libvirt| + libvirt.storage_pool_name = "Virt-SSD" + libvirt.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio' + end + end + + c.vbguest.auto_update = false + +<% if config[:vm_hostname] %> + c.vm.hostname = "<%= config[:vm_hostname] %>" +<% end %> +<% if config[:guest] %> + c.vm.guest = <%= config[:guest] %> +<% end %> +<% if config[:username] %> + c.ssh.username = "<%= config[:username] %>" +<% end %> +<% if config[:ssh_key] %> + c.ssh.private_key_path = "<%= config[:ssh_key] %>" +<% end %> + +<% Array(config[:network]).each do |opts| %> + c.vm.network(:<%= opts[0] %>, <%= opts[1..-1].join(", ") %>) +<% end %> + + c.vm.synced_folder ".", "/vagrant", disabled: true +<% config[:synced_folders].each do |source, destination, options| %> + c.vm.synced_folder "<%= source %>", "<%= destination %>", <%= options %> +<% end %> + + c.vm.provider :<%= config[:provider] %> do |p| +<% config[:customize].each do |key, value| %> + <% case config[:provider] + when "virtualbox" %> + p.customize ["modifyvm", :id, "--<%= key %>", "<%= value %>"] + <% when "rackspace", "softlayer" %> + p.<%= key %> = "<%= value%>" + <% when /^vmware_/ %> + <% if key == :memory %> + <% unless config[:customize].include?(:memsize) %> + p.vmx["memsize"] = "<%= value %>" + <% end %> + <% else %> + p.vmx["<%= key %>"] = "<%= value %>" + <% end %> + <% end %> +<% end %> + end + +end + diff --git a/test/environments/integration_test_env.json b/test/environments/integration_test_env.json new file mode 100644 index 0000000..445c15b --- /dev/null +++ b/test/environments/integration_test_env.json @@ -0,0 +1,16 @@ +{ + "name": "integration_test_env", + "description": "placeholder for integration testing", + "cookbook_versions": { + + }, + "json_class": "Chef::Environment", + "chef_type": "environment", + "default_attributes": { + + }, + "override_attributes": { + + } +} + diff --git a/test/integration/debian/serverspec/debian_spec.rb b/test/integration/debian/serverspec/debian_spec.rb new file mode 100644 index 0000000..958696a --- /dev/null +++ b/test/integration/debian/serverspec/debian_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe 'apt-zabbix::default' do + ### REPOSITORIES + # + describe 'Repositories should be installed:' do + describe file('/etc/apt/sources.list.d') do + it { should be_directory } + it { should be_mode 755 } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + end + + describe file('/etc/apt/sources.list.d/zabbix.list') do + it { should exist } + it { should be_mode 644 } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its(:content) { shoult match('deb ... jessie contrib non-free main') } + end + end +end + diff --git a/test/integration/helpers/serverspec/spec_helper.rb b/test/integration/helpers/serverspec/spec_helper.rb new file mode 100644 index 0000000..677ae95 --- /dev/null +++ b/test/integration/helpers/serverspec/spec_helper.rb @@ -0,0 +1,4 @@ +require 'serverspec' + +set :backend, :exec + From a57b86827e844515f5b5f99374d5e314208833b2 Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Tue, 13 Dec 2016 11:02:24 -0500 Subject: [PATCH 2/5] Removed Berksfile.lock from git --- Berksfile.lock | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 Berksfile.lock diff --git a/Berksfile.lock b/Berksfile.lock deleted file mode 100644 index 77654e0..0000000 --- a/Berksfile.lock +++ /dev/null @@ -1,14 +0,0 @@ -DEPENDENCIES - yum (~> 3.10.0) - yum-epel (~> 0.6.6) - yum-zabbix - path: . - metadata: true - -GRAPH - yum (3.10.0) - yum-epel (0.6.6) - yum (~> 3.10.0) - yum-zabbix (0.1.0) - yum (>= 3.2.0) - yum-epel (>= 0.0.0) From 533508c61e2cc3bd2c157d994c34201c1e5cdd6f Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Tue, 13 Dec 2016 11:12:59 -0500 Subject: [PATCH 3/5] Version bump --- metadata.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.rb b/metadata.rb index 082ac88..ced6906 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ maintainer_email 'psi-jack@linux-help.org' license 'Apache 2.0' description 'Installs and configures the NUX Community Desktop Yum Repository' long_description '' -version '0.1.0' +version '0.1.1' issues_url 'http://gogs.home.ld/Linux-Help/cookbook-apt-zabbix/issues' source_url 'http://gogs.home.ld/Linux-Help/cookbook-apt-zabbix' From df5b682fc685f06c850a092f235a1725638c2827 Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Sat, 24 Dec 2016 10:19:00 -0500 Subject: [PATCH 4/5] Updated kitchen suite to use new testing methods and integration test --- .kitchen.yml | 30 +++++++++---------- test/fixtures/environments/test.json | 17 +++++++++++ .../serverspec/debian_spec.rb | 2 +- 3 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 test/fixtures/environments/test.json rename test/integration/{debian => default}/serverspec/debian_spec.rb (85%) diff --git a/.kitchen.yml b/.kitchen.yml index 285e67a..51de9a0 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,28 +1,26 @@ --- driver: - name: vagrant + name: vagrant provisioner: - name: chef_zero - environments_path: test/environments - chef_client_path: /usr/bin/chef-client - client_rb: - environment: integration_test_env + name: chef_zero + nodes_path: test/fixtures/nodes + clients_path: test/fixtures/clients + environments_path: test/fixtures/environments + data_bags_path: test/fixtures/data_bags + chef_client_path: /usr/bin/chef-client + client_rb: + environment: test platforms: - - name: deb8 - driver: - box: lh-debian - box_url: http://repos.home.ld/vagrant/box/lh-debian.json - vm_hostname: integration.deb.test - vagrantfile_erb: test/Vagrantfile.erb - require_chef_omnibus: false + - name: debian-8.6 + driver_config: + vm_hostname: integration.deb.test + require_chef_omnibus: false suites: - - name: deb8 + - name: default run_list: - recipe[apt-zabbix::default] attributes: - includes: - - deb8 diff --git a/test/fixtures/environments/test.json b/test/fixtures/environments/test.json new file mode 100644 index 0000000..e065983 --- /dev/null +++ b/test/fixtures/environments/test.json @@ -0,0 +1,17 @@ +{ + "id": "test", + "name": "test", + "description": "placeholder for integration testing", + "cookbook_versions": { + + }, + "json_class": "Chef::Environment", + "chef_type": "environment", + "default_attributes": { + + }, + "override_attributes": { + + } +} + diff --git a/test/integration/debian/serverspec/debian_spec.rb b/test/integration/default/serverspec/debian_spec.rb similarity index 85% rename from test/integration/debian/serverspec/debian_spec.rb rename to test/integration/default/serverspec/debian_spec.rb index 958696a..242c390 100644 --- a/test/integration/debian/serverspec/debian_spec.rb +++ b/test/integration/default/serverspec/debian_spec.rb @@ -16,7 +16,7 @@ describe 'apt-zabbix::default' do it { should be_mode 644 } it { should be_owned_by 'root' } it { should be_grouped_into 'root' } - its(:content) { shoult match('deb ... jessie contrib non-free main') } + its(:content) { should match('deb "http://repo.zabbix.com/zabbix/3.0/debian" jessie main') } end end end From c28e4bd7396448ece798c58cf825fe476753e0fc Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Sat, 24 Dec 2016 15:31:32 -0500 Subject: [PATCH 5/5] Release v0.1.2 --- metadata.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.rb b/metadata.rb index ced6906..b5fce51 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ maintainer_email 'psi-jack@linux-help.org' license 'Apache 2.0' description 'Installs and configures the NUX Community Desktop Yum Repository' long_description '' -version '0.1.1' +version '0.1.2' issues_url 'http://gogs.home.ld/Linux-Help/cookbook-apt-zabbix/issues' source_url 'http://gogs.home.ld/Linux-Help/cookbook-apt-zabbix'