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..51de9a0 --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,26 @@ +--- +driver: + name: vagrant + +provisioner: + 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: debian-8.6 + driver_config: + vm_hostname: integration.deb.test + require_chef_omnibus: false + +suites: + - name: default + run_list: + - recipe[apt-zabbix::default] + attributes: + 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/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) 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/metadata.rb b/metadata.rb index 082ac88..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.0' +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' 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/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/default/serverspec/debian_spec.rb b/test/integration/default/serverspec/debian_spec.rb new file mode 100644 index 0000000..242c390 --- /dev/null +++ b/test/integration/default/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) { should match('deb "http://repo.zabbix.com/zabbix/3.0/debian" jessie 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 +