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

Commit 581d5c6

Browse files
committed
Require non-empty strings and update tests
1 parent a3e0d31 commit 581d5c6

File tree

3 files changed

+51
-46
lines changed

3 files changed

+51
-46
lines changed

manifests/init.pp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@
5858
class github_actions_runner (
5959
Enum['present', 'absent'] $ensure,
6060
Stdlib::Absolutepath $base_dir_name,
61-
String $personal_access_token,
62-
String $package_name,
63-
String $package_ensure,
64-
String $repository_url,
65-
String $user,
66-
String $group,
67-
Hash[String, Hash] $instances,
68-
String $github_domain,
69-
String $github_api,
70-
Optional[String] $enterprise_name = undef,
71-
Optional[String] $org_name = undef,
72-
Optional[String] $http_proxy = undef,
73-
Optional[String] $https_proxy = undef,
74-
Optional[String] $no_proxy = undef,
61+
String[1] $personal_access_token,
62+
String[1] $package_name,
63+
String[1] $package_ensure,
64+
String[1] $repository_url,
65+
String[1] $user,
66+
String[1] $group,
67+
Hash[String[1], Hash] $instances,
68+
String[1] $github_domain,
69+
String[1] $github_api,
70+
Optional[String[1]] $enterprise_name = undef,
71+
Optional[String[1]] $org_name = undef,
72+
Optional[String[1]] $http_proxy = undef,
73+
Optional[String[1]] $https_proxy = undef,
74+
Optional[String[1]] $no_proxy = undef,
7575
) {
7676

7777
$root_dir = "${github_actions_runner::base_dir_name}-${github_actions_runner::package_ensure}"

manifests/instance.pp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@
4242
# Optional[Array[String]], A list of costum lables to add to a runner.
4343
#
4444
define github_actions_runner::instance (
45-
Enum['present', 'absent'] $ensure = 'present',
46-
String $personal_access_token = $github_actions_runner::personal_access_token,
47-
String $user = $github_actions_runner::user,
48-
String $group = $github_actions_runner::group,
49-
String $hostname = $::facts['hostname'],
50-
String $instance_name = $title,
51-
String $github_domain = $github_actions_runner::github_domain,
52-
String $github_api = $github_actions_runner::github_api,
53-
Optional[String] $http_proxy = $github_actions_runner::http_proxy,
54-
Optional[String] $https_proxy = $github_actions_runner::https_proxy,
55-
Optional[String] $no_proxy = $github_actions_runner::no_proxy,
56-
Optional[Array[String]] $labels = undef,
57-
Optional[String] $enterprise_name = $github_actions_runner::enterprise_name,
58-
Optional[String] $org_name = $github_actions_runner::org_name,
59-
Optional[String] $repo_name = undef,
45+
Enum['present', 'absent'] $ensure = 'present',
46+
String[1] $personal_access_token = $github_actions_runner::personal_access_token,
47+
String[1] $user = $github_actions_runner::user,
48+
String[1] $group = $github_actions_runner::group,
49+
String[1] $hostname = $::facts['hostname'],
50+
String[1] $instance_name = $title,
51+
String[1] $github_domain = $github_actions_runner::github_domain,
52+
String[1] $github_api = $github_actions_runner::github_api,
53+
Optional[String[1]] $http_proxy = $github_actions_runner::http_proxy,
54+
Optional[String[1]] $https_proxy = $github_actions_runner::https_proxy,
55+
Optional[String[1]] $no_proxy = $github_actions_runner::no_proxy,
56+
Optional[Array[String[1]]] $labels = undef,
57+
Optional[String[1]] $enterprise_name = $github_actions_runner::enterprise_name,
58+
Optional[String[1]] $org_name = $github_actions_runner::org_name,
59+
Optional[String[1]] $repo_name = undef,
6060
) {
6161

6262
if $labels {
@@ -66,7 +66,6 @@
6666
$assured_labels = ''
6767
}
6868

69-
7069
if $org_name {
7170
if $repo_name {
7271
$token_url = "${github_api}/repos/${org_name}/${repo_name}/actions/runners/registration-token"

spec/classes/github_actions_runner_spec.rb

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,30 @@
66
let(:facts) { os_facts }
77
let(:params) do
88
{
9+
'org_name' => 'github_org',
910
'instances' => {
10-
'first_runner' => {},
11+
'first_runner' => {
12+
'labels' => ['test_label1', 'test_label2'],
13+
'repo_name' => 'test_repo',
14+
},
1115
},
1216
}
1317
end
1418

15-
context 'is expected compile and raise error' do
19+
context 'is expected compile' do
1620
it do
17-
is_expected.to compile.and_raise_error(%r{Either 'org_name' or 'enterprise_name' is required to create runner instances})
21+
is_expected.to compile.with_all_deps
22+
is_expected.to contain_class('github_actions_runner')
1823
end
1924
end
2025

21-
context 'is expected compile' do
26+
context 'is expected compile and raise error when required values are undefined' do
2227
let(:params) do
23-
super().merge(
24-
'org_name' => 'github_org',
25-
'instances' => {
26-
'first_runner' => {
27-
'labels' => ['test_label1', 'test_label2'],
28-
'repo_name' => 'test_repo',
29-
},
30-
},
31-
)
28+
super().merge('org_name' => :undef, 'enterprise_name' => :undef)
3229
end
3330

3431
it do
35-
it { is_expected.to compile.with_all_deps }
36-
it { is_expected.to contain_class('github_actions_runner') }
32+
is_expected.to compile.and_raise_error(%r{Either 'org_name' or 'enterprise_name' is required to create runner instances})
3733
end
3834
end
3935

@@ -189,6 +185,16 @@
189185
end
190186
end
191187

188+
context 'is expected to create a github_actions_runner installation script with test_org in content ignoring enterprise_name' do
189+
let(:params) do
190+
super().merge('org_name' => 'test_org', 'enterprise_name' => 'test_enterprise')
191+
end
192+
193+
it do
194+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{https://github.com/test_org/test_repo})
195+
end
196+
end
197+
192198
context 'is expected to create a github_actions_runner installation script with test_org in content' do
193199
let(:params) do
194200
super().merge('org_name' => 'test_org')
@@ -201,7 +207,7 @@
201207

202208
context 'is expected to create a github_actions_runner installation script with test_enterprise in content' do
203209
let(:params) do
204-
super().merge('org_name' => '',
210+
super().merge('org_name' => :undef,
205211
'enterprise_name' => 'test_enterprise')
206212
end
207213

0 commit comments

Comments
 (0)