wright 0.0.1 → 0.1.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 +7 -0
- data/LICENSE +2 -2
- data/NEWS +8 -0
- data/README.md +70 -0
- data/Rakefile +19 -0
- data/lib/wright/config.rb +64 -0
- data/lib/wright/dry_run.rb +33 -0
- data/lib/wright/dsl.rb +63 -0
- data/lib/wright/logger.rb +73 -0
- data/lib/wright/provider/directory.rb +78 -0
- data/lib/wright/provider/file.rb +104 -0
- data/lib/wright/provider/package/apt.rb +93 -0
- data/lib/wright/provider/package.rb +38 -0
- data/lib/wright/provider/symlink.rb +86 -0
- data/lib/wright/provider.rb +30 -0
- data/lib/wright/resource/directory.rb +67 -0
- data/lib/wright/resource/file.rb +67 -0
- data/lib/wright/resource/package.rb +70 -0
- data/lib/wright/resource/symlink.rb +47 -0
- data/lib/wright/resource.rb +157 -0
- data/lib/wright/util/color.rb +51 -0
- data/lib/wright/util/file.rb +258 -0
- data/lib/wright/util/file_permissions.rb +129 -0
- data/lib/wright/util/recursive_autoloader.rb +91 -0
- data/lib/wright/util/stolen_from_activesupport.rb +202 -0
- data/lib/wright/util/user.rb +75 -0
- data/lib/wright/util.rb +72 -0
- data/lib/wright/version.rb +3 -2
- data/lib/wright.rb +10 -1
- data/spec/config_spec.rb +37 -0
- data/spec/dsl_spec.rb +65 -0
- data/spec/logger_spec.rb +65 -0
- data/spec/provider/directory_spec.rb +114 -0
- data/spec/provider/file_spec.rb +130 -0
- data/spec/provider/package/apt/apt-get_install_-qy_abcde=2.5.4-1.return +1 -0
- data/spec/provider/package/apt/apt-get_install_-qy_abcde=2.5.4-1.stderr +0 -0
- data/spec/provider/package/apt/apt-get_install_-qy_abcde=2.5.4-1.stdout +15 -0
- data/spec/provider/package/apt/apt-get_install_-qy_htop.return +1 -0
- data/spec/provider/package/apt/apt-get_install_-qy_htop.stderr +0 -0
- data/spec/provider/package/apt/apt-get_install_-qy_htop.stdout +19 -0
- data/spec/provider/package/apt/apt-get_install_-qy_unknown-package.return +1 -0
- data/spec/provider/package/apt/apt-get_install_-qy_unknown-package.stderr +1 -0
- data/spec/provider/package/apt/apt-get_install_-qy_unknown-package.stdout +3 -0
- data/spec/provider/package/apt/apt-get_remove_-qy_abcde.return +1 -0
- data/spec/provider/package/apt/apt-get_remove_-qy_abcde.stderr +0 -0
- data/spec/provider/package/apt/apt-get_remove_-qy_abcde.stdout +14 -0
- data/spec/provider/package/apt/dpkg-query_-s_abcde.return +1 -0
- data/spec/provider/package/apt/dpkg-query_-s_abcde.stderr +0 -0
- data/spec/provider/package/apt/dpkg-query_-s_abcde.stdout +23 -0
- data/spec/provider/package/apt/dpkg-query_-s_htop.return +1 -0
- data/spec/provider/package/apt/dpkg-query_-s_htop.stderr +0 -0
- data/spec/provider/package/apt/dpkg-query_-s_htop.stdout +19 -0
- data/spec/provider/package/apt/dpkg-query_-s_unknown-package.return +1 -0
- data/spec/provider/package/apt/dpkg-query_-s_unknown-package.stderr +3 -0
- data/spec/provider/package/apt/dpkg-query_-s_unknown-package.stdout +0 -0
- data/spec/provider/package/apt/dpkg-query_-s_vlc.return +1 -0
- data/spec/provider/package/apt/dpkg-query_-s_vlc.stderr +3 -0
- data/spec/provider/package/apt/dpkg-query_-s_vlc.stdout +0 -0
- data/spec/provider/package/apt_spec.rb +297 -0
- data/spec/provider/package_spec.rb +63 -0
- data/spec/provider/symlink_spec.rb +122 -0
- data/spec/provider_spec.rb +19 -0
- data/spec/recursive_autoloader/foo/bar/baz.rb +12 -0
- data/spec/recursive_autoloader/identically_named_dir_and_file/this_should_not_be_loaded.rb +1 -0
- data/spec/recursive_autoloader/identically_named_dir_and_file.rb +8 -0
- data/spec/recursive_autoloader/loaded_on_demand.rb +8 -0
- data/spec/recursive_autoloader/raises_exception.rb +1 -0
- data/spec/recursive_autoloader_spec.rb +41 -0
- data/spec/resource/directory_spec.rb +187 -0
- data/spec/resource/file_spec.rb +213 -0
- data/spec/resource/symlink_spec.rb +117 -0
- data/spec/resource_spec.rb +184 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/spec_helpers/fake_capture3.rb +47 -0
- data/spec/util/activesupport_spec.rb +24 -0
- data/spec/util/file_permissions_spec.rb +141 -0
- data/spec/util/file_spec.rb +127 -0
- data/spec/util/user_spec.rb +46 -0
- data/spec/util_spec.rb +80 -0
- metadata +253 -20
- data/.gitignore +0 -17
- data/Gemfile +0 -3
- data/wright.gemspec +0 -16
@@ -0,0 +1,23 @@
|
|
1
|
+
Package: abcde
|
2
|
+
Status: install ok installed
|
3
|
+
Priority: optional
|
4
|
+
Section: sound
|
5
|
+
Installed-Size: 282
|
6
|
+
Maintainer: Jesus Climent <jesus.climent@hispalinux.es>
|
7
|
+
Architecture: all
|
8
|
+
Version: 2.5.3-1
|
9
|
+
Depends: cd-discid, wget, cdparanoia | icedax, vorbis-tools (>= 1.0beta4-1) | lame | flac | bladeenc | speex
|
10
|
+
Recommends: vorbis-tools, libmusicbrainz-discid-perl, libwebservice-musicbrainz-perl, libdigest-sha-perl, mailx
|
11
|
+
Suggests: eject, distmp3, id3 (>= 0.12), id3v2, eyed3, normalize-audio, vorbisgain, mkcue, mp3gain, atomicparsley
|
12
|
+
Conffiles:
|
13
|
+
/etc/abcde.conf 6123bcbdb6204f9a2193f560e2cf5014
|
14
|
+
Description: A Better CD Encoder
|
15
|
+
A frontend program to cdparanoia, wget, cd-discid, id3, and your favorite
|
16
|
+
Ogg/Vorbis, MP3, FLAC, Ogg/Speex and/or MPP/MP+(Musepack) encoder (defaults
|
17
|
+
to oggenc). Grabs an entire CD and converts each track to the specified
|
18
|
+
formats and then comments or ID3-tags each file, with one command.
|
19
|
+
.
|
20
|
+
With abcde you can encode several formats with one single command, using a
|
21
|
+
single CD read operation. It also allows you to read and encode while not
|
22
|
+
on the internet, and later query a CDDB server to tag your files.
|
23
|
+
Homepage: http://code.google.com/p/abcde/
|
@@ -0,0 +1 @@
|
|
1
|
+
0
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Package: htop
|
2
|
+
Status: deinstall ok config-files
|
3
|
+
Priority: optional
|
4
|
+
Section: utils
|
5
|
+
Installed-Size: 211
|
6
|
+
Maintainer: Eugene V. Lyubimkin <jackyf@debian.org>
|
7
|
+
Architecture: amd64
|
8
|
+
Version: 1.0.1-1
|
9
|
+
Config-Version: 1.0.1-1
|
10
|
+
Depends: libc6 (>= 2.3.4), libncursesw5 (>= 5.6+20070908), libtinfo5
|
11
|
+
Suggests: strace, ltrace
|
12
|
+
Description: interactive processes viewer
|
13
|
+
Htop is an ncursed-based process viewer similar to top, but it
|
14
|
+
allows one to scroll the list vertically and horizontally to see
|
15
|
+
all processes and their full command lines.
|
16
|
+
.
|
17
|
+
Tasks related to processes (killing, renicing) can be done without
|
18
|
+
entering their PIDs.
|
19
|
+
Homepage: http://htop.sourceforge.net
|
@@ -0,0 +1 @@
|
|
1
|
+
1
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
1
|
File without changes
|
@@ -0,0 +1,297 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
require 'wright/provider/package/apt'
|
4
|
+
|
5
|
+
def dpkg_query(pkg_name)
|
6
|
+
"dpkg-query -s #{pkg_name}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def apt_get(action, pkg_name, pkg_version = nil)
|
10
|
+
version = pkg_version.nil? ? '' : "=#{pkg_version}"
|
11
|
+
"apt-get #{action} -qy #{pkg_name}#{version}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def package_provider(pkg_name, pkg_version = nil)
|
15
|
+
pkg_resource = OpenStruct.new(name: pkg_name, version: pkg_version)
|
16
|
+
Wright::Provider::Package::Apt.new(pkg_resource)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Wright::Provider::Package::Apt do
|
20
|
+
before :each do
|
21
|
+
apt_dir = File.join(File.dirname(__FILE__), 'apt')
|
22
|
+
env = { 'DEBIAN_FRONTEND' => 'noninteractive' }
|
23
|
+
@fake_capture3 = FakeCapture3.new(apt_dir, env)
|
24
|
+
@install_message = ->(pkg) { "INFO: install package: '#{pkg}'\n" }
|
25
|
+
@install_message_dry = lambda do |pkg|
|
26
|
+
"INFO: (would) install package: '#{pkg}'\n"
|
27
|
+
end
|
28
|
+
@install_message_debug = lambda do |pkg|
|
29
|
+
"DEBUG: package already installed: '#{pkg}'\n"
|
30
|
+
end
|
31
|
+
@remove_message = ->(pkg) { "INFO: remove package: '#{pkg}'\n" }
|
32
|
+
@remove_message_dry = lambda do |pkg|
|
33
|
+
"INFO: (would) remove package: '#{pkg}'\n"
|
34
|
+
end
|
35
|
+
@remove_message_debug = lambda do |pkg|
|
36
|
+
"DEBUG: package already removed: '#{pkg}'\n"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#installed_versions' do
|
41
|
+
it 'should return the installed package version via dpkg-query' do
|
42
|
+
pkg_name = 'abcde'
|
43
|
+
pkg_versions = ['2.5.3-1']
|
44
|
+
pkg_provider = package_provider(pkg_name)
|
45
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
46
|
+
|
47
|
+
@fake_capture3.expect(dpkg_cmd)
|
48
|
+
@fake_capture3.stub do
|
49
|
+
pkg_provider.installed_versions.must_equal pkg_versions
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should return empty array for missing packages' do
|
54
|
+
pkg_name = 'vlc'
|
55
|
+
pkg_versions = []
|
56
|
+
pkg_provider = package_provider(pkg_name)
|
57
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
58
|
+
|
59
|
+
@fake_capture3.expect(dpkg_cmd)
|
60
|
+
@fake_capture3.stub do
|
61
|
+
pkg_provider.installed_versions.must_equal pkg_versions
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should return nil for removed packages' do
|
66
|
+
pkg_name = 'htop'
|
67
|
+
pkg_versions = []
|
68
|
+
pkg_provider = package_provider(pkg_name)
|
69
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
70
|
+
|
71
|
+
@fake_capture3.expect(dpkg_cmd)
|
72
|
+
@fake_capture3.stub do
|
73
|
+
pkg_provider.installed_versions.must_equal pkg_versions
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#install' do
|
79
|
+
it 'should install packages that are not currently installed' do
|
80
|
+
pkg_name = 'htop'
|
81
|
+
pkg_provider = package_provider(pkg_name)
|
82
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
83
|
+
apt_cmd = apt_get(:install, pkg_name)
|
84
|
+
|
85
|
+
@fake_capture3.expect(dpkg_cmd)
|
86
|
+
@fake_capture3.expect(apt_cmd)
|
87
|
+
@fake_capture3.stub do
|
88
|
+
lambda do
|
89
|
+
reset_logger
|
90
|
+
pkg_provider.install
|
91
|
+
pkg_provider.updated?.must_equal true
|
92
|
+
end.must_output @install_message.call(pkg_name)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should not try to install packages that are already installed' do
|
97
|
+
pkg_name = 'abcde'
|
98
|
+
pkg_provider = package_provider(pkg_name)
|
99
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
100
|
+
|
101
|
+
@fake_capture3.expect(dpkg_cmd)
|
102
|
+
@fake_capture3.stub do
|
103
|
+
lambda do
|
104
|
+
reset_logger
|
105
|
+
pkg_provider.install
|
106
|
+
pkg_provider.updated?.must_equal false
|
107
|
+
end.must_output @install_message_debug.call(pkg_name)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should install package versions that are not currently installed' do
|
112
|
+
pkg_name = 'abcde'
|
113
|
+
pkg_version = '2.5.4-1'
|
114
|
+
pkg_provider = package_provider(pkg_name, pkg_version)
|
115
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
116
|
+
apt_cmd = apt_get(:install, pkg_name, pkg_version)
|
117
|
+
|
118
|
+
@fake_capture3.expect(dpkg_cmd)
|
119
|
+
@fake_capture3.expect(apt_cmd)
|
120
|
+
@fake_capture3.stub do
|
121
|
+
lambda do
|
122
|
+
reset_logger
|
123
|
+
pkg_provider.install
|
124
|
+
pkg_provider.updated?.must_equal true
|
125
|
+
end.must_output @install_message.call(pkg_name)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should not try to install package versions already installed' do
|
130
|
+
pkg_name = 'abcde'
|
131
|
+
pkg_version = '2.5.3-1'
|
132
|
+
pkg_provider = package_provider(pkg_name, pkg_version)
|
133
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
134
|
+
|
135
|
+
@fake_capture3.expect(dpkg_cmd)
|
136
|
+
@fake_capture3.stub do
|
137
|
+
lambda do
|
138
|
+
reset_logger
|
139
|
+
pkg_provider.install
|
140
|
+
pkg_provider.updated?.must_equal false
|
141
|
+
end.must_output @install_message_debug.call(pkg_name)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should raise exceptions for unknown packages' do
|
146
|
+
pkg_name = 'unknown-package'
|
147
|
+
pkg_provider = package_provider(pkg_name)
|
148
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
149
|
+
apt_cmd = apt_get(:install, pkg_name)
|
150
|
+
|
151
|
+
@fake_capture3.expect(dpkg_cmd)
|
152
|
+
@fake_capture3.expect(apt_cmd)
|
153
|
+
@fake_capture3.stub do
|
154
|
+
e = -> { pkg_provider.install }.must_raise RuntimeError
|
155
|
+
wright_error = "cannot install package '#{pkg_name}'"
|
156
|
+
apt_error = "E: Unable to locate package #{pkg_name}"
|
157
|
+
e.message.must_equal %(#{wright_error}: "#{apt_error}")
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '#remove' do
|
163
|
+
it 'should remove packages that are currently installed' do
|
164
|
+
pkg_name = 'abcde'
|
165
|
+
pkg_provider = package_provider(pkg_name)
|
166
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
167
|
+
apt_cmd = apt_get(:remove, pkg_name)
|
168
|
+
|
169
|
+
@fake_capture3.expect(dpkg_cmd)
|
170
|
+
@fake_capture3.expect(apt_cmd)
|
171
|
+
@fake_capture3.stub do
|
172
|
+
lambda do
|
173
|
+
reset_logger
|
174
|
+
pkg_provider.remove
|
175
|
+
pkg_provider.updated?.must_equal true
|
176
|
+
end.must_output @remove_message.call(pkg_name)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'should not try to remove packages that are already removed' do
|
181
|
+
pkg_name = 'htop'
|
182
|
+
pkg_provider = package_provider(pkg_name)
|
183
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
184
|
+
|
185
|
+
@fake_capture3.expect(dpkg_cmd)
|
186
|
+
@fake_capture3.stub do
|
187
|
+
lambda do
|
188
|
+
reset_logger
|
189
|
+
pkg_provider.remove
|
190
|
+
pkg_provider.updated?.must_equal false
|
191
|
+
end.must_output @remove_message_debug.call(pkg_name)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'should remove package versions that are currently installed' do
|
196
|
+
pkg_name = 'abcde'
|
197
|
+
pkg_version = '2.5.3-1'
|
198
|
+
pkg_provider = package_provider(pkg_name, pkg_version)
|
199
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
200
|
+
apt_cmd = apt_get(:remove, pkg_name)
|
201
|
+
|
202
|
+
@fake_capture3.expect(dpkg_cmd)
|
203
|
+
@fake_capture3.expect(apt_cmd)
|
204
|
+
@fake_capture3.stub do
|
205
|
+
lambda do
|
206
|
+
reset_logger
|
207
|
+
pkg_provider.remove
|
208
|
+
pkg_provider.updated?.must_equal true
|
209
|
+
end.must_output @remove_message.call(pkg_name)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should not try to remove packages that are already removed' do
|
214
|
+
pkg_name = 'htop'
|
215
|
+
pkg_version = '2.5.4-1'
|
216
|
+
pkg_provider = package_provider(pkg_name, pkg_version)
|
217
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
218
|
+
|
219
|
+
@fake_capture3.expect(dpkg_cmd)
|
220
|
+
@fake_capture3.stub do
|
221
|
+
lambda do
|
222
|
+
reset_logger
|
223
|
+
pkg_provider.remove
|
224
|
+
pkg_provider.updated?.must_equal false
|
225
|
+
end.must_output @remove_message_debug.call(pkg_name)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
describe 'dry_run' do
|
231
|
+
it 'should not actually install packages' do
|
232
|
+
pkg_name = 'htop'
|
233
|
+
pkg_provider = package_provider(pkg_name)
|
234
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
235
|
+
|
236
|
+
Wright.dry_run do
|
237
|
+
@fake_capture3.expect(dpkg_cmd)
|
238
|
+
@fake_capture3.stub do
|
239
|
+
lambda do
|
240
|
+
reset_logger
|
241
|
+
pkg_provider.install
|
242
|
+
end.must_output @install_message_dry.call(pkg_name)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'should not try to install packages that are already installed' do
|
248
|
+
pkg_name = 'abcde'
|
249
|
+
pkg_provider = package_provider(pkg_name)
|
250
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
251
|
+
|
252
|
+
Wright.dry_run do
|
253
|
+
@fake_capture3.expect(dpkg_cmd)
|
254
|
+
@fake_capture3.stub do
|
255
|
+
lambda do
|
256
|
+
reset_logger
|
257
|
+
pkg_provider.install
|
258
|
+
pkg_provider.updated?.must_equal false
|
259
|
+
end.must_output @install_message_debug.call(pkg_name)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'should not actually remove packages' do
|
265
|
+
pkg_name = 'abcde'
|
266
|
+
pkg_provider = package_provider(pkg_name)
|
267
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
268
|
+
|
269
|
+
Wright.dry_run do
|
270
|
+
@fake_capture3.expect(dpkg_cmd)
|
271
|
+
@fake_capture3.stub do
|
272
|
+
lambda do
|
273
|
+
reset_logger
|
274
|
+
pkg_provider.remove
|
275
|
+
end.must_output @remove_message_dry.call(pkg_name)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'should not try to remove packages that are already removed' do
|
281
|
+
pkg_name = 'htop'
|
282
|
+
pkg_provider = package_provider(pkg_name)
|
283
|
+
dpkg_cmd = dpkg_query(pkg_name)
|
284
|
+
|
285
|
+
Wright.dry_run do
|
286
|
+
@fake_capture3.expect(dpkg_cmd)
|
287
|
+
@fake_capture3.stub do
|
288
|
+
lambda do
|
289
|
+
reset_logger
|
290
|
+
pkg_provider.remove
|
291
|
+
pkg_provider.updated?.must_equal false
|
292
|
+
end.must_output @remove_message_debug.call(pkg_name)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
require 'wright/provider'
|
4
|
+
require 'wright/provider/package'
|
5
|
+
|
6
|
+
describe Wright::Provider::Package do
|
7
|
+
before(:each) do
|
8
|
+
Wright::Provider::Package.send(:public, :uptodate?)
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:each) do
|
12
|
+
Wright::Provider::Package.send(:private, :uptodate?)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#uptodate?' do
|
16
|
+
it 'should return the correct status' do
|
17
|
+
pkg_resource = OpenStruct.new(name: 'foo')
|
18
|
+
pkg_provider = Wright::Provider::Package.new(pkg_resource)
|
19
|
+
|
20
|
+
def pkg_provider.installed_versions
|
21
|
+
['4.2']
|
22
|
+
end
|
23
|
+
pkg_provider.uptodate?(:install).must_equal true
|
24
|
+
pkg_provider.uptodate?(:remove).must_equal false
|
25
|
+
|
26
|
+
def pkg_provider.installed_versions
|
27
|
+
[]
|
28
|
+
end
|
29
|
+
pkg_provider.uptodate?(:install).must_equal false
|
30
|
+
pkg_provider.uptodate?(:remove).must_equal true
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should return the correct status when given a specific version' do
|
34
|
+
pkg_resource = OpenStruct.new(name: 'foo', version: '4.3')
|
35
|
+
pkg_provider = Wright::Provider::Package.new(pkg_resource)
|
36
|
+
|
37
|
+
def pkg_provider.installed_versions
|
38
|
+
['4.2']
|
39
|
+
end
|
40
|
+
pkg_provider.uptodate?(:install).must_equal false
|
41
|
+
pkg_provider.uptodate?(:remove).must_equal true
|
42
|
+
|
43
|
+
def pkg_provider.installed_versions
|
44
|
+
[]
|
45
|
+
end
|
46
|
+
pkg_provider.uptodate?(:install).must_equal false
|
47
|
+
pkg_provider.uptodate?(:remove).must_equal true
|
48
|
+
|
49
|
+
def pkg_provider.installed_versions
|
50
|
+
['4.3']
|
51
|
+
end
|
52
|
+
pkg_provider.uptodate?(:install).must_equal true
|
53
|
+
pkg_provider.uptodate?(:remove).must_equal false
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should raise exceptions for invalid actions' do
|
57
|
+
pkg_resource = OpenStruct.new(name: 'foo')
|
58
|
+
pkg_provider = Wright::Provider::Package.new(pkg_resource)
|
59
|
+
e = -> { pkg_provider.uptodate?(:foobarbaz) }.must_raise ArgumentError
|
60
|
+
e.message.must_equal "invalid action 'foobarbaz'"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
require 'wright/provider/symlink'
|
6
|
+
require 'wright/dry_run'
|
7
|
+
|
8
|
+
describe Wright::Provider::Symlink do
|
9
|
+
before(:each) do
|
10
|
+
@link_resource = OpenStruct.new(to: 'foo', name: 'bar')
|
11
|
+
|
12
|
+
name = @link_resource.name
|
13
|
+
to = @link_resource.to
|
14
|
+
symlink_to_s = "'#{name}' -> '#{to}'"
|
15
|
+
@create_message = "INFO: create symlink: #{symlink_to_s}\n"
|
16
|
+
@create_message_dry = "INFO: (would) create symlink: #{symlink_to_s}\n"
|
17
|
+
@create_message_debug = "DEBUG: symlink already created: #{symlink_to_s}\n"
|
18
|
+
@remove_message = "INFO: remove symlink: '#{name}'\n"
|
19
|
+
@remove_message_dry = "INFO: (would) remove symlink: '#{name}'\n"
|
20
|
+
@remove_message_debug = "DEBUG: symlink already removed: '#{name}'\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
after(:each) do
|
24
|
+
FakeFS::FileSystem.clear
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#updated?' do
|
28
|
+
it 'should return the update status if a link was created' do
|
29
|
+
link = Wright::Provider::Symlink.new(@link_resource)
|
30
|
+
lambda do
|
31
|
+
reset_logger
|
32
|
+
FakeFS { link.create }
|
33
|
+
end.must_output @create_message
|
34
|
+
assert link.updated?
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should return the update status if a link was not created' do
|
38
|
+
link = Wright::Provider::Symlink.new(@link_resource)
|
39
|
+
lambda do
|
40
|
+
FakeFS do
|
41
|
+
reset_logger
|
42
|
+
FileUtils.ln_sf(@link_resource.to, @link_resource.name)
|
43
|
+
link.create
|
44
|
+
assert !link.updated?
|
45
|
+
end
|
46
|
+
end.must_output @create_message_debug
|
47
|
+
|
48
|
+
FakeFS do
|
49
|
+
FileUtils.rm(@link_resource.name)
|
50
|
+
FileUtils.touch(@link_resource.name)
|
51
|
+
-> { link.create }.must_raise Errno::EEXIST
|
52
|
+
assert !link.updated?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should return the update status if a link was changed' do
|
57
|
+
link = Wright::Provider::Symlink.new(@link_resource)
|
58
|
+
lambda do
|
59
|
+
reset_logger
|
60
|
+
FakeFS do
|
61
|
+
FileUtils.ln_sf('old-source', @link_resource.name)
|
62
|
+
link.create
|
63
|
+
end
|
64
|
+
end.must_output @create_message
|
65
|
+
assert link.updated?
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should return the update status if a link was removed' do
|
69
|
+
link = Wright::Provider::Symlink.new(@link_resource)
|
70
|
+
lambda do
|
71
|
+
reset_logger
|
72
|
+
FakeFS do
|
73
|
+
FileUtils.ln_sf(@link_resource.to, @link_resource.name)
|
74
|
+
link.remove
|
75
|
+
end
|
76
|
+
end.must_output @remove_message
|
77
|
+
assert link.updated?
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should return the update status if a link was not removed' do
|
81
|
+
link = Wright::Provider::Symlink.new(@link_resource)
|
82
|
+
lambda do
|
83
|
+
reset_logger
|
84
|
+
FakeFS { link.remove }
|
85
|
+
assert !link.updated?
|
86
|
+
end.must_output @remove_message_debug
|
87
|
+
|
88
|
+
FakeFS do
|
89
|
+
FileUtils.touch(@link_resource.name)
|
90
|
+
-> { link.remove }.must_raise RuntimeError
|
91
|
+
assert !link.updated?
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'dry_run' do
|
97
|
+
it 'should not actually create symlinks' do
|
98
|
+
link = Wright::Provider::Symlink.new(@link_resource)
|
99
|
+
Wright.dry_run do
|
100
|
+
lambda do
|
101
|
+
reset_logger
|
102
|
+
FakeFS { link.create }
|
103
|
+
end.must_output @create_message_dry
|
104
|
+
FakeFS { assert !File.symlink?(@link_resource.name) }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should not actually remove symlinks' do
|
109
|
+
link = Wright::Provider::Symlink.new(@link_resource)
|
110
|
+
Wright.dry_run do
|
111
|
+
lambda do
|
112
|
+
reset_logger
|
113
|
+
FakeFS do
|
114
|
+
FileUtils.ln_sf(@link_resource.to, @link_resource.name)
|
115
|
+
link.remove
|
116
|
+
end
|
117
|
+
end.must_output @remove_message_dry
|
118
|
+
end
|
119
|
+
FakeFS { assert File.symlink?(@link_resource.name) }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
require 'wright/provider'
|
4
|
+
|
5
|
+
# fake provider
|
6
|
+
class FakeProvider < Wright::Provider
|
7
|
+
def initialize
|
8
|
+
super(nil)
|
9
|
+
@updated = true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Wright::Provider do
|
14
|
+
it 'should reset the updated attribute after checks' do
|
15
|
+
provider = FakeProvider.new
|
16
|
+
provider.updated?.must_equal true
|
17
|
+
provider.updated?.must_equal false
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
fail 'This should not be loaded'
|
@@ -0,0 +1 @@
|
|
1
|
+
fail 'This should never be loaded'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
require 'wright/util/recursive_autoloader'
|
4
|
+
|
5
|
+
BASEDIR = File.expand_path('recursive_autoloader', File.dirname(__FILE__))
|
6
|
+
Wright::Util::RecursiveAutoloader.add_autoloads(BASEDIR, 'Wright')
|
7
|
+
|
8
|
+
describe Wright::Util::RecursiveAutoloader do
|
9
|
+
it 'should not load files prematurely' do
|
10
|
+
-> { Wright::RaisesException }.must_raise(RuntimeError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should load files when needed' do
|
14
|
+
assert Wright.autoload?(:LoadedOnDemand)
|
15
|
+
loaded = Wright::LoadedOnDemand.new
|
16
|
+
assert loaded.was_loaded
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should load files in subdirectories' do
|
20
|
+
assert Wright::Foo::Bar.autoload?(:Baz)
|
21
|
+
baz = Wright::Foo::Bar::Baz.new
|
22
|
+
assert baz.was_loaded
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should throw exceptions for unknown base classes' do
|
26
|
+
lambda do
|
27
|
+
baseclass = 'This::Class::Does::Not::Exist'
|
28
|
+
Wright::Util::RecursiveAutoloader.add_autoloads(BASEDIR, baseclass)
|
29
|
+
end.must_raise(ArgumentError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should autoload existing classes before creating them itself' do
|
33
|
+
dir = File.join(BASEDIR, 'identically_named_dir_and_file/')
|
34
|
+
file = File.join(BASEDIR, 'identically_named_dir_and_file.rb')
|
35
|
+
assert File.exist?(dir)
|
36
|
+
assert File.exist?(file)
|
37
|
+
|
38
|
+
Wright.autoload?(:IdenticallyNamedDirAndFile).must_be_nil
|
39
|
+
assert Wright::IdenticallyNamedDirAndFile.new.was_loaded
|
40
|
+
end
|
41
|
+
end
|