chefspec 2.0.1 → 3.0.0.beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/chefspec.rb +30 -44
- data/lib/chefspec/api.rb +74 -0
- data/lib/chefspec/api/apt_package.rb +192 -0
- data/lib/chefspec/api/batch.rb +43 -0
- data/lib/chefspec/api/chef_gem.rb +191 -0
- data/lib/chefspec/api/cookbook_file.rb +166 -0
- data/lib/chefspec/api/cron.rb +80 -0
- data/lib/chefspec/api/deploy.rb +117 -0
- data/lib/chefspec/api/directory.rb +80 -0
- data/lib/chefspec/api/dpkg_package.rb +117 -0
- data/lib/chefspec/api/easy_install_package.rb +154 -0
- data/lib/chefspec/api/env.rb +117 -0
- data/lib/chefspec/api/erl_call.rb +43 -0
- data/lib/chefspec/api/execute.rb +43 -0
- data/lib/chefspec/api/file.rb +166 -0
- data/lib/chefspec/api/freebsd_package.rb +80 -0
- data/lib/chefspec/api/gem_package.rb +191 -0
- data/lib/chefspec/api/git.rb +117 -0
- data/lib/chefspec/api/group.rb +154 -0
- data/lib/chefspec/api/http_request.rb +228 -0
- data/lib/chefspec/api/ifconfig.rb +154 -0
- data/lib/chefspec/api/include_recipe.rb +26 -0
- data/lib/chefspec/api/ips_package.rb +117 -0
- data/lib/chefspec/api/link.rb +102 -0
- data/lib/chefspec/api/log.rb +43 -0
- data/lib/chefspec/api/macports_package.rb +154 -0
- data/lib/chefspec/api/mdadm.rb +117 -0
- data/lib/chefspec/api/mount.rb +192 -0
- data/lib/chefspec/api/notifications.rb +38 -0
- data/lib/chefspec/api/ohai.rb +43 -0
- data/lib/chefspec/api/package.rb +192 -0
- data/lib/chefspec/api/pacman_package.rb +155 -0
- data/lib/chefspec/api/portage_package.rb +155 -0
- data/lib/chefspec/api/powershell_script.rb +43 -0
- data/lib/chefspec/api/registry_key.rb +166 -0
- data/lib/chefspec/api/remote_directory.rb +120 -0
- data/lib/chefspec/api/remote_file.rb +166 -0
- data/lib/chefspec/api/render_file.rb +32 -0
- data/lib/chefspec/api/route.rb +80 -0
- data/lib/chefspec/api/rpm_package.rb +117 -0
- data/lib/chefspec/api/ruby_block.rb +37 -0
- data/lib/chefspec/api/script.rb +228 -0
- data/lib/chefspec/api/service.rb +246 -0
- data/lib/chefspec/api/smartos_package.rb +117 -0
- data/lib/chefspec/api/solaris_package.rb +80 -0
- data/lib/chefspec/api/subversion.rb +154 -0
- data/lib/chefspec/api/template.rb +166 -0
- data/lib/chefspec/api/user.rb +228 -0
- data/lib/chefspec/api/yum_package.rb +154 -0
- data/lib/chefspec/berkshelf.rb +37 -0
- data/lib/chefspec/deprecations.rb +151 -0
- data/lib/chefspec/errors.rb +99 -0
- data/lib/chefspec/expect_exception.rb +45 -0
- data/lib/chefspec/extensions/chef/client.rb +15 -0
- data/lib/chefspec/extensions/chef/conditional.rb +11 -0
- data/lib/chefspec/extensions/chef/data_query.rb +29 -0
- data/lib/chefspec/extensions/chef/lwrp_base.rb +44 -0
- data/lib/chefspec/extensions/chef/resource.rb +27 -0
- data/lib/chefspec/extensions/chef/securable.rb +19 -0
- data/lib/chefspec/formatter.rb +270 -0
- data/lib/chefspec/macros.rb +217 -0
- data/lib/chefspec/matchers.rb +9 -0
- data/lib/chefspec/matchers/include_recipe_matcher.rb +45 -0
- data/lib/chefspec/matchers/link_to_matcher.rb +28 -0
- data/lib/chefspec/matchers/notifications_matcher.rb +92 -0
- data/lib/chefspec/matchers/render_file_matcher.rb +72 -0
- data/lib/chefspec/matchers/resource_matcher.rb +143 -0
- data/lib/chefspec/renderer.rb +137 -0
- data/lib/chefspec/rspec.rb +17 -0
- data/lib/chefspec/runner.rb +274 -0
- data/lib/chefspec/stubs/command_registry.rb +11 -0
- data/lib/chefspec/stubs/command_stub.rb +37 -0
- data/lib/chefspec/stubs/data_bag_item_registry.rb +13 -0
- data/lib/chefspec/stubs/data_bag_item_stub.rb +25 -0
- data/lib/chefspec/stubs/data_bag_registry.rb +13 -0
- data/lib/chefspec/stubs/data_bag_stub.rb +23 -0
- data/lib/chefspec/stubs/registry.rb +32 -0
- data/lib/chefspec/stubs/search_registry.rb +13 -0
- data/lib/chefspec/stubs/search_stub.rb +25 -0
- data/lib/chefspec/stubs/stub.rb +37 -0
- data/lib/chefspec/version.rb +1 -2
- metadata +100 -103
- data/lib/chef/expect_exception.rb +0 -34
- data/lib/chef/formatters/chefspec.rb +0 -233
- data/lib/chef/knife/cookbook_create_specs.rb +0 -107
- data/lib/chefspec/chef_runner.rb +0 -275
- data/lib/chefspec/helpers/describe.rb +0 -17
- data/lib/chefspec/matchers/cron.rb +0 -7
- data/lib/chefspec/matchers/env.rb +0 -8
- data/lib/chefspec/matchers/execute.rb +0 -33
- data/lib/chefspec/matchers/file.rb +0 -83
- data/lib/chefspec/matchers/file_content.rb +0 -32
- data/lib/chefspec/matchers/group.rb +0 -8
- data/lib/chefspec/matchers/include_recipe.rb +0 -20
- data/lib/chefspec/matchers/link.rb +0 -14
- data/lib/chefspec/matchers/log.rb +0 -21
- data/lib/chefspec/matchers/notifications.rb +0 -43
- data/lib/chefspec/matchers/package.rb +0 -39
- data/lib/chefspec/matchers/python.rb +0 -7
- data/lib/chefspec/matchers/ruby_block.rb +0 -13
- data/lib/chefspec/matchers/script.rb +0 -34
- data/lib/chefspec/matchers/service.rb +0 -25
- data/lib/chefspec/matchers/shared.rb +0 -132
- data/lib/chefspec/matchers/user.rb +0 -8
- data/lib/chefspec/minitest.rb +0 -195
- data/lib/chefspec/monkey_patches/conditional.rb +0 -19
- data/lib/chefspec/monkey_patches/hash.rb +0 -23
- data/lib/chefspec/monkey_patches/lwrp_base.rb +0 -45
- data/lib/chefspec/monkey_patches/provider.rb +0 -43
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
module ChefSpec::API
|
|
2
|
+
# @since 0.0.1
|
|
3
|
+
module TemplateMatchers
|
|
4
|
+
ChefSpec::Runner.define_runner_method :template
|
|
5
|
+
|
|
6
|
+
#
|
|
7
|
+
# Assert that a +template+ resource exists in the Chef run with the
|
|
8
|
+
# action +:create+. Given a Chef Recipe that creates "/tmp/config" as a
|
|
9
|
+
# +template+:
|
|
10
|
+
#
|
|
11
|
+
# template '/tmp/config' do
|
|
12
|
+
# action :create
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# To test the content rendered by a +template+, see
|
|
16
|
+
# {ChefSpec::API::RenderFileMatchers}.
|
|
17
|
+
#
|
|
18
|
+
# The Examples section demonstrates the different ways to test a
|
|
19
|
+
# +template+ resource with ChefSpec.
|
|
20
|
+
#
|
|
21
|
+
# @example Assert that a +template+ was created
|
|
22
|
+
# expect(chef_run).to create_template('/tmp/config')
|
|
23
|
+
#
|
|
24
|
+
# @example Assert that a +template+ was created with predicate matchers
|
|
25
|
+
# expect(chef_run).to create_template('/tmp/config').with_user('svargo')
|
|
26
|
+
#
|
|
27
|
+
# @example Assert that a +template+ was created with attributes
|
|
28
|
+
# expect(chef_run).to create_template('/tmp/config').with(user: 'svargo')
|
|
29
|
+
#
|
|
30
|
+
# @example Assert that a +template+ was created using a regex
|
|
31
|
+
# expect(chef_run).to create_template('/tmp/config').with(user: /sva(.+)/)
|
|
32
|
+
#
|
|
33
|
+
# @example Assert that a +template+ was _not_ created
|
|
34
|
+
# expect(chef_run).to_not create_template('/tmp/config')
|
|
35
|
+
#
|
|
36
|
+
#
|
|
37
|
+
# @param [String, Regex] resource_name
|
|
38
|
+
# the name of the resource to match
|
|
39
|
+
#
|
|
40
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
41
|
+
#
|
|
42
|
+
def create_template(resource_name)
|
|
43
|
+
ChefSpec::Matchers::ResourceMatcher.new(:template, :create, resource_name)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
#
|
|
47
|
+
# Assert that a +template+ resource exists in the Chef run with the
|
|
48
|
+
# action +:create_if_missing+. Given a Chef Recipe that creates "/tmp/config"
|
|
49
|
+
# if missing as a +template+:
|
|
50
|
+
#
|
|
51
|
+
# template '/tmp/config' do
|
|
52
|
+
# action :create_if_missing
|
|
53
|
+
# end
|
|
54
|
+
#
|
|
55
|
+
# To test the content rendered by a +template+, see
|
|
56
|
+
# {ChefSpec::API::RenderFileMatchers}.
|
|
57
|
+
#
|
|
58
|
+
# The Examples section demonstrates the different ways to test a
|
|
59
|
+
# +template+ resource with ChefSpec.
|
|
60
|
+
#
|
|
61
|
+
# @example Assert that a +template+ was created if missing
|
|
62
|
+
# expect(chef_run).to create_template_if_missing('/tmp/config')
|
|
63
|
+
#
|
|
64
|
+
# @example Assert that a +template+ was created if missing with predicate matchers
|
|
65
|
+
# expect(chef_run).to create_template_if_missing('/tmp/config').with_user('svargo')
|
|
66
|
+
#
|
|
67
|
+
# @example Assert that a +template+ was created if missing with attributes
|
|
68
|
+
# expect(chef_run).to create_template_if_missing('/tmp/config').with(user: 'svargo')
|
|
69
|
+
#
|
|
70
|
+
# @example Assert that a +template+ was created if missing using a regex
|
|
71
|
+
# expect(chef_run).to create_template_if_missing('/tmp/config').with(user: /sva(.+)/)
|
|
72
|
+
#
|
|
73
|
+
# @example Assert that a +template+ was _not_ created if missing
|
|
74
|
+
# expect(chef_run).to_not create_template('/tmp/config')
|
|
75
|
+
#
|
|
76
|
+
#
|
|
77
|
+
# @param [String, Regex] resource_name
|
|
78
|
+
# the name of the resource to match
|
|
79
|
+
#
|
|
80
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
81
|
+
#
|
|
82
|
+
def create_template_if_missing(resource_name)
|
|
83
|
+
ChefSpec::Matchers::ResourceMatcher.new(:template, :create_if_missing, resource_name)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
#
|
|
87
|
+
# Assert that a +template+ resource exists in the Chef run with the
|
|
88
|
+
# action +:delete+. Given a Chef Recipe that deletes "/tmp/config" as a
|
|
89
|
+
# +template+:
|
|
90
|
+
#
|
|
91
|
+
# template '/tmp/config' do
|
|
92
|
+
# action :delete
|
|
93
|
+
# end
|
|
94
|
+
#
|
|
95
|
+
# To test the content rendered by a +template+, see
|
|
96
|
+
# {ChefSpec::API::RenderFileMatchers}.
|
|
97
|
+
#
|
|
98
|
+
# The Examples section demonstrates the different ways to test a
|
|
99
|
+
# +template+ resource with ChefSpec.
|
|
100
|
+
#
|
|
101
|
+
# @example Assert that a +template+ was deleted
|
|
102
|
+
# expect(chef_run).to delete_template('/tmp/config')
|
|
103
|
+
#
|
|
104
|
+
# @example Assert that a +template+ was deleted with predicate matchers
|
|
105
|
+
# expect(chef_run).to delete_template('/tmp/config').with_user('svargo')
|
|
106
|
+
#
|
|
107
|
+
# @example Assert that a +template+ was deleted with attributes
|
|
108
|
+
# expect(chef_run).to delete_template('/tmp/config').with(user: 'svargo')
|
|
109
|
+
#
|
|
110
|
+
# @example Assert that a +template+ was deleted using a regex
|
|
111
|
+
# expect(chef_run).to delete_template('/tmp/config').with(user: /sva(.+)/)
|
|
112
|
+
#
|
|
113
|
+
# @example Assert that a +template+ was _not_ deleted
|
|
114
|
+
# expect(chef_run).to_not delete_template('/tmp/config')
|
|
115
|
+
#
|
|
116
|
+
#
|
|
117
|
+
# @param [String, Regex] resource_name
|
|
118
|
+
# the name of the resource to match
|
|
119
|
+
#
|
|
120
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
121
|
+
#
|
|
122
|
+
def delete_template(resource_name)
|
|
123
|
+
ChefSpec::Matchers::ResourceMatcher.new(:template, :delete, resource_name)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
#
|
|
127
|
+
# Assert that a +template+ resource exists in the Chef run with the
|
|
128
|
+
# action +:touch+. Given a Chef Recipe that touches "/tmp/config" as a
|
|
129
|
+
# +template+:
|
|
130
|
+
#
|
|
131
|
+
# template '/tmp/config' do
|
|
132
|
+
# action :touch
|
|
133
|
+
# end
|
|
134
|
+
#
|
|
135
|
+
# To test the content rendered by a +template+, see
|
|
136
|
+
# {ChefSpec::API::RenderFileMatchers}.
|
|
137
|
+
#
|
|
138
|
+
# The Examples section demonstrates the different ways to test a
|
|
139
|
+
# +template+ resource with ChefSpec.
|
|
140
|
+
#
|
|
141
|
+
# @example Assert that a +template+ was touched
|
|
142
|
+
# expect(chef_run).to touch_template('/tmp/config')
|
|
143
|
+
#
|
|
144
|
+
# @example Assert that a +template+ was touched with predicate matchers
|
|
145
|
+
# expect(chef_run).to touch_template('/tmp/config').with_user('svargo')
|
|
146
|
+
#
|
|
147
|
+
# @example Assert that a +template+ was touched with attributes
|
|
148
|
+
# expect(chef_run).to touch_template('/tmp/config').with(user: 'svargo')
|
|
149
|
+
#
|
|
150
|
+
# @example Assert that a +template+ was touched using a regex
|
|
151
|
+
# expect(chef_run).to touch_template('/tmp/config').with(user: /sva(.+)/)
|
|
152
|
+
#
|
|
153
|
+
# @example Assert that a +template+ was _not_ touched
|
|
154
|
+
# expect(chef_run).to_not touch_template('/tmp/config')
|
|
155
|
+
#
|
|
156
|
+
#
|
|
157
|
+
# @param [String, Regex] resource_name
|
|
158
|
+
# the name of the resource to match
|
|
159
|
+
#
|
|
160
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
161
|
+
#
|
|
162
|
+
def touch_template(resource_name)
|
|
163
|
+
ChefSpec::Matchers::ResourceMatcher.new(:template, :touch, resource_name)
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
module ChefSpec::API
|
|
2
|
+
# @since 0.3.0
|
|
3
|
+
module UserMatchers
|
|
4
|
+
ChefSpec::Runner.define_runner_method :user
|
|
5
|
+
|
|
6
|
+
#
|
|
7
|
+
# Assert that a +user+ resource exists in the Chef run with the
|
|
8
|
+
# action +:create+. Given a Chef Recipe that creates "apache2" as a
|
|
9
|
+
# +user+:
|
|
10
|
+
#
|
|
11
|
+
# user 'apache2' do
|
|
12
|
+
# action :create
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# The Examples section demonstrates the different ways to test a
|
|
16
|
+
# +user+ resource with ChefSpec.
|
|
17
|
+
#
|
|
18
|
+
# @example Assert that a +user+ was createed
|
|
19
|
+
# expect(chef_run).to create_user('apache2')
|
|
20
|
+
#
|
|
21
|
+
# @example Assert that a +user+ was createed with predicate matchers
|
|
22
|
+
# expect(chef_run).to create_user('apache2').with_uid(1234)
|
|
23
|
+
#
|
|
24
|
+
# @example Assert that a +user+ was createed with attributes
|
|
25
|
+
# expect(chef_run).to create_user('apache2').with(uid: 1234)
|
|
26
|
+
#
|
|
27
|
+
# @example Assert that a +user+ was createed using a regex
|
|
28
|
+
# expect(chef_run).to create_user('apache2').with(uid: /\d+/)
|
|
29
|
+
#
|
|
30
|
+
# @example Assert that a +user+ was _not_ createed
|
|
31
|
+
# expect(chef_run).to_not create_user('apache2')
|
|
32
|
+
#
|
|
33
|
+
#
|
|
34
|
+
# @param [String, Regex] resource_name
|
|
35
|
+
# the name of the resource to match
|
|
36
|
+
#
|
|
37
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
38
|
+
#
|
|
39
|
+
def create_user(resource_name)
|
|
40
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user, :create, resource_name)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
#
|
|
44
|
+
# Assert that a +user+ resource exists in the Chef run with the
|
|
45
|
+
# action +:remove+. Given a Chef Recipe that removes "apache2" as a
|
|
46
|
+
# +user+:
|
|
47
|
+
#
|
|
48
|
+
# user 'apache2' do
|
|
49
|
+
# action :remove
|
|
50
|
+
# end
|
|
51
|
+
#
|
|
52
|
+
# The Examples section demonstrates the different ways to test a
|
|
53
|
+
# +user+ resource with ChefSpec.
|
|
54
|
+
#
|
|
55
|
+
# @example Assert that a +user+ was remove
|
|
56
|
+
# expect(chef_run).to remove_user('apache2')
|
|
57
|
+
#
|
|
58
|
+
# @example Assert that a +user+ was remove with predicate matchers
|
|
59
|
+
# expect(chef_run).to remove_user('apache2').with_uid(1234)
|
|
60
|
+
#
|
|
61
|
+
# @example Assert that a +user+ was remove with attributes
|
|
62
|
+
# expect(chef_run).to remove_user('apache2').with(uid: 1234)
|
|
63
|
+
#
|
|
64
|
+
# @example Assert that a +user+ was remove using a regex
|
|
65
|
+
# expect(chef_run).to remove_user('apache2').with(uid: /\d+/)
|
|
66
|
+
#
|
|
67
|
+
# @example Assert that a +user+ was _not_ remove
|
|
68
|
+
# expect(chef_run).to_not remove_user('apache2')
|
|
69
|
+
#
|
|
70
|
+
#
|
|
71
|
+
# @param [String, Regex] resource_name
|
|
72
|
+
# the name of the resource to match
|
|
73
|
+
#
|
|
74
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
75
|
+
#
|
|
76
|
+
def remove_user(resource_name)
|
|
77
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user, :remove, resource_name)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
#
|
|
81
|
+
# Assert that a +user+ resource exists in the Chef run with the
|
|
82
|
+
# action +:modify+. Given a Chef Recipe that modifies "apache2" as a
|
|
83
|
+
# +user+:
|
|
84
|
+
#
|
|
85
|
+
# user 'apache2' do
|
|
86
|
+
# action :modify
|
|
87
|
+
# end
|
|
88
|
+
#
|
|
89
|
+
# The Examples section demonstrates the different ways to test a
|
|
90
|
+
# +user+ resource with ChefSpec.
|
|
91
|
+
#
|
|
92
|
+
# @example Assert that a +user+ was modified
|
|
93
|
+
# expect(chef_run).to modify_user('apache2')
|
|
94
|
+
#
|
|
95
|
+
# @example Assert that a +user+ was modified with predicate matchers
|
|
96
|
+
# expect(chef_run).to modify_user('apache2').with_uid(1234)
|
|
97
|
+
#
|
|
98
|
+
# @example Assert that a +user+ was modified with attributes
|
|
99
|
+
# expect(chef_run).to modify_user('apache2').with(uid: 1234)
|
|
100
|
+
#
|
|
101
|
+
# @example Assert that a +user+ was modified using a regex
|
|
102
|
+
# expect(chef_run).to modify_user('apache2').with(uid: /\d+/)
|
|
103
|
+
#
|
|
104
|
+
# @example Assert that a +user+ was _not_ modified
|
|
105
|
+
# expect(chef_run).to_not modify_user('apache2')
|
|
106
|
+
#
|
|
107
|
+
#
|
|
108
|
+
# @param [String, Regex] resource_name
|
|
109
|
+
# the name of the resource to match
|
|
110
|
+
#
|
|
111
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
112
|
+
#
|
|
113
|
+
def modify_user(resource_name)
|
|
114
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user, :modify, resource_name)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
#
|
|
118
|
+
# Assert that a +user+ resource exists in the Chef run with the
|
|
119
|
+
# action +:manage+. Given a Chef Recipe that manages "apache2" as a
|
|
120
|
+
# +user+:
|
|
121
|
+
#
|
|
122
|
+
# user 'apache2' do
|
|
123
|
+
# action :manage
|
|
124
|
+
# end
|
|
125
|
+
#
|
|
126
|
+
# The Examples section demonstrates the different ways to test a
|
|
127
|
+
# +user+ resource with ChefSpec.
|
|
128
|
+
#
|
|
129
|
+
# @example Assert that a +user+ was managed
|
|
130
|
+
# expect(chef_run).to manage_user('apache2')
|
|
131
|
+
#
|
|
132
|
+
# @example Assert that a +user+ was managed with predicate matchers
|
|
133
|
+
# expect(chef_run).to manage_user('apache2').with_uid(1234)
|
|
134
|
+
#
|
|
135
|
+
# @example Assert that a +user+ was managed with attributes
|
|
136
|
+
# expect(chef_run).to manage_user('apache2').with(uid: 1234)
|
|
137
|
+
#
|
|
138
|
+
# @example Assert that a +user+ was managed using a regex
|
|
139
|
+
# expect(chef_run).to manage_user('apache2').with(uid: /\d+/)
|
|
140
|
+
#
|
|
141
|
+
# @example Assert that a +user+ was _not_ managed
|
|
142
|
+
# expect(chef_run).to_not manage_user('apache2')
|
|
143
|
+
#
|
|
144
|
+
#
|
|
145
|
+
# @param [String, Regex] resource_name
|
|
146
|
+
# the name of the resource to match
|
|
147
|
+
#
|
|
148
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
149
|
+
#
|
|
150
|
+
def manage_user(resource_name)
|
|
151
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user, :manage, resource_name)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
#
|
|
155
|
+
# Assert that a +user+ resource exists in the Chef run with the
|
|
156
|
+
# action +:lock+. Given a Chef Recipe that locks "apache2" as a
|
|
157
|
+
# +user+:
|
|
158
|
+
#
|
|
159
|
+
# user 'apache2' do
|
|
160
|
+
# action :lock
|
|
161
|
+
# end
|
|
162
|
+
#
|
|
163
|
+
# The Examples section demonstrates the different ways to test a
|
|
164
|
+
# +user+ resource with ChefSpec.
|
|
165
|
+
#
|
|
166
|
+
# @example Assert that a +user+ was locked
|
|
167
|
+
# expect(chef_run).to lock_user('apache2')
|
|
168
|
+
#
|
|
169
|
+
# @example Assert that a +user+ was locked with predicate matchers
|
|
170
|
+
# expect(chef_run).to lock_user('apache2').with_uid(1234)
|
|
171
|
+
#
|
|
172
|
+
# @example Assert that a +user+ was locked with attributes
|
|
173
|
+
# expect(chef_run).to lock_user('apache2').with(uid: 1234)
|
|
174
|
+
#
|
|
175
|
+
# @example Assert that a +user+ was locked using a regex
|
|
176
|
+
# expect(chef_run).to lock_user('apache2').with(uid: /\d+/)
|
|
177
|
+
#
|
|
178
|
+
# @example Assert that a +user+ was _not_ locked
|
|
179
|
+
# expect(chef_run).to_not lock_user('apache2')
|
|
180
|
+
#
|
|
181
|
+
#
|
|
182
|
+
# @param [String, Regex] resource_name
|
|
183
|
+
# the name of the resource to match
|
|
184
|
+
#
|
|
185
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
186
|
+
#
|
|
187
|
+
def lock_user(resource_name)
|
|
188
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user, :lock, resource_name)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
#
|
|
192
|
+
# Assert that a +user+ resource exists in the Chef run with the
|
|
193
|
+
# action +:unlock+. Given a Chef Recipe that unlocks "apache2" as a
|
|
194
|
+
# +user+:
|
|
195
|
+
#
|
|
196
|
+
# user 'apache2' do
|
|
197
|
+
# action :unlock
|
|
198
|
+
# end
|
|
199
|
+
#
|
|
200
|
+
# The Examples section demonstrates the different ways to test a
|
|
201
|
+
# +user+ resource with ChefSpec.
|
|
202
|
+
#
|
|
203
|
+
# @example Assert that a +user+ was unlocked
|
|
204
|
+
# expect(chef_run).to unlock_user('apache2')
|
|
205
|
+
#
|
|
206
|
+
# @example Assert that a +user+ was unlocked with predicate matchers
|
|
207
|
+
# expect(chef_run).to unlock_user('apache2').with_uid(1234)
|
|
208
|
+
#
|
|
209
|
+
# @example Assert that a +user+ was unlocked with attributes
|
|
210
|
+
# expect(chef_run).to unlock_user('apache2').with(uid: 1234)
|
|
211
|
+
#
|
|
212
|
+
# @example Assert that a +user+ was unlocked using a regex
|
|
213
|
+
# expect(chef_run).to unlock_user('apache2').with(uid: /\d+/)
|
|
214
|
+
#
|
|
215
|
+
# @example Assert that a +user+ was _not_ unlocked
|
|
216
|
+
# expect(chef_run).to_not unlock_user('apache2')
|
|
217
|
+
#
|
|
218
|
+
#
|
|
219
|
+
# @param [String, Regex] resource_name
|
|
220
|
+
# the name of the resource to match
|
|
221
|
+
#
|
|
222
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
223
|
+
#
|
|
224
|
+
def unlock_user(resource_name)
|
|
225
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user, :unlock, resource_name)
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
module ChefSpec::API
|
|
2
|
+
# @since 3.0.0
|
|
3
|
+
module YumPackageMatchers
|
|
4
|
+
ChefSpec::Runner.define_runner_method :yum_package
|
|
5
|
+
|
|
6
|
+
#
|
|
7
|
+
# Assert that a +yum_package+ resource exists in the Chef run with the
|
|
8
|
+
# action +:install+. Given a Chef Recipe that installs "apache2" as a
|
|
9
|
+
# +yum_package+:
|
|
10
|
+
#
|
|
11
|
+
# yum_package 'apache2' do
|
|
12
|
+
# action :install
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# The Examples section demonstrates the different ways to test a
|
|
16
|
+
# +yum_package+ resource with ChefSpec.
|
|
17
|
+
#
|
|
18
|
+
# @example Assert that a +yum_package+ was installed
|
|
19
|
+
# expect(chef_run).to install_yum_package('apache2')
|
|
20
|
+
#
|
|
21
|
+
# @example Assert that a +yum_package+ was installed with predicate matchers
|
|
22
|
+
# expect(chef_run).to install_yum_package('apache2').with_version('1.2.3')
|
|
23
|
+
#
|
|
24
|
+
# @example Assert that a +yum_package+ was installed with attributes
|
|
25
|
+
# expect(chef_run).to install_yum_package('apache2').with(version: '1.2.3')
|
|
26
|
+
#
|
|
27
|
+
# @example Assert that a +yum_package+ was installed using a regex
|
|
28
|
+
# expect(chef_run).to install_yum_package('apache2').with(version: /(\d+\.){2}\.\d+/)
|
|
29
|
+
#
|
|
30
|
+
# @example Assert that a +yum_package+ was _not_ installed
|
|
31
|
+
# expect(chef_run).to_not install_yum_package('apache2')
|
|
32
|
+
#
|
|
33
|
+
#
|
|
34
|
+
# @param [String, Regex] resource_name
|
|
35
|
+
# the name of the resource to match
|
|
36
|
+
#
|
|
37
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
38
|
+
#
|
|
39
|
+
def install_yum_package(resource_name)
|
|
40
|
+
ChefSpec::Matchers::ResourceMatcher.new(:yum_package, :install, resource_name)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
#
|
|
44
|
+
# Assert that a +yum_package+ resource exists in the Chef run with the
|
|
45
|
+
# action +:purge+. Given a Chef Recipe that purges "apache2" as a
|
|
46
|
+
# +yum_package+:
|
|
47
|
+
#
|
|
48
|
+
# yum_package 'apache2' do
|
|
49
|
+
# action :purge
|
|
50
|
+
# end
|
|
51
|
+
#
|
|
52
|
+
# The Examples section demonstrates the different ways to test a
|
|
53
|
+
# +yum_package+ resource with ChefSpec.
|
|
54
|
+
#
|
|
55
|
+
# @example Assert that a +yum_package+ was purged
|
|
56
|
+
# expect(chef_run).to purge_yum_package('apache2')
|
|
57
|
+
#
|
|
58
|
+
# @example Assert that a +yum_package+ was purged with predicate matchers
|
|
59
|
+
# expect(chef_run).to purge_yum_package('apache2').with_version('1.2.3')
|
|
60
|
+
#
|
|
61
|
+
# @example Assert that a +yum_package+ was purged with attributes
|
|
62
|
+
# expect(chef_run).to purge_yum_package('apache2').with(version: '1.2.3')
|
|
63
|
+
#
|
|
64
|
+
# @example Assert that a +yum_package+ was purged using a regex
|
|
65
|
+
# expect(chef_run).to purge_yum_package('apache2').with(version: /(\d+\.){2}\.\d+/)
|
|
66
|
+
#
|
|
67
|
+
# @example Assert that a +yum_package+ was _not_ purged
|
|
68
|
+
# expect(chef_run).to_not purge_yum_package('apache2')
|
|
69
|
+
#
|
|
70
|
+
#
|
|
71
|
+
# @param [String, Regex] resource_name
|
|
72
|
+
# the name of the resource to match
|
|
73
|
+
#
|
|
74
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
75
|
+
#
|
|
76
|
+
def purge_yum_package(resource_name)
|
|
77
|
+
ChefSpec::Matchers::ResourceMatcher.new(:yum_package, :purge, resource_name)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
#
|
|
81
|
+
# Assert that a +yum_package+ resource exists in the Chef run with the
|
|
82
|
+
# action +:remove+. Given a Chef Recipe that removes "apache2" as a
|
|
83
|
+
# +yum_package+:
|
|
84
|
+
#
|
|
85
|
+
# yum_package 'apache2' do
|
|
86
|
+
# action :remove
|
|
87
|
+
# end
|
|
88
|
+
#
|
|
89
|
+
# The Examples section demonstrates the different ways to test a
|
|
90
|
+
# +yum_package+ resource with ChefSpec.
|
|
91
|
+
#
|
|
92
|
+
# @example Assert that a +yum_package+ was removed
|
|
93
|
+
# expect(chef_run).to remove_yum_package('apache2')
|
|
94
|
+
#
|
|
95
|
+
# @example Assert that a +yum_package+ was removed with predicate matchers
|
|
96
|
+
# expect(chef_run).to remove_yum_package('apache2').with_version('1.2.3')
|
|
97
|
+
#
|
|
98
|
+
# @example Assert that a +yum_package+ was removed with attributes
|
|
99
|
+
# expect(chef_run).to remove_yum_package('apache2').with(version: '1.2.3')
|
|
100
|
+
#
|
|
101
|
+
# @example Assert that a +yum_package+ was removed using a regex
|
|
102
|
+
# expect(chef_run).to remove_yum_package('apache2').with(version: /(\d+\.){2}\.\d+/)
|
|
103
|
+
#
|
|
104
|
+
# @example Assert that a +yum_package+ was _not_ removed
|
|
105
|
+
# expect(chef_run).to_not remove_yum_package('apache2')
|
|
106
|
+
#
|
|
107
|
+
#
|
|
108
|
+
# @param [String, Regex] resource_name
|
|
109
|
+
# the name of the resource to match
|
|
110
|
+
#
|
|
111
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
112
|
+
#
|
|
113
|
+
def remove_yum_package(resource_name)
|
|
114
|
+
ChefSpec::Matchers::ResourceMatcher.new(:yum_package, :remove, resource_name)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
#
|
|
118
|
+
# Assert that a +yum_package+ resource exists in the Chef run with the
|
|
119
|
+
# action +:upgrade+. Given a Chef Recipe that upgrades "apache2" as a
|
|
120
|
+
# +yum_package+:
|
|
121
|
+
#
|
|
122
|
+
# yum_package 'apache2' do
|
|
123
|
+
# action :upgrade
|
|
124
|
+
# end
|
|
125
|
+
#
|
|
126
|
+
# The Examples section demonstrates the different ways to test a
|
|
127
|
+
# +yum_package+ resource with ChefSpec.
|
|
128
|
+
#
|
|
129
|
+
# @example Assert that a +yum_package+ was upgraded
|
|
130
|
+
# expect(chef_run).to upgrade_yum_package('apache2')
|
|
131
|
+
#
|
|
132
|
+
# @example Assert that a +yum_package+ was upgraded with predicate matchers
|
|
133
|
+
# expect(chef_run).to upgrade_yum_package('apache2').with_version('1.2.3')
|
|
134
|
+
#
|
|
135
|
+
# @example Assert that a +yum_package+ was upgraded with attributes
|
|
136
|
+
# expect(chef_run).to upgrade_yum_package('apache2').with(version: '1.2.3')
|
|
137
|
+
#
|
|
138
|
+
# @example Assert that a +yum_package+ was upgraded using a regex
|
|
139
|
+
# expect(chef_run).to upgrade_yum_package('apache2').with(version: /(\d+\.){2}\.\d+/)
|
|
140
|
+
#
|
|
141
|
+
# @example Assert that a +yum_package+ was _not_ upgraded
|
|
142
|
+
# expect(chef_run).to_not upgrade_yum_package('apache2')
|
|
143
|
+
#
|
|
144
|
+
#
|
|
145
|
+
# @param [String, Regex] resource_name
|
|
146
|
+
# the name of the resource to match
|
|
147
|
+
#
|
|
148
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
|
149
|
+
#
|
|
150
|
+
def upgrade_yum_package(resource_name)
|
|
151
|
+
ChefSpec::Matchers::ResourceMatcher.new(:yum_package, :upgrade, resource_name)
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|