Skip to content

Commit 721fd97

Browse files
committed
Acceptance tests: check .source_url file
This also makes the tests for `golang::from_tarball` more robust.
1 parent 528429f commit 721fd97

File tree

3 files changed

+91
-12
lines changed

3 files changed

+91
-12
lines changed

spec/acceptance/golang_from_tarball_spec.rb

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,130 @@
22

33
require 'spec_helper_acceptance'
44

5+
# This tarball contains entries owned by gopher (501) rather than root.
6+
source_url = 'https://go.dev/dl/go1.10.4.darwin-amd64.tar.gz'
7+
8+
newer_source_url = 'https://go.dev/dl/go1.19.1.darwin-amd64.tar.gz'
9+
510
describe 'defined type golang::from_tarball' do
611
context 'repeated root installs:' do
712
context 'default ensure with 1.10.4 source' do
813
it 'installs Go' do
9-
idempotent_apply(<<~'PUPPET')
14+
idempotent_apply(<<~"PUPPET")
1015
golang::from_tarball { '/opt/go':
11-
source => 'https://go.dev/dl/go1.10.4.linux-amd64.tar.gz',
16+
source => '#{source_url}',
1217
}
1318
PUPPET
1419
end
1520

21+
describe file('/opt/go') do
22+
it { is_expected.to be_directory }
23+
its(:mode) { is_expected.to eq '755' }
24+
its(:owner) { is_expected.to eq 'root' }
25+
end
26+
27+
describe file('/opt/.go.source_url') do
28+
it { is_expected.to be_file }
29+
its(:mode) { is_expected.to eq '444' }
30+
its(:owner) { is_expected.to eq 'root' }
31+
its(:content) { is_expected.to include "\n#{source_url}\n" }
32+
end
33+
34+
describe file('/opt/go/bin/go') do
35+
it { is_expected.to be_file }
36+
its(:mode) { is_expected.to eq '755' }
37+
its(:owner) { is_expected.to eq 'root' }
38+
end
39+
1640
describe file('/opt/go/VERSION') do
1741
its(:content) { is_expected.to eq 'go1.10.4' }
1842
end
1943
end
2044

2145
context 'ensure => present' do
2246
it 'causes no changes' do
23-
apply_manifest(<<~'PUPPET', catch_changes: true)
47+
apply_manifest(<<~"PUPPET", catch_changes: true)
2448
golang::from_tarball { '/opt/go':
2549
ensure => present,
26-
source => 'https://go.dev/dl/go1.10.4.linux-amd64.tar.gz',
50+
source => '#{source_url}',
2751
}
2852
PUPPET
2953
end
3054

55+
describe file('/opt/.go.source_url') do
56+
it { is_expected.to be_file }
57+
its(:mode) { is_expected.to eq '444' }
58+
its(:owner) { is_expected.to eq 'root' }
59+
its(:content) { is_expected.to include "\n#{source_url}\n" }
60+
end
61+
3162
describe file('/opt/go/VERSION') do
3263
its(:content) { is_expected.to eq 'go1.10.4' }
3364
end
3465
end
3566

36-
context 'ensure => any_version with 1.19.1 source' do
67+
context 'ensure => any_version with newer source' do
3768
it 'causes no changes' do
38-
apply_manifest(<<~'PUPPET', catch_changes: true)
69+
apply_manifest(<<~"PUPPET", catch_changes: true)
3970
golang::from_tarball { '/opt/go':
4071
ensure => any_version,
41-
source => 'https://go.dev/dl/go1.19.1.linux-amd64.tar.gz',
72+
source => '#{newer_source_url}',
4273
}
4374
PUPPET
4475
end
4576

77+
describe file('/opt/.go.source_url') do
78+
it { is_expected.to be_file }
79+
its(:mode) { is_expected.to eq '444' }
80+
its(:owner) { is_expected.to eq 'root' }
81+
its(:content) { is_expected.to include "\n#{source_url}\n" }
82+
end
83+
4684
describe file('/opt/go/VERSION') do
4785
its(:content) { is_expected.to eq 'go1.10.4' }
4886
end
4987
end
5088

51-
context 'ensure => present with 1.19.1 source' do
89+
context 'ensure => present with newer source' do
5290
it 'causes changes' do
53-
apply_manifest(<<~'PUPPET', expect_changes: true)
91+
apply_manifest(<<~"PUPPET", expect_changes: true)
5492
golang::from_tarball { '/opt/go':
5593
ensure => present,
56-
source => 'https://go.dev/dl/go1.19.1.linux-amd64.tar.gz',
94+
source => '#{newer_source_url}',
5795
}
5896
PUPPET
5997
end
6098

99+
describe file('/opt/.go.source_url') do
100+
it { is_expected.to be_file }
101+
its(:mode) { is_expected.to eq '444' }
102+
its(:owner) { is_expected.to eq 'root' }
103+
its(:content) { is_expected.to include "\n#{newer_source_url}\n" }
104+
end
105+
61106
describe file('/opt/go/VERSION') do
62107
its(:content) { is_expected.to eq 'go1.19.1' }
63108
end
64109
end
65110

66111
context 'ensure => absent' do
67112
it do
68-
idempotent_apply(<<~'PUPPET')
113+
idempotent_apply(<<~"PUPPET")
69114
golang::from_tarball { '/opt/go':
70115
ensure => absent,
71-
source => 'https://go.dev/dl/go1.19.1.linux-amd64.tar.gz',
116+
source => '#{newer_source_url}',
72117
}
73118
PUPPET
74119
end
75120

121+
describe file('/opt/go') do
122+
it { is_expected.not_to exist }
123+
end
124+
125+
describe file('/opt/.go.source_url') do
126+
it { is_expected.not_to exist }
127+
end
128+
76129
describe file('/opt/go/VERSION') do
77130
it { is_expected.not_to exist }
78131
end

spec/acceptance/golang_installation_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@
111111
its(:owner) { is_expected.to eq 'root' }
112112
end
113113

114+
describe file("/opt/.go#{version}.source_url") do
115+
it { is_expected.to be_file }
116+
its(:mode) { is_expected.to eq '444' }
117+
its(:owner) { is_expected.to eq 'root' }
118+
its(:content) { is_expected.to include "\nhttps://go.dev/dl/" }
119+
end
120+
114121
describe file("/opt/go#{version}/bin/go") do
115122
it { is_expected.to be_file }
116123
it { is_expected.to be_executable }
@@ -241,6 +248,14 @@
241248
it { is_expected.to be_mode 700 } # WTF converted to octal
242249
end
243250

251+
describe file("#{home}/user/.go#{version}.source_url") do
252+
it { is_expected.to be_file }
253+
its(:mode) { is_expected.to eq '444' }
254+
its(:owner) { is_expected.to eq 'user' }
255+
its(:group) { is_expected.to eq 'user' }
256+
its(:content) { is_expected.to include "\nhttps://go.dev/dl/" }
257+
end
258+
244259
describe file("#{home}/user/go#{version}/bin/go") do
245260
it { is_expected.to be_file }
246261
its(:owner) { is_expected.to eq 'user' }

spec/acceptance/golang_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ class { 'golang':
5050
its(:owner) { is_expected.to eq 'root' }
5151
end
5252

53+
describe file('/usr/local/.go.source_url') do
54+
it { is_expected.to be_file }
55+
its(:mode) { is_expected.to eq '444' }
56+
its(:owner) { is_expected.to eq 'root' }
57+
its(:content) { is_expected.to include "\nhttps://go.dev/dl/" }
58+
end
59+
5360
describe file('/usr/local/go/bin/go') do
5461
it { is_expected.to be_file }
5562
it { is_expected.to be_executable }
@@ -86,6 +93,10 @@ class { 'golang':
8693
it { is_expected.not_to exist }
8794
end
8895

96+
describe file('/usr/local/.go.source_url') do
97+
it { is_expected.not_to exist }
98+
end
99+
89100
describe file('/usr/local/bin/go') do
90101
it { is_expected.not_to exist }
91102
end

0 commit comments

Comments
 (0)