-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathaccounts_group_members_spec.rb
More file actions
88 lines (75 loc) · 2.63 KB
/
accounts_group_members_spec.rb
File metadata and controls
88 lines (75 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#! /usr/bin/env ruby -S rspec
# frozen_string_literal: true
require 'spec_helper'
require 'rspec-puppet'
describe 'accounts_group_members' do
describe 'basic usage ' do
it 'should raise an error if run with extra arguments' do
is_expected.to run.with_params(1, 2, 3, 4).and_raise_error(Puppet::ParseError)
end
it 'should raise an error with incorrect type of arguments' do
is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError)
end
it 'should raise an error when running without arguments' do
is_expected.to run.with_params(nil).and_raise_error(Puppet::ParseError)
end
it 'should raise an error when given incorrect type' do
is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError)
end
end
describe 'extract group members' do
it 'find groups assignments' do
users = {
foo: { 'groups' => ['sudo', 'users']},
john: { 'groups' => ['bar', 'users']},
}
is_expected.to run.with_params(users, {}).and_return(
{
'sudo' => {'members' => [:foo], 'before'=> ['User[foo]']},
'bar' => {'members' => [:john],'before'=> ['User[john]']},
'users' => {'members' => [:foo,:john], 'before'=> ['User[foo]','User[john]']},
'foo' => {'members' => [], 'before' => []},
'john' => {'members' => [], 'before' => []},
}
)
end
it 'skips absent users' do
users = {
alice: { 'groups' => ['users']},
bob: { 'groups' => ['sudo', 'users']},
tracy: { 'groups' => ['sudo', 'users'], 'ensure' => 'absent'},
}
is_expected.to run.with_params(users, {}).and_return(
{
'alice' => {'members' => [], 'before'=> []},
'bob' => {'members' => [], 'before'=> []},
'sudo' => {'members' => [:bob], 'before'=> ['User[bob]']},
'users' => {
'members' => [:alice,:bob],
'before'=> ['User[alice]', 'User[bob]']
},
}
)
end
end
describe 'do not extract primary groups' do
it 'finds group specified by primary_group' do
users = {
foo: { 'primary_group' => 'testgroup', 'manage_group' => true},
}
is_expected.to run.with_params(users, {}).and_return(
{'testgroup' => {'members' => [], 'before' => []}}
)
end
it 'finds group with gid' do
users = {
foo: { 'primary_group' => 'testgroup',
'manage_group' => true, 'gid' => 123,
'before' => []},
}
is_expected.to run.with_params(users, {}).and_return(
{"testgroup"=>{"members"=>[], "before"=>[], "gid"=>123}}
)
end
end
end