diff --git a/.kitchen.yml b/.kitchen.yml deleted file mode 100644 index 4b89c12..0000000 --- a/.kitchen.yml +++ /dev/null @@ -1,38 +0,0 @@ ---- -driver: - name: vagrant - -platforms: - - name: debian-jessie64 - driver_config: - box: ssplatt/salt-deb-8 - -provisioner: - name: salt_solo - salt_version: 2015.8.8 - data_path: test/shared - is_file_root: true - pillars-from-files: - apt.sls: pillar.example - pillars: - top.sls: - base: - '*': - - apt - grains: - os_family: Debian - -suites: - - name: repositories - provisioner: - state_top: - base: - '*': - - apt.repositories - - apt.update - - name: preferences - provisioner: - state_top: - base: - '*': - - apt.preferences diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1895415 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,68 @@ +stages: + - test + - commitlint + - name: release + if: branch = master AND type != pull_request + +sudo: required +cache: bundler +language: ruby + +services: + - docker + +# Make sure the instances listed below match up with +# the `platforms` defined in `kitchen.yml` +# NOTE: Please try to select up to six instances that add some meaningful +# testing of the formula's behaviour. If possible, try to refrain from +# the classical "chosing all the instances because I want to test on +# another/all distro/s" trap: it will just add time to the testing (see +# the discussion on #121). As an example, the set chosen below covers +# the most used distros families, systemd and non-systemd and the latest +# three supported Saltstack versions with python2 and 3." +# As for `kitchen.yml`, that should still contain all of the platforms, +# to allow for comprehensive local testing +# Ref: https://github.com/saltstack-formulas/template-formula/issues/118 +# Ref: https://github.com/saltstack-formulas/template-formula/issues/121 +env: + matrix: + - INSTANCE: repositories-debian-9-2019-2-py3 + - INSTANCE: repositories-ubuntu-1804-2019-2-py3 + - INSTANCE: preferences-debian-9-2019-2-py3 + - INSTANCE: preferences-ubuntu-1804-2019-2-py3 + +script: + - bundle exec kitchen verify ${INSTANCE} + +jobs: + include: + # Define the commitlint stage + - stage: commitlint + language: node_js + node_js: lts/* + before_install: skip + script: + - npm install @commitlint/config-conventional -D + - npm install @commitlint/travis-cli -D + - commitlint-travis + # Define the release stage that runs semantic-release + - stage: release + language: node_js + node_js: lts/* + before_install: skip + script: + # Update `AUTHORS.md` + - export MAINTAINER_TOKEN=${GH_TOKEN} + - go get github.com/myii/maintainer + - maintainer contributor + + # Install all dependencies required for `semantic-release` + - npm install @semantic-release/changelog@3 -D + - npm install @semantic-release/exec@3 -D + - npm install @semantic-release/git@7 -D + deploy: + provider: script + skip_cleanup: true + script: + # Run `semantic-release` + - npx semantic-release@15 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..3b36de3 --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +gem 'kitchen-docker', '>= 2.9' +gem 'kitchen-salt', '>= 0.6.0' +gem 'kitchen-inspec', '>= 1.1' + diff --git a/kitchen.yml b/kitchen.yml new file mode 100644 index 0000000..697b5f6 --- /dev/null +++ b/kitchen.yml @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +# For help on this file's format, see https://kitchen.ci/ +driver: + name: docker + use_sudo: false + privileged: true + run_command: /lib/systemd/systemd + +# Make sure the platforms listed below match up with +# the `env.matrix` instances defined in `.travis.yml` +platforms: + - name: debian-9-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:debian-9 + - name: ubuntu-1804-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:ubuntu-18.04 + +provisioner: + name: salt_solo + log_level: info + salt_install: none + require_chef: false + formula: apt + salt_copy_filter: + - .kitchen + - .git + pillars: + top.sls: + base: + '*': + - apt + +verifier: + # https://www.inspec.io/ + name: inspec + sudo: true + # cli, documentation, html, progress, json, json-min, json-rspec, junit + reporter: + - cli + +suites: + - name: repositories + provisioner: + state_top: + base: + '*': + - apt.repositories + - apt.update + pillars_from_files: + apt.sls: test/salt/pillar/repositories.pillar.sls + verifier: + inspec_tests: + - path: test/integration/repositories + - name: preferences + provisioner: + state_top: + base: + '*': + - apt.preferences + pillars_from_files: + apt.sls: test/salt/pillar/preferences.pillar.sls + verifier: + inspec_tests: + - path: test/integration/preferences diff --git a/test/integration/preferences/serverspec/preferences_spec.rb b/test/integration/preferences/controls/preferences_spec.rb similarity index 80% rename from test/integration/preferences/serverspec/preferences_spec.rb rename to test/integration/preferences/controls/preferences_spec.rb index 2c8667b..148cd1f 100644 --- a/test/integration/preferences/serverspec/preferences_spec.rb +++ b/test/integration/preferences/controls/preferences_spec.rb @@ -1,48 +1,47 @@ -require_relative '../../../kitchen/data/spec_helper' - -describe 'apt.preferences' do +control 'Apt preferences' do + title 'should be configured' describe file('/etc/apt/preferences') do - it { should_not exist } + it { should exist } + its(:size) { should eq 0 } end describe file('/etc/apt/preferences.d') do it { should be_directory } - it { should be_mode 755 } it { should be_owned_by 'root' } it { should be_grouped_into 'root' } + its('mode') { should cmp '0755' } end describe file('/etc/apt/preferences.d/00-rspamd') do it { should exist } - it { should be_mode 644 } it { should be_owned_by 'root' } it { should be_grouped_into 'root' } + its('mode') { should cmp '0644' } its(:content) { should match("Package: rspamd\nPin: origin rspamd.com\nPin-Priority: 650\n") } end describe file('/etc/apt/preferences.d/01-all') do it { should exist } - it { should be_mode 644 } it { should be_owned_by 'root' } it { should be_grouped_into 'root' } + its('mode') { should cmp '0644' } its(:content) { should match("Package: *\nPin: release stable\nPin-Priority: 610\n") } end describe file('/etc/apt/preferences.d/02-all') do it { should exist } - it { should be_mode 644 } it { should be_owned_by 'root' } it { should be_grouped_into 'root' } + its('mode') { should cmp '0644' } its(:content) { should match("Package: *\nPin: release testing\nPin-Priority: 600\n") } end describe file('/etc/apt/preferences.d/03-all') do it { should exist } - it { should be_mode 644 } it { should be_owned_by 'root' } it { should be_grouped_into 'root' } + its('mode') { should cmp '0644' } its(:content) { should match("Package: *\nPin: release unstable\nPin-Priority: 50\n") } end - end diff --git a/test/integration/preferences/inspec.yml b/test/integration/preferences/inspec.yml new file mode 100644 index 0000000..a32e354 --- /dev/null +++ b/test/integration/preferences/inspec.yml @@ -0,0 +1,8 @@ +name: preferences +title: Apt Formula +maintainer: Saltstack-formulas org +license: Apache-2.0 +summary: Verify that the apt preferences are configured correctly +supports: + - os-name: debian + - os-name: ubuntu diff --git a/test/integration/repositories/controls/repositories_spec.rb b/test/integration/repositories/controls/repositories_spec.rb new file mode 100644 index 0000000..3031d22 --- /dev/null +++ b/test/integration/repositories/controls/repositories_spec.rb @@ -0,0 +1,41 @@ +control 'Apt repositories' do + title 'should be configured' + + if os[:name] == 'ubuntu' + keyring_package = 'ubuntu-keyring' + else + keyring_package = 'debian-archive-keyring' + end + + describe package(keyring_package) do + it { should be_installed } + end + + describe file('/etc/apt/sources.list') do + it { should exist } + its(:size) { should eq 0 } + end + + describe file('/etc/apt/sources.list.d') do + it { should be_directory } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('mode') { should cmp '0755' } + end + + describe file('/etc/apt/sources.list.d/spotify-binary.list') do + it { should exist } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('mode') { should cmp '0644' } + its(:content) { should match(%r{deb \[arch=amd64\] http://repository.spotify.com stable non-free}) } + end + + describe file('/etc/apt/sources.list.d/heroku-binary.list') do + it { should exist } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('mode') { should cmp '0644' } + its(:content) { should match(%r{deb \[arch=amd64\] https://cli-assets.heroku.com/apt ./}) } + end +end diff --git a/test/integration/repositories/inspec.yml b/test/integration/repositories/inspec.yml new file mode 100644 index 0000000..7fa5acb --- /dev/null +++ b/test/integration/repositories/inspec.yml @@ -0,0 +1,8 @@ +name: repositories +title: Apt Formula +maintainer: Saltstack-formulas org +license: Apache-2.0 +summary: Verify that the apt repositories are configured correctly +supports: + - os-name: debian + - os-name: ubuntu diff --git a/test/integration/repositories/serverspec/repositories_spec.rb b/test/integration/repositories/serverspec/repositories_spec.rb deleted file mode 100644 index 5a19b55..0000000 --- a/test/integration/repositories/serverspec/repositories_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../kitchen/data/spec_helper' - -describe 'apt.repositories' do - - describe package('debian-archive-keyring') do - it { should be_installed } - end - - describe file('/etc/apt/sources.list') do - it { should exist } - its(:size) { should eq 0 } - end - - 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/debian-jessie-source.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-src http://httpredir.debian.org/debian jessie contrib non-free main') } - end - - describe file('/etc/apt/sources.list.d/dropbox-binary.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(%r{deb \[arch=i386,amd64\] http://linux.dropbox.com/debian jessie main}) } - end -end diff --git a/test/salt/pillar/preferences.pillar.sls b/test/salt/pillar/preferences.pillar.sls new file mode 100644 index 0000000..f207765 --- /dev/null +++ b/test/salt/pillar/preferences.pillar.sls @@ -0,0 +1,18 @@ +apt: + remove_preferences: true + clean_preferences_d: true + + preferences: + 00-rspamd: + package: rspamd + pin: origin rspamd.com + priority: 650 + 01-all: + pin: release stable + priority: 610 + 02-all: + pin: release testing + priority: 600 + 03-all: + pin: release unstable + priority: 50 diff --git a/test/salt/pillar/repositories.pillar.sls b/test/salt/pillar/repositories.pillar.sls new file mode 100644 index 0000000..142b878 --- /dev/null +++ b/test/salt/pillar/repositories.pillar.sls @@ -0,0 +1,19 @@ +apt: + remove_sources_list: true + clean_sources_list_d: true + + repositories: + spotify: + distro: stable + url: http://repository.spotify.com + arch: [amd64] + comps: [non-free] + keyid: 931FF8E79F0876134EDDBDCCA87FF9DF48BF1C90 + keyserver: keyserver.ubuntu.com + heroku: + distro: ./ + url: https://cli-assets.heroku.com/apt + arch: [amd64] + comps: [] + key_url: https://cli-assets.heroku.com/apt/release.key + diff --git a/test/shared/spec_helper.rb b/test/shared/spec_helper.rb deleted file mode 100644 index d62fc6d..0000000 --- a/test/shared/spec_helper.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "serverspec" -require "pathname" - -# Set backend type -set :backend, :exec - -RSpec.configure do |c| - c.path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" -end