diff --git a/.travis.yml b/.travis.yml index 6007a29..578fca6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,36 +59,67 @@ jobs: # Make sure the instances listed below match up with # the `platforms` defined in `kitchen.yml` - env: INSTANCE=default-debian-10-master-py3 + # - env: INSTANCE=package-debian-10-master-py3 # - env: INSTANCE=default-ubuntu-2004-master-py3 + - env: INSTANCE=package-ubuntu-2004-master-py3 # - env: INSTANCE=default-ubuntu-1804-master-py3 + # - env: INSTANCE=package-ubuntu-1804-master-py3 - env: INSTANCE=default-centos-8-master-py3 - - env: INSTANCE=default-fedora-32-master-py3 + # - env: INSTANCE=package-centos-8-master-py3 + # - env: INSTANCE=default-fedora-32-master-py3 + - env: INSTANCE=package-fedora-32-master-py3 # - env: INSTANCE=default-fedora-31-master-py3 - - env: INSTANCE=default-opensuse-leap-152-master-py3 + # - env: INSTANCE=package-fedora-31-master-py3 + # - env: INSTANCE=default-opensuse-leap-152-master-py3 + # - env: INSTANCE=package-opensuse-leap-152-master-py3 # - env: INSTANCE=default-amazonlinux-2-master-py3 + # - env: INSTANCE=package-amazonlinux-2-master-py3 # - env: INSTANCE=default-debian-10-3000-3-py3 + # - env: INSTANCE=package-debian-10-3000-3-py3 # - env: INSTANCE=default-debian-9-3000-3-py3 + # - env: INSTANCE=package-debian-9-3000-3-py3 # - env: INSTANCE=default-ubuntu-1804-3000-3-py3 + # - env: INSTANCE=package-ubuntu-1804-3000-3-py3 # - env: INSTANCE=default-centos-8-3000-3-py3 + # - env: INSTANCE=package-centos-8-3000-3-py3 # - env: INSTANCE=default-centos-7-3000-3-py3 + # - env: INSTANCE=package-centos-7-3000-3-py3 # - env: INSTANCE=default-fedora-31-3000-3-py3 - # - env: INSTANCE=default-opensuse-leap-152-3000-3-py3 - # - env: INSTANCE=default-amazonlinux-2-3000-3-py3 + # - env: INSTANCE=package-fedora-31-3000-3-py3 + - env: INSTANCE=default-opensuse-leap-152-3000-3-py3 + # - env: INSTANCE=package-opensuse-leap-152-3000-3-py3 + - env: INSTANCE=default-amazonlinux-2-3000-3-py3 + # - env: INSTANCE=package-amazonlinux-2-3000-3-py3 # - env: INSTANCE=default-ubuntu-1804-3000-3-py2 + # - env: INSTANCE=package-ubuntu-1804-3000-3-py2 # - env: INSTANCE=default-ubuntu-1604-3000-3-py2 + # - env: INSTANCE=package-ubuntu-1604-3000-3-py2 # - env: INSTANCE=default-arch-base-latest-3000-3-py2 + # - env: INSTANCE=package-arch-base-latest-3000-3-py2 # - env: INSTANCE=default-debian-10-2019-2-py3 + # - env: INSTANCE=package-debian-10-2019-2-py3 # - env: INSTANCE=default-debian-9-2019-2-py3 + # - env: INSTANCE=package-debian-9-2019-2-py3 # - env: INSTANCE=default-ubuntu-1804-2019-2-py3 + # - env: INSTANCE=package-ubuntu-1804-2019-2-py3 # - env: INSTANCE=default-ubuntu-1604-2019-2-py3 + # - env: INSTANCE=package-ubuntu-1604-2019-2-py3 # - env: INSTANCE=default-centos-8-2019-2-py3 + # - env: INSTANCE=package-centos-8-2019-2-py3 # - env: INSTANCE=default-centos-7-2019-2-py3 + # - env: INSTANCE=package-centos-7-2019-2-py3 # - env: INSTANCE=default-fedora-31-2019-2-py3 + # - env: INSTANCE=package-fedora-31-2019-2-py3 # - env: INSTANCE=default-opensuse-leap-152-2019-2-py3 + # - env: INSTANCE=package-opensuse-leap-152-2019-2-py3 # - env: INSTANCE=default-amazonlinux-2-2019-2-py3 + # - env: INSTANCE=package-amazonlinux-2-2019-2-py3 # - env: INSTANCE=default-centos-6-2019-2-py2 + # - env: INSTANCE=package-centos-6-2019-2-py2 # - env: INSTANCE=default-amazonlinux-1-2019-2-py2 + # - env: INSTANCE=package-amazonlinux-1-2019-2-py2 # - env: INSTANCE=default-arch-base-latest-2019-2-py2 + - env: INSTANCE=package-arch-base-latest-2019-2-py2 ## Define the release stage that runs `semantic-release` - stage: 'release' diff --git a/golang/defaults.yaml b/golang/defaults.yaml index 59c4d4b..f2f6f9a 100644 --- a/golang/defaults.yaml +++ b/golang/defaults.yaml @@ -7,8 +7,9 @@ golang: rootuser: root rootgroup: root command: go/bin/go + path: '' pkg: - name: go + name: golang use_upstream_repo: false use_upstream_archive: true archive: diff --git a/golang/osfamilymap.yaml b/golang/osfamilymap.yaml index 91c9b24..e5b2984 100644 --- a/golang/osfamilymap.yaml +++ b/golang/osfamilymap.yaml @@ -14,11 +14,15 @@ Debian: {} RedHat: {} -Suse: {} +Suse: + pkg: + name: go Gentoo: {} -Arch: {} +Arch: + pkg: + name: go Alpine: {} diff --git a/golang/package/install.sls b/golang/package/install.sls index 1529fa6..5c9d3ef 100644 --- a/golang/package/install.sls +++ b/golang/package/install.sls @@ -2,19 +2,23 @@ # vim: ft=sls {%- set tplroot = tpldir.split('/')[0] %} -{%- set sls_repo_install = '.repo' %} +{%- set sls_repo_install = tplroot ~ '.package.repo.install' %} {%- from tplroot ~ "/map.jinja" import golang with context %} {%- if grains.kernel|lower == 'linux' %} +{%- if golang.pkg.use_upstream_repo %} include: - {{ sls_repo_install }} +{%- endif %} golang-package-install-pkg-installed: pkg.installed: - name: {{ golang.pkg.name }} - reload_modules: true + {%- if golang.pkg.use_upstream_repo %} - require: - sls: {{ sls_repo_install }} + {%- endif %} {%- elif grains.os_family == 'MacOS' %} diff --git a/golang/package/repo/install.sls b/golang/package/repo/install.sls index cf594c1..e15751b 100644 --- a/golang/package/repo/install.sls +++ b/golang/package/repo/install.sls @@ -4,12 +4,8 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import golang with context %} - - {%- if golang.pkg.use_upstream_repo %} - {%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %} +{%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %} golang-package-repo-install-pkgrepo-managed: pkgrepo.managed: {{- format_kwargs(golang.pkg.repo) }} - - {%- endif %} diff --git a/kitchen.yml b/kitchen.yml index c40951d..b323092 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -164,3 +164,19 @@ suites: verifier: inspec_tests: - path: test/integration/default + - name: package + provisioner: + state_top: + base: + '*': + - golang + pillars: + top.sls: + base: + '*': + - golang + pillars_from_files: + golang.sls: test/salt/pillar/package.sls + verifier: + inspec_tests: + - path: test/integration/package diff --git a/test/integration/default/inspec.yml b/test/integration/default/inspec.yml index 2168298..bf2264b 100644 --- a/test/integration/default/inspec.yml +++ b/test/integration/default/inspec.yml @@ -5,7 +5,8 @@ name: default title: golang formula maintainer: SaltStack Formulas license: Apache-2.0 -summary: Verify that the golang formula is setup and configured correctly +# yamllint disable-line rule:line-length +summary: Verify that the golang formula is setup and configured correctly (installation from archive) supports: - platform-name: debian - platform-name: ubuntu diff --git a/test/integration/package/README.md b/test/integration/package/README.md new file mode 100644 index 0000000..8a5a5ba --- /dev/null +++ b/test/integration/package/README.md @@ -0,0 +1,50 @@ +# InSpec Profile: `package` + +This shows the implementation of the `package` InSpec [profile](https://github.com/inspec/inspec/blob/master/docs/profiles.md). + +## Verify a profile + +InSpec ships with built-in features to verify a profile structure. + +```bash +$ inspec check package +Summary +------- +Location: package +Profile: profile +Controls: 4 +Timestamp: 2019-06-24T23:09:01+00:00 +Valid: true + +Errors +------ + +Warnings +-------- +``` + +## Execute a profile + +To run all **supported** controls on a local machine use `inspec exec /path/to/profile`. + +```bash +$ inspec exec package +.. + +Finished in 0.0025 seconds (files took 0.12449 seconds to load) +8 examples, 0 failures +``` + +## Execute a specific control from a profile + +To run one control from the profile use `inspec exec /path/to/profile --controls name`. + +```bash +$ inspec exec package --controls package +. + +Finished in 0.0025 seconds (files took 0.12449 seconds to load) +1 examples, 0 failures +``` + +See an [example control here](https://github.com/inspec/inspec/blob/master/examples/profile/controls/example.rb). diff --git a/test/integration/package/controls/config_spec.rb b/test/integration/package/controls/config_spec.rb new file mode 100644 index 0000000..1406e94 --- /dev/null +++ b/test/integration/package/controls/config_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +control 'golang configuration' do + title 'should match desired configuration' + + describe file('/etc/default/golang.sh') do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } + its('mode') { should cmp '0644' } + end +end diff --git a/test/integration/package/controls/packages_spec.rb b/test/integration/package/controls/packages_spec.rb new file mode 100644 index 0000000..4973e98 --- /dev/null +++ b/test/integration/package/controls/packages_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +control 'golang package' do + title 'should be installed' + + # Overide by platform + pkg = + case platform[:family] + # `linux` covers `arch` here + when 'suse', 'linux' + 'go' + else + 'golang' + end + + describe package(pkg) do + it { should be_installed } + end +end diff --git a/test/integration/package/inspec.yml b/test/integration/package/inspec.yml new file mode 100644 index 0000000..02722c5 --- /dev/null +++ b/test/integration/package/inspec.yml @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +name: package +title: golang formula +maintainer: SaltStack Formulas +license: Apache-2.0 +# yamllint disable-line rule:line-length +summary: Verify that the golang formula is setup and configured correctly (installation from package) +supports: + - platform-name: debian + - platform-name: ubuntu + - platform-name: centos + - platform-name: fedora + - platform-name: opensuse + - platform-name: suse + - platform-name: freebsd + - platform-name: amazon + - platform-name: arch diff --git a/test/salt/pillar/package.sls b/test/salt/pillar/package.sls new file mode 100644 index 0000000..b92aac8 --- /dev/null +++ b/test/salt/pillar/package.sls @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +golang: + pkg: + use_upstream_repo: false + use_upstream_archive: false