File tree 2 files changed +48
-0
lines changed
2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ # https://puppet.com/docs/puppet/latest/fact_overview.html
4
+ Facter . add ( :loginctl_linger_users ) do
5
+ confine kernel : 'Linux'
6
+
7
+ setcode do
8
+ users = [ ]
9
+
10
+ if Dir . exist? ( '/var/lib/systemd/linger' )
11
+ users = Dir . entries ( '/var/lib/systemd/linger' )
12
+ users . delete ( '.' )
13
+ users . delete ( '..' )
14
+ end
15
+
16
+ users . append ( 'root' ) unless users . include? ( 'root' ) # root should always linger
17
+
18
+ users
19
+ end
20
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Facter . fact ( :loginctl_linger_users ) do
6
+ before do
7
+ Facter . clear
8
+ end
9
+
10
+ describe 'loginctl_linger_users' do
11
+ context 'returns root when nothing is present' do
12
+ allow ( Dir ) . to receive ( :exist? ) . with ( '/var/lib/systemd/linger' ) . and_return ( false )
13
+
14
+ it do
15
+ expect ( Facter . value ( :loginctl_linger_users ) ) . to eq ( [ 'root' ] )
16
+ end
17
+ end
18
+
19
+ context 'returns list with root others are present' do
20
+ allow ( Dir ) . to receive ( :exist? ) . with ( '/var/lib/systemd/linger' ) . and_return ( true )
21
+ allow ( Dir ) . to receive ( :entries ) . with ( '/var/lib/systemd/linger' ) . and_return ( %w[ . .. abc test ] )
22
+
23
+ it do
24
+ expect ( Facter . value ( :loginctl_linger_users ) ) . to eq ( %w[ abc test root ] )
25
+ end
26
+ end
27
+ end
28
+ end
You can’t perform that action at this time.
0 commit comments