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

Commit 1be751c

Browse files
committed
Update tests
1 parent c1bfced commit 1be751c

File tree

1 file changed

+48
-80
lines changed

1 file changed

+48
-80
lines changed

spec/classes/github_actions_runner_spec.rb

Lines changed: 48 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'spec_helper'
2-
require 'deep_merge'
32

43
describe 'github_actions_runner' do
54
on_supported_os.each do |os, os_facts|
@@ -165,98 +164,43 @@
165164
end
166165
end
167166

168-
context 'installation scripts' do
167+
context 'installation scripts for different types of runners' do
169168
let(:params) do
170-
super().deep_merge(
169+
super().merge(
170+
'org_name' => :undef,
171+
'enterprise_name' => :undef,
171172
'instances' => {
173+
'first_runner' => {
174+
'org_name' => 'github_org',
175+
'repo_name' => 'test_repo',
176+
},
172177
'org_runner' => {
178+
'org_name' => 'github_org',
179+
'labels' => ['default'],
180+
},
181+
'enterprise_runner' => {
182+
'org_name' => :undef,
183+
'enterprise_name' => 'test_enterprise',
173184
'labels' => ['default'],
174185
},
175186
},
176187
)
177188
end
178189

179-
install_script_content_first_runner = <<~HEREDOC
180-
#!/bin/bash
181-
# Configure the action runner after the package file has been downloaded.
182-
set -e
183-
184-
# Get registration token.
185-
TOKEN=$(curl -s -XPOST -H "authorization: token PAT" \\
186-
https://api.github.com/repos/github_org/test_repo/actions/runners/registration-token | jq -r .token)
187-
188-
# Allow root
189-
export RUNNER_ALLOW_RUNASROOT=true
190-
191-
192-
# (Optional) Remove previous config.
193-
/some_dir/actions-runner-2.272.0/first_runner/config.sh remove \\
194-
--url https://github.com/github_org/test_repo \\
195-
--token ${TOKEN} \\
196-
--name foo-first_runner &>/dev/null
197-
198-
199-
# Configure the runner.
200-
/some_dir/actions-runner-2.272.0/first_runner/config.sh \\
201-
--unattended \\
202-
--replace \\
203-
--name foo-first_runner \\
204-
--url https://github.com/github_org/test_repo \\
205-
--token ${TOKEN} \\
206-
--labels test_label1,test_label2 &>/dev/null
207-
208-
# Copy service endpoint script.
209-
if [ ! -f /some_dir/actions-runner-2.272.0/first_runner/runsvc.sh ]; then
210-
cp /some_dir/actions-runner-2.272.0/first_runner/bin/runsvc.sh /some_dir/actions-runner-2.272.0/first_runner/runsvc.sh
211-
chmod 755 /some_dir/actions-runner-2.272.0/first_runner/runsvc.sh
212-
fi
213-
HEREDOC
214-
install_script_content_org_runner = <<~HEREDOC
215-
#!/bin/bash
216-
# Configure the action runner after the package file has been downloaded.
217-
set -e
218-
219-
# Get registration token.
220-
TOKEN=$(curl -s -XPOST -H "authorization: token PAT" \\
221-
https://api.github.com/orgs/github_org/actions/runners/registration-token | jq -r .token)
222-
223-
# Allow root
224-
export RUNNER_ALLOW_RUNASROOT=true
225-
226-
227-
# (Optional) Remove previous config.
228-
/some_dir/actions-runner-2.272.0/org_runner/config.sh remove \\
229-
--url https://github.com/github_org \\
230-
--token ${TOKEN} \\
231-
--name foo-org_runner &>/dev/null
232-
233-
234-
# Configure the runner.
235-
/some_dir/actions-runner-2.272.0/org_runner/config.sh \\
236-
--unattended \\
237-
--replace \\
238-
--name foo-org_runner \\
239-
--url https://github.com/github_org \\
240-
--token ${TOKEN} \\
241-
--labels default &>/dev/null
242-
243-
# Copy service endpoint script.
244-
if [ ! -f /some_dir/actions-runner-2.272.0/org_runner/runsvc.sh ]; then
245-
cp /some_dir/actions-runner-2.272.0/org_runner/bin/runsvc.sh /some_dir/actions-runner-2.272.0/org_runner/runsvc.sh
246-
chmod 755 /some_dir/actions-runner-2.272.0/org_runner/runsvc.sh
247-
fi
248-
HEREDOC
249-
250190
it 'creates a repo specific runner script' do
251191
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with(
252192
'ensure' => 'present',
253193
'owner' => 'root',
254194
'group' => 'root',
255195
'mode' => '0755',
256-
'require' => 'Archive[first_runner-actions-runner-linux-x64-2.272.0.tar.gz]',
257-
'notify' => 'Exec[first_runner-run_configure_install_runner.sh]',
258-
'content' => install_script_content_first_runner,
259196
)
197+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(
198+
%r{https://api.github.com/repos/github_org/test_repo/actions/runners/registration-token},
199+
)
200+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{--url https://github.com/github_org/test_repo })
201+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{--name foo-first_runner })
202+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').that_requires('Archive[first_runner-actions-runner-linux-x64-2.272.0.tar.gz]')
203+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').that_notifies('Exec[first_runner-run_configure_install_runner.sh]')
260204
end
261205

262206
it 'creates an org specific runner script' do
@@ -265,10 +209,32 @@
265209
'owner' => 'root',
266210
'group' => 'root',
267211
'mode' => '0755',
268-
'require' => 'Archive[org_runner-actions-runner-linux-x64-2.272.0.tar.gz]',
269-
'notify' => 'Exec[org_runner-run_configure_install_runner.sh]',
270-
'content' => install_script_content_org_runner,
271212
)
213+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/org_runner/configure_install_runner.sh').with_content(
214+
%r{https://api.github.com/orgs/github_org/actions/runners/registration-token},
215+
)
216+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/org_runner/configure_install_runner.sh').with_content(%r{--url https://github.com/github_org })
217+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/org_runner/configure_install_runner.sh').with_content(%r{--name foo-org_runner })
218+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/org_runner/configure_install_runner.sh').that_requires('Archive[org_runner-actions-runner-linux-x64-2.272.0.tar.gz]')
219+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/org_runner/configure_install_runner.sh').that_notifies('Exec[org_runner-run_configure_install_runner.sh]')
220+
end
221+
222+
it 'creates an enterprise specific runner script' do
223+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/enterprise_runner/configure_install_runner.sh').with(
224+
'ensure' => 'present',
225+
'owner' => 'root',
226+
'group' => 'root',
227+
'mode' => '0755',
228+
)
229+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/enterprise_runner/configure_install_runner.sh').with_content(
230+
%r{https://api.github.com/enterprises/test_enterprise/actions/runners/registration-token},
231+
)
232+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/enterprise_runner/configure_install_runner.sh').with_content(%r{--url https://github.com/enterprises/test_enterprise })
233+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/enterprise_runner/configure_install_runner.sh').with_content(%r{--name foo-enterprise_runner })
234+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/enterprise_runner/configure_install_runner.sh').that_requires(
235+
'Archive[enterprise_runner-actions-runner-linux-x64-2.272.0.tar.gz]',
236+
)
237+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/enterprise_runner/configure_install_runner.sh').that_notifies('Exec[enterprise_runner-run_configure_install_runner.sh]')
272238
end
273239
end
274240

@@ -329,6 +295,8 @@
329295

330296
it do
331297
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{https://github.com/enterprises/test_enterprise})
298+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{--url https://github.com/enterprises/test_enterprise })
299+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{--name foo-first_runner })
332300
end
333301
end
334302

0 commit comments

Comments
 (0)