Skip to content

Commit

Permalink
fix(alternatives): better no alternatives support
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmcloughlin committed Jan 25, 2020
1 parent c946e42 commit 04caf8e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
8 changes: 5 additions & 3 deletions golang/config/alternatives/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
{%- set sls_archive_install = tplroot ~ '.archive.install' %}
{%- set sls_package_install = tplroot ~ '.package.install' %}
{%- if golang.kernel == 'linux' and golang.linux.altpriority|int > 0 %}
{%- if grains.kernel|lower == 'linux' and golang.linux.altpriority|int > 0 %}
{%- if grains.os_family not in ('Arch', 'FreeBSD') %}
include:
- {{ sls_archive_install if golang.pkg.use_upstream_archive else sls_package_install }}
Expand Down Expand Up @@ -40,7 +41,7 @@ golang-package-archive-install-home-alternative-set:
- alternatives: golang-package-archive-install-home-alternative-install
- unless: {{ grains.os_family in ('Suse',) }}
{% for i in ['go', 'godoc', 'gofmt'] %}
{% for i in ['go', 'godoc', 'gofmt'] %}
golang-package-archive-install-{{ i }}-alternative-install:
cmd.run:
Expand All @@ -66,5 +67,6 @@ golang-package-archive-install-{{ i }}-alternative-set:
- alternatives: golang-package-archive-install-{{ i }}-alternative-install
- unless: {{ grains.os_family in ('Suse',) }}
{% endfor %}
{% endfor %}
{%- endif %}
{%- endif %}
17 changes: 17 additions & 0 deletions golang/config/environ.sls
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,20 @@ golang-config-file-managed-environ_file:
golang: {{ golang|json }}
- require:
- sls: {{ sls_archive_install if golang.pkg.use_upstream_archive else sls_package_install }}
{% for i in ('go', 'godoc', 'gofmt') %}
# create symlink under certain conditions
# archlinux, freebsd, macos for now
golang-config-file-symlink-{{ i }}-golang-binary:
file.symlink:
- name: /usr/local/bin/{{ i }}
- target: {{ golang.linux.base_dir }}/ {{ i }}
- mode: '0755'
- force: True
- onlyif:
- {{ grains.os_family in ('Arch', 'FreeBSD', 'MacOS') }}
- test -x {{ golang.linux.base_dir }}/ {{ i }}
{%- endfor %}
1 change: 1 addition & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ golang:

linux:
# 'Alternatives system' priority: zero disables (default)
base_dir: ''
altpriority: 9100

cmd:
Expand Down
15 changes: 8 additions & 7 deletions test/integration/default/controls/archives_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

control 'golang tar archive' do
impact 1.0
title 'should be installed'
Expand All @@ -16,25 +17,25 @@
binary = file('/usr/local/go1.10.1.linux-amd64/go/bin/go').content
sha256sum = Digest::SHA256.hexdigest(binary)
describe file('/usr/local/go1.10.1.linux-amd64/go/bin/go') do
# rubocop:disable LineLength
# rubocop:disable LineLength
its('sha256sum') { should eq '11438a2d41e257519e8c0ad098c287f9f73f1b8382a012a0c10e1dee5fb1e8ae' }
# rubocop:enable LineLength
# rubocop:enable LineLength
end

binary = file('/usr/local/go1.10.1.linux-amd64/go/bin/godoc').content
sha256sum = Digest::SHA256.hexdigest(binary)
describe file('/usr/local/go1.10.1.linux-amd64/go/bin/godoc') do
# rubocop:disable LineLength
# rubocop:disable LineLength
its('sha256sum') { should eq '4076bb73349f253c04e5ef214934938760eefb26529f22d2e6fdbd61b99bb4b5' }
# rubocop:enable LineLength
# rubocop:enable LineLength
end

binary = file('/usr/local/go1.10.1.linux-amd64/go/bin/gofmt').content
sha256sum = Digest::SHA256.hexdigest(binary)
describe file('/usr/local/go1.10.1.linux-amd64/go/bin/gofmt') do
# rubocop:disable LineLength
its('sha256sum') { should eq '5673f5914f195331322b20aee026f1882dac7c92b61c41bae23a04fb803b3e2c'}
# rubocop:enable LineLength
# rubocop:disable LineLength
its('sha256sum') { should eq '5673f5914f195331322b20aee026f1882dac7c92b61c41bae23a04fb803b3e2c' }
# rubocop:enable LineLength
end

end

0 comments on commit 04caf8e

Please sign in to comment.