wright 0.4.4 → 0.5.0
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/CONTRIBUTING.md +10 -3
- data/NEWS.md +8 -0
- data/README.md +9 -16
- data/lib/wright/cli.rb +25 -24
- data/lib/wright/config.rb +5 -3
- data/lib/wright/dsl.rb +52 -9
- data/lib/wright/logger.rb +1 -1
- data/lib/wright/provider.rb +8 -5
- data/lib/wright/provider/directory.rb +2 -2
- data/lib/wright/provider/file.rb +4 -4
- data/lib/wright/provider/group.rb +4 -4
- data/lib/wright/provider/package.rb +3 -3
- data/lib/wright/provider/package/apt.rb +1 -1
- data/lib/wright/provider/package/yum.rb +1 -1
- data/lib/wright/provider/symlink.rb +2 -2
- data/lib/wright/provider/user.rb +8 -8
- data/lib/wright/resource.rb +21 -19
- data/lib/wright/resource/directory.rb +21 -10
- data/lib/wright/resource/file.rb +25 -14
- data/lib/wright/resource/group.rb +16 -9
- data/lib/wright/resource/package.rb +14 -9
- data/lib/wright/resource/symlink.rb +10 -8
- data/lib/wright/resource/user.rb +30 -9
- data/lib/wright/util.rb +14 -2
- data/lib/wright/util/erb_renderer.rb +29 -0
- data/lib/wright/util/file.rb +1 -1
- data/lib/wright/util/file_owner.rb +8 -3
- data/lib/wright/util/file_permissions.rb +14 -12
- data/lib/wright/util/file_renderer.rb +50 -0
- data/lib/wright/util/mustache_renderer.rb +41 -0
- data/lib/wright/util/pencil_mustache.rb +58 -0
- data/lib/wright/version.rb +1 -1
- data/man/wright.1 +10 -11
- data/spec/dsl_spec.rb +72 -7
- data/spec/provider/package/apt/{apt-get_--purge_remove_-qy_abcde.return → apt-get_-qy_--purge_remove_abcde.return} +0 -0
- data/spec/provider/package/apt/{apt-get_--purge_remove_-qy_abcde.stderr → apt-get_-qy_--purge_remove_abcde.stderr} +0 -0
- data/spec/provider/package/apt/{apt-get_--purge_remove_-qy_abcde.stdout → apt-get_-qy_--purge_remove_abcde.stdout} +0 -0
- data/spec/provider/package/apt/{apt-get_install_-qy_abcde=2.5.4-1.return → apt-get_-qy_install_abcde=2.5.4-1.return} +0 -0
- data/spec/provider/package/apt/{apt-get_install_-qy_abcde=2.5.4-1.stderr → apt-get_-qy_install_abcde=2.5.4-1.stderr} +0 -0
- data/spec/provider/package/apt/{apt-get_install_-qy_abcde=2.5.4-1.stdout → apt-get_-qy_install_abcde=2.5.4-1.stdout} +0 -0
- data/spec/provider/package/apt/{apt-get_install_-qy_htop.return → apt-get_-qy_install_htop.return} +0 -0
- data/spec/provider/package/apt/{apt-get_install_-qy_htop.stderr → apt-get_-qy_install_htop.stderr} +0 -0
- data/spec/provider/package/apt/{apt-get_install_-qy_htop.stdout → apt-get_-qy_install_htop.stdout} +0 -0
- data/spec/provider/package/apt/{apt-get_install_-qy_not-a-real-package.return → apt-get_-qy_install_not-a-real-package.return} +0 -0
- data/spec/provider/package/apt/{apt-get_install_-qy_not-a-real-package.stderr → apt-get_-qy_install_not-a-real-package.stderr} +0 -0
- data/spec/provider/package/apt/{apt-get_install_-qy_not-a-real-package.stdout → apt-get_-qy_install_not-a-real-package.stdout} +0 -0
- data/spec/provider/package/apt/{apt-get_remove_-qy_abcde.return → apt-get_-qy_remove_abcde.return} +0 -0
- data/spec/provider/package/apt/{apt-get_remove_-qy_abcde.stderr → apt-get_-qy_remove_abcde.stderr} +0 -0
- data/spec/provider/package/apt/{apt-get_remove_-qy_abcde.stdout → apt-get_-qy_remove_abcde.stdout} +0 -0
- data/spec/provider/package/apt_spec.rb +2 -2
- data/spec/provider/package/yum/{yum_install_-y_mc-4.8.7-8.el7.return → yum_-y_install_mc-4.8.7-8.el7.return} +0 -0
- data/spec/provider/package/yum/{yum_install_-y_mc-4.8.7-8.el7.stderr → yum_-y_install_mc-4.8.7-8.el7.stderr} +0 -0
- data/spec/provider/package/yum/{yum_install_-y_mc-4.8.7-8.el7.stdout → yum_-y_install_mc-4.8.7-8.el7.stdout} +0 -0
- data/spec/provider/package/yum/{yum_install_-y_nano.return → yum_-y_install_nano.return} +0 -0
- data/spec/provider/package/yum/{yum_install_-y_nano.stderr → yum_-y_install_nano.stderr} +0 -0
- data/spec/provider/package/yum/{yum_install_-y_nano.stdout → yum_-y_install_nano.stdout} +0 -0
- data/spec/provider/package/yum/{yum_install_-y_not-a-real-package.return → yum_-y_install_not-a-real-package.return} +0 -0
- data/spec/provider/package/yum/{yum_install_-y_not-a-real-package.stderr → yum_-y_install_not-a-real-package.stderr} +0 -0
- data/spec/provider/package/yum/{yum_install_-y_not-a-real-package.stdout → yum_-y_install_not-a-real-package.stdout} +0 -0
- data/spec/provider/package/yum/{yum_remove_-y_screen.return → yum_-y_remove_screen.return} +0 -0
- data/spec/provider/package/yum/{yum_remove_-y_screen.stderr → yum_-y_remove_screen.stderr} +0 -0
- data/spec/provider/package/yum/{yum_remove_-y_screen.stdout → yum_-y_remove_screen.stdout} +0 -0
- data/spec/provider/package/yum_spec.rb +1 -1
- data/spec/resource/directory_spec.rb +15 -0
- data/spec/resource/file_spec.rb +17 -0
- data/spec/resource/group_spec.rb +15 -0
- data/spec/resource/package_spec.rb +13 -0
- data/spec/resource/symlink_spec.rb +11 -0
- data/spec/resource/user_spec.rb +32 -0
- data/spec/resource_spec.rb +18 -10
- data/spec/spec_helper.rb +1 -0
- data/spec/spec_helpers/fake_capture3.rb +1 -1
- data/spec/util/erb_renderer_spec.rb +23 -0
- data/spec/util/file_owner_spec.rb +19 -0
- data/spec/util/file_renderer_spec.rb +28 -0
- data/spec/util/mustache_renderer_spec.rb +57 -0
- data/spec/util/pencil_mustache_spec.rb +15 -0
- data/spec/util_spec.rb +17 -3
- metadata +90 -64
data/lib/wright/version.rb
CHANGED
data/man/wright.1
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
.\" Title: wright
|
|
3
3
|
.\" Author: [see the "AUTHOR" section]
|
|
4
4
|
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
|
|
5
|
-
.\" Date:
|
|
5
|
+
.\" Date: 09/20/2015
|
|
6
6
|
.\" Manual: \ \&
|
|
7
7
|
.\" Source: \ \&
|
|
8
8
|
.\" Language: English
|
|
9
9
|
.\"
|
|
10
|
-
.TH "WRIGHT" "1" "
|
|
10
|
+
.TH "WRIGHT" "1" "09/20/2015" "\ \&" "\ \&"
|
|
11
11
|
.\" -----------------------------------------------------------------
|
|
12
12
|
.\" * Define some portability stuff
|
|
13
13
|
.\" -----------------------------------------------------------------
|
|
@@ -94,7 +94,7 @@ Create a system user named "foobard":
|
|
|
94
94
|
.RS 4
|
|
95
95
|
.\}
|
|
96
96
|
.nf
|
|
97
|
-
wright \-e \*(Aquser
|
|
97
|
+
wright \-e \*(Aquser "foobard", system: true\*(Aq
|
|
98
98
|
.fi
|
|
99
99
|
.if n \{\
|
|
100
100
|
.RE
|
|
@@ -106,7 +106,7 @@ Create a system group named "foobard":
|
|
|
106
106
|
.RS 4
|
|
107
107
|
.\}
|
|
108
108
|
.nf
|
|
109
|
-
wright \-e \*(Aqgroup
|
|
109
|
+
wright \-e \*(Aqgroup "foobard", system: true\*(Aq
|
|
110
110
|
.fi
|
|
111
111
|
.if n \{\
|
|
112
112
|
.RE
|
|
@@ -118,7 +118,7 @@ Create a file named \fI/etc/issue\fR containing the current wright version:
|
|
|
118
118
|
.RS 4
|
|
119
119
|
.\}
|
|
120
120
|
.nf
|
|
121
|
-
wright \-e \*(Aqfile
|
|
121
|
+
wright \-e \*(Aqfile "/etc/issue", content: Wright::VERSION\*(Aq
|
|
122
122
|
.fi
|
|
123
123
|
.if n \{\
|
|
124
124
|
.RE
|
|
@@ -142,7 +142,7 @@ Create a symlink from \fI\&.bash_profile\fR to \fI\&.profile\fR in the current u
|
|
|
142
142
|
.RS 4
|
|
143
143
|
.\}
|
|
144
144
|
.nf
|
|
145
|
-
wright \-e \*(Aqsymlink
|
|
145
|
+
wright \-e \*(Aqsymlink "~/\&.bash_profile", to: "~/\&.profile"\*(Aq
|
|
146
146
|
.fi
|
|
147
147
|
.if n \{\
|
|
148
148
|
.RE
|
|
@@ -156,15 +156,14 @@ To install tmux and update its config file from a wright script, create the foll
|
|
|
156
156
|
.nf
|
|
157
157
|
package \*(Aqtmux\*(Aq
|
|
158
158
|
|
|
159
|
-
file \*(Aq/etc/tmux\&.conf\*(Aq
|
|
160
|
-
|
|
159
|
+
file \*(Aq/etc/tmux\&.conf\*(Aq,
|
|
160
|
+
mode: \*(Aq444\*(Aq,
|
|
161
|
+
on_update: \-> { puts \*(AqUpdated /etc/tmux\&.conf\*(Aq },
|
|
162
|
+
content: <<EOF
|
|
161
163
|
unbind C\-b
|
|
162
164
|
set \-g prefix C\-a
|
|
163
165
|
bind\-key a send\-prefix
|
|
164
166
|
EOF
|
|
165
|
-
f\&.mode = \*(Aq444\*(Aq
|
|
166
|
-
f\&.on_update = \-> { puts \*(AqUpdated /etc/tmux\&.conf\*(Aq }
|
|
167
|
-
end
|
|
168
167
|
.fi
|
|
169
168
|
.if n \{\
|
|
170
169
|
.RE
|
data/spec/dsl_spec.rb
CHANGED
|
@@ -6,9 +6,8 @@ describe Wright::DSL do
|
|
|
6
6
|
before(:each) do
|
|
7
7
|
# duplicate Wright::DSL for testing
|
|
8
8
|
dsl = Wright::DSL.dup
|
|
9
|
-
@recipe =
|
|
10
|
-
|
|
11
|
-
end
|
|
9
|
+
@recipe = Object.new
|
|
10
|
+
@recipe.extend(dsl)
|
|
12
11
|
@wright_dsl = dsl
|
|
13
12
|
end
|
|
14
13
|
|
|
@@ -17,7 +16,8 @@ describe Wright::DSL do
|
|
|
17
16
|
def self.name
|
|
18
17
|
'ResourceKlass'
|
|
19
18
|
end
|
|
20
|
-
|
|
19
|
+
|
|
20
|
+
def initialize(_name, _args); end
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
@wright_dsl.register_resource(resource_class)
|
|
@@ -26,8 +26,10 @@ describe Wright::DSL do
|
|
|
26
26
|
resource_name = 'just a name'
|
|
27
27
|
@recipe.must_respond_to(resource_method_name)
|
|
28
28
|
|
|
29
|
+
# Ruby 1.9: "0 for 1", Ruby 2: "0 for 1..2"
|
|
30
|
+
error_message_re = /\Awrong number of arguments \(0 for 1(..2)?\)\Z/
|
|
29
31
|
e = -> { @recipe.send(resource_method_name) }.must_raise ArgumentError
|
|
30
|
-
e.message.
|
|
32
|
+
e.message.must_match error_message_re
|
|
31
33
|
|
|
32
34
|
resource = @recipe.send(resource_method_name, resource_name)
|
|
33
35
|
resource.must_be_instance_of(resource_class)
|
|
@@ -39,7 +41,7 @@ describe Wright::DSL do
|
|
|
39
41
|
'Hello'
|
|
40
42
|
end
|
|
41
43
|
|
|
42
|
-
def initialize(name)
|
|
44
|
+
def initialize(name, _args = {})
|
|
43
45
|
@name = name
|
|
44
46
|
end
|
|
45
47
|
|
|
@@ -58,7 +60,7 @@ describe Wright::DSL do
|
|
|
58
60
|
'ResourceKlass'
|
|
59
61
|
end
|
|
60
62
|
|
|
61
|
-
def initialize(_name); end
|
|
63
|
+
def initialize(_name, _args = {}); end
|
|
62
64
|
end
|
|
63
65
|
@wright_dsl.register_resource(resource_class)
|
|
64
66
|
|
|
@@ -67,4 +69,67 @@ describe Wright::DSL do
|
|
|
67
69
|
|
|
68
70
|
-> { @recipe.send(resource_name, nil, &block) }.must_throw resource_class
|
|
69
71
|
end
|
|
72
|
+
|
|
73
|
+
describe '#util' do
|
|
74
|
+
it 'should return a Wright::DSL::Util object' do
|
|
75
|
+
@recipe.util.must_be_instance_of Wright::DSL::Util
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe Wright::DSL::Util do
|
|
81
|
+
before(:each) { @util = Wright::DSL::Util.new }
|
|
82
|
+
|
|
83
|
+
describe '#render_erb' do
|
|
84
|
+
it 'should delegate rendering ERB templates to ErbRenderer' do
|
|
85
|
+
erb_renderer_class_double = Minitest::Mock.new
|
|
86
|
+
erb_renderer_object_double = Minitest::Mock.new
|
|
87
|
+
erb_renderer_class_double.expect(:new,
|
|
88
|
+
erb_renderer_object_double,
|
|
89
|
+
[:hash])
|
|
90
|
+
erb_renderer_object_double.expect(:render, nil, [:template])
|
|
91
|
+
|
|
92
|
+
Wright::Util.stub_const(:ErbRenderer,
|
|
93
|
+
erb_renderer_class_double) do
|
|
94
|
+
@util.render_erb(:template, :hash)
|
|
95
|
+
end
|
|
96
|
+
erb_renderer_class_double.verify
|
|
97
|
+
erb_renderer_object_double.verify
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe '#render_mustache' do
|
|
102
|
+
it 'should delegate rendering mustache templates to MustacheRenderer' do
|
|
103
|
+
mustache_renderer_class_double = Minitest::Mock.new
|
|
104
|
+
mustache_renderer_object_double = Minitest::Mock.new
|
|
105
|
+
mustache_renderer_class_double.expect(:new,
|
|
106
|
+
mustache_renderer_object_double,
|
|
107
|
+
[:hash])
|
|
108
|
+
mustache_renderer_object_double.expect(:render, nil, [:template])
|
|
109
|
+
|
|
110
|
+
Wright::Util.stub_const(:MustacheRenderer,
|
|
111
|
+
mustache_renderer_class_double) do
|
|
112
|
+
@util.render_mustache(:template, :hash)
|
|
113
|
+
end
|
|
114
|
+
mustache_renderer_class_double.verify
|
|
115
|
+
mustache_renderer_object_double.verify
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe '#render_file' do
|
|
120
|
+
it 'should delegate rendering files templates to FileRenderer' do
|
|
121
|
+
file_renderer_class_double = Minitest::Mock.new
|
|
122
|
+
file_renderer_object_double = Minitest::Mock.new
|
|
123
|
+
file_renderer_class_double.expect(:new,
|
|
124
|
+
file_renderer_object_double,
|
|
125
|
+
[:hash])
|
|
126
|
+
file_renderer_object_double.expect(:render, nil, [:filename])
|
|
127
|
+
|
|
128
|
+
Wright::Util.stub_const(:FileRenderer, file_renderer_class_double) do
|
|
129
|
+
@util.render_file(:filename, :hash)
|
|
130
|
+
end
|
|
131
|
+
file_renderer_class_double.verify
|
|
132
|
+
file_renderer_object_double.verify
|
|
133
|
+
end
|
|
134
|
+
end
|
|
70
135
|
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/spec/provider/package/apt/{apt-get_install_-qy_htop.return → apt-get_-qy_install_htop.return}
RENAMED
|
File without changes
|
data/spec/provider/package/apt/{apt-get_install_-qy_htop.stderr → apt-get_-qy_install_htop.stderr}
RENAMED
|
File without changes
|
data/spec/provider/package/apt/{apt-get_install_-qy_htop.stdout → apt-get_-qy_install_htop.stdout}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/spec/provider/package/apt/{apt-get_remove_-qy_abcde.return → apt-get_-qy_remove_abcde.return}
RENAMED
|
File without changes
|
data/spec/provider/package/apt/{apt-get_remove_-qy_abcde.stderr → apt-get_-qy_remove_abcde.stderr}
RENAMED
|
File without changes
|
data/spec/provider/package/apt/{apt-get_remove_-qy_abcde.stdout → apt-get_-qy_remove_abcde.stdout}
RENAMED
|
File without changes
|
|
@@ -10,7 +10,7 @@ describe Wright::Provider::Package::Apt do
|
|
|
10
10
|
def apt_get(action, pkg_name, args = {})
|
|
11
11
|
version = args[:version].nil? ? '' : "=#{args[:version]}"
|
|
12
12
|
options = args[:options]
|
|
13
|
-
['apt-get', *options, action.to_s,
|
|
13
|
+
['apt-get', '-qy', *options, action.to_s, pkg_name + version]
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def package_provider(pkg_name, args = {})
|
|
@@ -135,7 +135,7 @@ describe Wright::Provider::Package::Apt do
|
|
|
135
135
|
pkg_provider = package_provider(pkg_name, options: pkg_options)
|
|
136
136
|
apt_cmd = apt_get(:install, pkg_name, options: pkg_options)
|
|
137
137
|
|
|
138
|
-
@fake_capture3.expect(apt_cmd, 'apt-
|
|
138
|
+
@fake_capture3.expect(apt_cmd, 'apt-get_-qy_install_htop')
|
|
139
139
|
@fake_capture3.stub do
|
|
140
140
|
pkg_provider.send(:install_package)
|
|
141
141
|
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -18,7 +18,7 @@ describe Wright::Provider::Package::Yum do
|
|
|
18
18
|
|
|
19
19
|
def yum(action, pkg_name, args = {})
|
|
20
20
|
version = args[:version].nil? ? '' : "-#{args[:version]}"
|
|
21
|
-
['yum', *args[:options], action.to_s,
|
|
21
|
+
['yum', '-y', *args[:options], action.to_s, pkg_name + version]
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
before :each do
|
|
@@ -9,6 +9,21 @@ describe Wright::Resource::Directory do
|
|
|
9
9
|
|
|
10
10
|
after(:each) { FakeFS::FileSystem.clear }
|
|
11
11
|
|
|
12
|
+
describe '#initialize' do
|
|
13
|
+
it 'should accept attributes via an argument hash' do
|
|
14
|
+
resource = Wright::Resource::Directory.new(@dirname,
|
|
15
|
+
mode: 'sample_mode',
|
|
16
|
+
action: 'sample_action',
|
|
17
|
+
owner: 'sample_owner',
|
|
18
|
+
group: 'sample_group')
|
|
19
|
+
resource.name.must_equal @dirname
|
|
20
|
+
resource.mode.must_equal 'sample_mode'
|
|
21
|
+
resource.action.must_equal 'sample_action'
|
|
22
|
+
resource.owner.must_equal 'sample_owner'
|
|
23
|
+
resource.group.must_equal 'sample_group'
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
12
27
|
describe '#create' do
|
|
13
28
|
it 'should create directories' do
|
|
14
29
|
FakeFS do
|
data/spec/resource/file_spec.rb
CHANGED
|
@@ -12,6 +12,23 @@ describe Wright::Resource::File do
|
|
|
12
12
|
|
|
13
13
|
after(:each) { FakeFS::FileSystem.clear }
|
|
14
14
|
|
|
15
|
+
describe '#initialize' do
|
|
16
|
+
it 'should accept attributes via an argument hash' do
|
|
17
|
+
resource = Wright::Resource::File.new(@filename,
|
|
18
|
+
content: 'sample_content',
|
|
19
|
+
mode: 'sample_mode',
|
|
20
|
+
action: 'sample_action',
|
|
21
|
+
owner: 'sample_owner',
|
|
22
|
+
group: 'sample_group')
|
|
23
|
+
resource.name.must_equal @filename
|
|
24
|
+
resource.content.must_equal 'sample_content'
|
|
25
|
+
resource.mode.must_equal 'sample_mode'
|
|
26
|
+
resource.action.must_equal 'sample_action'
|
|
27
|
+
resource.owner.must_equal 'sample_owner'
|
|
28
|
+
resource.group.must_equal 'sample_group'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
15
32
|
describe '#create' do
|
|
16
33
|
it 'should create files' do
|
|
17
34
|
FakeFS do
|
data/spec/resource/group_spec.rb
CHANGED
|
@@ -9,6 +9,21 @@ describe Wright::Resource::Group do
|
|
|
9
9
|
@group.instance_variable_set(:@provider, @provider)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
describe '#initialize' do
|
|
13
|
+
it 'should accept attributes via an argument hash' do
|
|
14
|
+
resource = Wright::Resource::Group.new('sample_name',
|
|
15
|
+
members: 'sample_members',
|
|
16
|
+
gid: 'sample_gid',
|
|
17
|
+
system: 'sample_system',
|
|
18
|
+
action: 'sample_action')
|
|
19
|
+
resource.name.must_equal 'sample_name'
|
|
20
|
+
resource.members.must_equal 'sample_members'
|
|
21
|
+
resource.gid.must_equal 'sample_gid'
|
|
22
|
+
resource.system.must_equal 'sample_system'
|
|
23
|
+
resource.action.must_equal 'sample_action'
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
12
27
|
describe '#create' do
|
|
13
28
|
it 'should ask the provider to create the group' do
|
|
14
29
|
@provider.expect(:create, nil)
|
|
@@ -9,6 +9,19 @@ describe Wright::Resource::Package do
|
|
|
9
9
|
@package.instance_variable_set(:@provider, @provider)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
describe '#initialize' do
|
|
13
|
+
it 'should accept attributes via an argument hash' do
|
|
14
|
+
resource = Wright::Resource::Package.new('sample_name',
|
|
15
|
+
version: 'sample_version',
|
|
16
|
+
options: 'sample_options',
|
|
17
|
+
action: 'sample_action')
|
|
18
|
+
resource.name.must_equal 'sample_name'
|
|
19
|
+
resource.version.must_equal 'sample_version'
|
|
20
|
+
resource.options.must_equal 'sample_options'
|
|
21
|
+
resource.action.must_equal 'sample_action'
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
12
25
|
describe '#installed_versions' do
|
|
13
26
|
it 'should ask the provider for installed versions' do
|
|
14
27
|
@provider.expect(:installed_versions, nil)
|
|
@@ -18,6 +18,17 @@ describe Wright::Resource::Symlink do
|
|
|
18
18
|
link
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
describe '#initialize' do
|
|
22
|
+
it 'should accept attributes via an argument hash' do
|
|
23
|
+
resource = Wright::Resource::Symlink.new(@link_name,
|
|
24
|
+
to: 'sample_to',
|
|
25
|
+
action: 'sample_action')
|
|
26
|
+
resource.name.must_equal @link_name
|
|
27
|
+
resource.to.must_equal 'sample_to'
|
|
28
|
+
resource.action.must_equal 'sample_action'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
21
32
|
describe '#create' do
|
|
22
33
|
it 'should create symlinks' do
|
|
23
34
|
FakeFS do
|
data/spec/resource/user_spec.rb
CHANGED
|
@@ -9,6 +9,38 @@ describe Wright::Resource::User do
|
|
|
9
9
|
@user.instance_variable_set(:@provider, @provider)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
describe '#initialize' do
|
|
13
|
+
it 'should accept attributes via an argument hash' do
|
|
14
|
+
resource = Wright::Resource::User.new('sample_name',
|
|
15
|
+
uid: 'sample_uid',
|
|
16
|
+
full_name: 'sample_full_name',
|
|
17
|
+
groups: 'sample_groups',
|
|
18
|
+
shell: 'sample_shell',
|
|
19
|
+
home: 'sample_home',
|
|
20
|
+
primary_group: 'sample_pgroup',
|
|
21
|
+
system: 'sample_system',
|
|
22
|
+
action: 'sample_action')
|
|
23
|
+
resource.name.must_equal 'sample_name'
|
|
24
|
+
resource.uid.must_equal 'sample_uid'
|
|
25
|
+
resource.full_name.must_equal 'sample_full_name'
|
|
26
|
+
resource.groups.must_equal 'sample_groups'
|
|
27
|
+
resource.shell.must_equal 'sample_shell'
|
|
28
|
+
resource.home.must_equal 'sample_home'
|
|
29
|
+
resource.primary_group.must_equal 'sample_pgroup'
|
|
30
|
+
resource.system.must_equal 'sample_system'
|
|
31
|
+
resource.action.must_equal 'sample_action'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'should accept aliased attributes via an argument hash' do
|
|
35
|
+
resource = Wright::Resource::User.new('sample_name',
|
|
36
|
+
login_group: 'sample_login_group',
|
|
37
|
+
homedir: 'sample_homedir')
|
|
38
|
+
resource.name.must_equal 'sample_name'
|
|
39
|
+
resource.login_group.must_equal 'sample_login_group'
|
|
40
|
+
resource.homedir.must_equal 'sample_homedir'
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
12
44
|
describe '#create' do
|
|
13
45
|
it 'should ask the provider to create the user' do
|
|
14
46
|
@provider.expect(:create, nil)
|
data/spec/resource_spec.rb
CHANGED
|
@@ -3,13 +3,6 @@ require_relative 'spec_helper'
|
|
|
3
3
|
require 'wright/resource'
|
|
4
4
|
require 'wright/provider'
|
|
5
5
|
|
|
6
|
-
module Wright
|
|
7
|
-
# add provider attribute reader for tests
|
|
8
|
-
class Resource
|
|
9
|
-
attr_reader :provider
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
6
|
module Wright
|
|
14
7
|
class Provider
|
|
15
8
|
class Sample < Wright::Provider; end
|
|
@@ -56,20 +49,23 @@ describe Wright::Resource do
|
|
|
56
49
|
|
|
57
50
|
it 'should retrieve a provider for a resource' do
|
|
58
51
|
provider_class = Wright::Provider::Sample
|
|
59
|
-
Sample.new.provider
|
|
52
|
+
provider = Sample.new.send(:provider)
|
|
53
|
+
provider.must_be_kind_of provider_class
|
|
60
54
|
end
|
|
61
55
|
|
|
62
56
|
it 'should retrieve a provider for a resource listed in the config' do
|
|
63
57
|
# instantiating the Sample resource without any config should
|
|
64
58
|
# yield the Sample provider
|
|
65
59
|
provider_class = Wright::Provider::Sample
|
|
66
|
-
Sample.new.provider
|
|
60
|
+
provider = Sample.new.send(:provider)
|
|
61
|
+
provider.must_be_kind_of provider_class
|
|
67
62
|
|
|
68
63
|
# when the provider for Sample resources is set to
|
|
69
64
|
# AlternateSample, AlternateSample should be instantiated
|
|
70
65
|
alternate = Wright::Provider::AlternateSample
|
|
71
66
|
Wright::Config[:resources] = { sample: { provider: alternate.name } }
|
|
72
|
-
Sample.new.provider
|
|
67
|
+
alternate_provider = Sample.new.send(:provider)
|
|
68
|
+
alternate_provider.must_be_kind_of alternate
|
|
73
69
|
end
|
|
74
70
|
|
|
75
71
|
it 'should display warnings for nonexistent providers' do
|
|
@@ -189,4 +185,16 @@ describe Wright::Resource do
|
|
|
189
185
|
resource.fail_train
|
|
190
186
|
end.must_raise(RuntimeError)
|
|
191
187
|
end
|
|
188
|
+
|
|
189
|
+
it 'should accept attributes via an argument hash' do
|
|
190
|
+
sample_lambda = -> {}
|
|
191
|
+
sample = Sample.new('sample_name',
|
|
192
|
+
action: 'sample_action',
|
|
193
|
+
on_update: sample_lambda,
|
|
194
|
+
ignore_failure: 'sample_ignore_failure')
|
|
195
|
+
sample.name.must_equal 'sample_name'
|
|
196
|
+
sample.action.must_equal 'sample_action'
|
|
197
|
+
sample.send(:on_update).must_equal sample_lambda
|
|
198
|
+
sample.ignore_failure.must_equal 'sample_ignore_failure'
|
|
199
|
+
end
|
|
192
200
|
end
|