Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit 7bc9786

Browse files
author
Shimon
authored
[0.2.4]Fixing files permissions, adding unit tests (#11)
* Fixing files permissions, adding unit tests * adding test with defaults params * add more unit test to cover all params
1 parent d0ee06a commit 7bc9786

File tree

3 files changed

+149
-20
lines changed

3 files changed

+149
-20
lines changed

manifests/instance.pp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
archive { "${instance_name}-${archive_name}":
8181
ensure => $ensure,
8282
path => "/tmp/${instance_name}-${archive_name}",
83+
user => $user,
84+
group => $group,
8385
source => $source,
8486
extract => true,
8587
extract_path => "${github_actions_runner::root_dir}/${instance_name}",
@@ -106,7 +108,17 @@
106108
require => Archive["${instance_name}-${archive_name}"],
107109
}
108110

111+
exec { "${instance_name}-ownership":
112+
user => $user,
113+
cwd => "${github_actions_runner::root_dir}",
114+
command => "/bin/chown -R ${user}:${group} ${github_actions_runner::root_dir}/${instance_name}",
115+
refreshonly => true,
116+
path => "/tmp/${instance_name}-${archive_name}",
117+
subscribe => Archive["${instance_name}-${archive_name}"]
118+
}
119+
109120
exec { "${instance_name}-run_configure_install_runner.sh":
121+
user => $user,
110122
cwd => "${github_actions_runner::root_dir}/${instance_name}",
111123
command => "${github_actions_runner::root_dir}/${instance_name}/configure_install_runner.sh",
112124
refreshonly => true

metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "telefonica-github_actions_runner",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"author": "Shimon Ohayon",
55
"summary": "Module to configure our GitHub Actions runner on Debian hosts",
66
"license": "Apache-2.0",

spec/classes/github_actions_runner_spec.rb

Lines changed: 136 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,44 @@
66
let(:facts) { os_facts }
77
let(:params) do
88
{
9-
:ensure => 'present',
10-
:org_name => 'test_org',
11-
:personal_access_token => 'test_PAT',
12-
:package_name => 'test_package',
13-
:package_ensure => '1.0.1',
14-
:repository_url => 'https://test_url',
15-
:user => 'test_user',
16-
:group => 'test_group',
17-
:base_dir_name => '/tmp/actions-runner',
18-
:instances => { 'first_runner' => { 'labels' => ['test_label1', 'test_label2'], 'repo_name' => 'test_repo'}}, }
9+
:instances => { 'first_runner' => { 'labels' => ['test_label1', 'test_label2'], 'repo_name' => 'test_repo'}}, }
1910
end
2011

2112
it { is_expected.to compile.with_all_deps }
2213
it { is_expected.to contain_class('github_actions_runner') }
2314

2415
context 'is expected to create a github_actions_runner root directory' do
2516
it do
26-
is_expected.to contain_file('/tmp/actions-runner-1.0.1').with({
17+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0').with({
18+
'ensure' => 'directory',
19+
'owner' => 'root',
20+
'group' => 'root',
21+
'mode' => '0644',
22+
})
23+
end
24+
end
25+
26+
context 'is expected to create a github_actions_runner a new root directory' do
27+
let(:params) do
28+
super().merge({ 'base_dir_name' => '/tmp/actions-runner'})
29+
end
30+
it do
31+
is_expected.to contain_file('/tmp/actions-runner-2.272.0').with({
32+
'ensure' => 'directory',
33+
'owner' => 'root',
34+
'group' => 'root',
35+
'mode' => '0644',
36+
})
37+
end
38+
end
39+
40+
context 'is expected to create a github_actions_runner root directory with test user' do
41+
let(:params) do
42+
super().merge({ 'user' => 'test_user',
43+
'group' => 'test_group'})
44+
end
45+
it do
46+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0').with({
2747
'ensure' => 'directory',
2848
'owner' => 'test_user',
2949
'group' => 'test_group',
@@ -34,7 +54,22 @@
3454

3555
context 'is expected to create a github_actions_runner instance directory' do
3656
it do
37-
is_expected.to contain_file('/tmp/actions-runner-1.0.1/first_runner').with({
57+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner').with({
58+
'ensure' => 'directory',
59+
'owner' => 'root',
60+
'group' => 'root',
61+
'mode' => '0644',
62+
})
63+
end
64+
end
65+
66+
context 'is expected to create a github_actions_runner instance directory with test user' do
67+
let(:params) do
68+
super().merge({ 'user' => 'test_user',
69+
'group' => 'test_group'})
70+
end
71+
it do
72+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner').with({
3873
'ensure' => 'directory',
3974
'owner' => 'test_user',
4075
'group' => 'test_group',
@@ -49,32 +84,114 @@
4984
end
5085
end
5186

87+
context 'is expected to contain archive' do
88+
it do
89+
is_expected.to contain_archive("first_runner-actions-runner-linux-x64-2.272.0.tar.gz").with({
90+
'ensure' => 'present',
91+
'user' => 'root',
92+
'group' => 'root',
93+
})
94+
end
95+
end
96+
97+
context 'is expected to contain archive with test package and test url' do
98+
let(:params) do
99+
super().merge({ 'package_name' => 'test_package',
100+
'package_ensure' => '9.9.9',
101+
'repository_url' => 'https://test_url'})
102+
end
103+
it do
104+
is_expected.to contain_archive("first_runner-test_package-9.9.9.tar.gz").with({
105+
'ensure' => 'present',
106+
'user' => 'root',
107+
'group' => 'root',
108+
'source' => 'https://test_url/v9.9.9/test_package-9.9.9.tar.gz'
109+
})
110+
end
111+
end
112+
113+
context 'is expected to contain an ownership exec' do
114+
it do
115+
is_expected.to contain_exec('first_runner-ownership').with({
116+
'user' => 'root',
117+
'command' => '/bin/chown -R root:root /some_dir/actions-runner-2.272.0/first_runner',
118+
})
119+
end
120+
end
121+
122+
context 'is expected to contain a Run exec' do
123+
it do
124+
is_expected.to contain_exec('first_runner-run_configure_install_runner.sh').with({
125+
'user' => 'root',
126+
'command' => '/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh',
127+
})
128+
end
129+
end
130+
52131
context 'is expected to create a github_actions_runner installation script' do
53132
it do
54-
is_expected.to contain_file('/tmp/actions-runner-1.0.1/first_runner/configure_install_runner.sh').with({
133+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with({
55134
'ensure' => 'present',
56-
'owner' => 'test_user',
57-
'group' => 'test_group',
135+
'owner' => 'root',
136+
'group' => 'root',
137+
'mode' => '0755',
138+
})
139+
end
140+
end
141+
142+
context 'is expected to create a github_actions_runner installation script with test version' do
143+
let(:params) do
144+
super().merge({ 'package_ensure' => '9.9.9'})
145+
end
146+
it do
147+
is_expected.to contain_file('/some_dir/actions-runner-9.9.9/first_runner/configure_install_runner.sh').with({
148+
'ensure' => 'present',
149+
'owner' => 'root',
150+
'group' => 'root',
58151
'mode' => '0755',
59152
})
60153
end
61154
end
62155

63156
context 'is expected to create a github_actions_runner installation script with config in content' do
64157
it do
65-
is_expected.to contain_file('/tmp/actions-runner-1.0.1/first_runner/configure_install_runner.sh').with_content(/\/tmp\/actions-runner-1.0.1\/first_runner\/config.sh/)
158+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(/\/some_dir\/actions-runner-2.272.0\/first_runner\/config.sh/)
66159
end
67160
end
68161

69-
context 'is expected to create a github_actions_runner installation script with repo url in content' do
162+
context 'is expected to create a github_actions_runner installation script with github org in content' do
70163
it do
71-
is_expected.to contain_file('/tmp/actions-runner-1.0.1/first_runner/configure_install_runner.sh').with_content(/https:\/\/github.com\/test_org\/test_repo/)
164+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(/https:\/\/github.com\/github_org\/test_repo/)
165+
end
166+
end
167+
168+
context 'is expected to create a github_actions_runner installation script with test_org in content ' do
169+
let(:params) do
170+
super().merge({ 'org_name' => 'test_org'})
171+
end
172+
it do
173+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(/https:\/\/github.com\/test_org\/test_repo/)
72174
end
73175
end
74176

75177
context 'is expected to create a github_actions_runner installation script with labels in content' do
76178
it do
77-
is_expected.to contain_file('/tmp/actions-runner-1.0.1/first_runner/configure_install_runner.sh').with_content(/test_label1,test_label2/)
179+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(/test_label1,test_label2/)
180+
end
181+
end
182+
183+
context 'is expected to create a github_actions_runner installation script with PAT in content' do
184+
it do
185+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(/authorization: token PAT/)
186+
end
187+
end
188+
189+
context 'is expected to create a github_actions_runner installation script with test_PAT in content' do
190+
let(:params) do
191+
super().merge({ 'personal_access_token' => 'test_PAT'})
192+
end
193+
it do
194+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(/authorization: token test_PAT/)
78195
end
79196
end
80197
end

0 commit comments

Comments
 (0)