ruby-augeas 0.4.1 → 0.6.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/COPYING +38 -46
- data/NEWS +26 -1
- data/README.md +86 -0
- data/Rakefile +12 -8
- data/ext/augeas/_augeas.c +238 -30
- data/ext/augeas/_augeas.h +48 -0
- data/ext/augeas/extconf.rb +4 -0
- data/lib/augeas/facade.rb +326 -0
- data/lib/augeas.rb +94 -0
- data/tests/tc_augeas.rb +85 -2
- data/tests/tc_facade.rb +554 -0
- metadata +32 -53
- data/README.rdoc +0 -34
data/tests/tc_facade.rb
ADDED
@@ -0,0 +1,554 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
##
|
3
|
+
# Augeas tests
|
4
|
+
#
|
5
|
+
# Copyright (C) 2011 Red Hat Inc.
|
6
|
+
# Copyright (C) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
7
|
+
#
|
8
|
+
# This library is free software; you can redistribute it and/or
|
9
|
+
# modify it under the terms of the GNU Lesser General Public
|
10
|
+
# License as published by the Free Software Foundation; either
|
11
|
+
# version 2.1 of the License, or (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This library is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
+
# Lesser General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU Lesser General Public
|
19
|
+
# License along with this library; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21
|
+
#
|
22
|
+
# Authors: David Lutterkort <dlutter@redhat.com>
|
23
|
+
# Ionuț Arțăriși <iartarisi@suse.cz>
|
24
|
+
##
|
25
|
+
|
26
|
+
require 'test/unit'
|
27
|
+
|
28
|
+
unless defined?(TOPDIR)
|
29
|
+
TOPDIR = File::expand_path(File::join(File::dirname(__FILE__), ".."))
|
30
|
+
end
|
31
|
+
|
32
|
+
$:.unshift(File::join(TOPDIR, "lib"))
|
33
|
+
$:.unshift(File::join(TOPDIR, "ext", "augeas"))
|
34
|
+
|
35
|
+
require 'augeas'
|
36
|
+
require 'fileutils'
|
37
|
+
|
38
|
+
class TestAugeasFacade < Test::Unit::TestCase
|
39
|
+
|
40
|
+
SRC_ROOT = File::expand_path(File::join(TOPDIR, "tests", "root")) + "/."
|
41
|
+
TST_ROOT = File::expand_path(File::join(TOPDIR, "build", "root")) + "/"
|
42
|
+
|
43
|
+
def test_basics
|
44
|
+
aug = aug_create(:save_mode => :newfile)
|
45
|
+
assert_equal("newfile", aug.get("/augeas/save"))
|
46
|
+
assert_equal(TST_ROOT, aug.get("/augeas/root"))
|
47
|
+
|
48
|
+
assert(aug.exists("/augeas/root"))
|
49
|
+
assert_not_nil(aug.get("/augeas/root"))
|
50
|
+
node = "/ruby/test/node"
|
51
|
+
assert_nothing_raised {
|
52
|
+
aug.set(node, "value")
|
53
|
+
}
|
54
|
+
assert_equal("value", aug.get(node))
|
55
|
+
assert_nothing_raised {
|
56
|
+
aug.clear(node)
|
57
|
+
}
|
58
|
+
assert_equal(nil, aug.get(node))
|
59
|
+
m = aug.match("/*")
|
60
|
+
["/augeas", "/ruby"].each do |p|
|
61
|
+
assert(m.include?(p))
|
62
|
+
assert(aug.exists(p))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_no_new
|
67
|
+
assert_raise NoMethodError do
|
68
|
+
Augeas.new
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_create_unknown_argument
|
73
|
+
assert_raise ArgumentError do
|
74
|
+
Augeas::create(:bogus => false)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_create_invalid_save_mode
|
79
|
+
assert_raise ArgumentError do
|
80
|
+
Augeas::create(:save_mode => :bogus)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_create_block
|
85
|
+
foo = nil
|
86
|
+
Augeas::create do |aug|
|
87
|
+
aug.set('/foo', 'bar')
|
88
|
+
foo = aug.get('/foo')
|
89
|
+
end
|
90
|
+
assert_equal(foo, 'bar')
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_close
|
94
|
+
aug = Augeas::create(:root => "/tmp", :save_mode => :newfile)
|
95
|
+
assert_equal("newfile", aug.get("/augeas/save"))
|
96
|
+
aug.close
|
97
|
+
|
98
|
+
assert_raise(SystemCallError) {
|
99
|
+
aug.get("/augeas/save")
|
100
|
+
}
|
101
|
+
|
102
|
+
assert_raise(SystemCallError) {
|
103
|
+
aug.close
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_mv
|
108
|
+
Augeas::create(:root => "/dev/null") do |aug|
|
109
|
+
aug.set("/a/b", "value")
|
110
|
+
aug.mv("/a/b", "/x/y")
|
111
|
+
assert_equal("value", aug.get("/x/y"))
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_mv_descendent_error
|
116
|
+
aug = aug_create
|
117
|
+
aug.set("/foo", "bar")
|
118
|
+
assert_raises(Augeas::DescendantError) {aug.mv("/foo", "/foo/bar/baz")}
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_mv_multiple_matches_error
|
122
|
+
aug = aug_create
|
123
|
+
aug.set("/foo/bar", "bar")
|
124
|
+
aug.set("/foo/baz", "baz")
|
125
|
+
assert_raises(Augeas::MultipleMatchesError) {aug.mv("/foo/*", "/qux")}
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_mv_invalid_path_error
|
129
|
+
aug = aug_create
|
130
|
+
assert_raises(Augeas::InvalidPathError) {aug.mv("/foo", "[]")}
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_mv_no_match_error
|
134
|
+
aug = aug_create
|
135
|
+
assert_raises(Augeas::NoMatchError) {aug.mv("/nonexistent", "/")}
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_mv_mutiple_dest_error
|
139
|
+
aug = aug_create
|
140
|
+
aug.set("/foo", "bar")
|
141
|
+
assert_raises(Augeas::CommandExecutionError) {aug.mv("/foo", "/bar/baz/*")}
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_load
|
145
|
+
aug = aug_create(:no_load => true)
|
146
|
+
assert_equal([], aug.match("/files/etc/*"))
|
147
|
+
aug.rm("/augeas/load/*");
|
148
|
+
assert_nothing_raised {
|
149
|
+
aug.load
|
150
|
+
}
|
151
|
+
assert_equal([], aug.match("/files/etc/*"))
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_load_bad_lens
|
155
|
+
aug = aug_create(:no_load => true, :no_modl_autoload => true)
|
156
|
+
aug.transform(:lens => "bad_lens", :incl => "irrelevant")
|
157
|
+
aug.load
|
158
|
+
assert_equal "Can not find lens bad_lens", aug.get("/augeas/load/bad_lens/error")
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_transform
|
162
|
+
aug = aug_create(:no_load => true)
|
163
|
+
aug.clear_transforms
|
164
|
+
aug.transform(:lens => "Hosts.lns",
|
165
|
+
:incl => "/etc/hosts")
|
166
|
+
assert_raise(ArgumentError) {
|
167
|
+
aug.transform(:name => "Fstab",
|
168
|
+
:incl => [ "/etc/fstab" ],
|
169
|
+
:excl => [ "*~", "*.rpmnew" ])
|
170
|
+
}
|
171
|
+
aug.transform(:lens => "Inittab.lns",
|
172
|
+
:incl => "/etc/inittab")
|
173
|
+
aug.transform(:lens => "Fstab.lns",
|
174
|
+
:incl => "/etc/fstab*",
|
175
|
+
:excl => "*~")
|
176
|
+
assert_equal(["/augeas/load/Fstab", "/augeas/load/Fstab/excl",
|
177
|
+
"/augeas/load/Fstab/incl", "/augeas/load/Fstab/lens",
|
178
|
+
"/augeas/load/Hosts", "/augeas/load/Hosts/incl",
|
179
|
+
"/augeas/load/Hosts/lens", "/augeas/load/Inittab",
|
180
|
+
"/augeas/load/Inittab/incl",
|
181
|
+
"/augeas/load/Inittab/lens"],
|
182
|
+
aug.match("/augeas/load//*").sort)
|
183
|
+
aug.load
|
184
|
+
assert_equal(["/files/etc/hosts", "/files/etc/inittab"],
|
185
|
+
aug.match("/files/etc/*").sort)
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_transform_invalid_path
|
189
|
+
aug = aug_create
|
190
|
+
assert_raises (Augeas::InvalidPathError) {
|
191
|
+
aug.transform :lens => '//', :incl => 'foo' }
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_clear_transforms
|
195
|
+
aug = aug_create
|
196
|
+
assert_not_equal [], aug.match("/augeas/load/*")
|
197
|
+
aug.clear_transforms
|
198
|
+
assert_equal [], aug.match("/augeas/load/*")
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_clear
|
202
|
+
aug = aug_create
|
203
|
+
aug.set("/foo/bar", "baz")
|
204
|
+
aug.clear("/foo/bar")
|
205
|
+
assert_equal aug.get("/foo/bar"), nil
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_rm
|
209
|
+
aug = aug_create
|
210
|
+
aug.set("/foo/bar", "baz")
|
211
|
+
assert aug.get("/foo/bar")
|
212
|
+
assert_equal 2, aug.rm("/foo")
|
213
|
+
assert_nil aug.get("/foo")
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_rm_invalid_path
|
217
|
+
aug = aug_create
|
218
|
+
assert_raises(Augeas::InvalidPathError) { aug.rm('//') }
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_defvar
|
222
|
+
Augeas::create(:root => "/dev/null") do |aug|
|
223
|
+
aug.set("/a/b", "bval")
|
224
|
+
aug.set("/a/c", "cval")
|
225
|
+
assert aug.defvar("var", "/a/b")
|
226
|
+
assert_equal(["/a/b"], aug.match("$var"))
|
227
|
+
assert aug.defvar("var", nil)
|
228
|
+
assert_raises(Augeas::InvalidPathError) {
|
229
|
+
aug.match("$var")
|
230
|
+
}
|
231
|
+
assert_raises(Augeas::InvalidPathError) {
|
232
|
+
aug.defvar("var", "/foo/")
|
233
|
+
}
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_insert_before
|
238
|
+
aug = aug_create
|
239
|
+
aug.set("/parent/child", "foo")
|
240
|
+
aug.insert("/parent/child", "sibling", true)
|
241
|
+
assert_equal ["/parent/sibling", "/parent/child"], aug.match("/parent/*")
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_insert_after
|
245
|
+
aug = aug_create
|
246
|
+
aug.set("/parent/child", "foo")
|
247
|
+
aug.insert("/parent/child", "sibling", false)
|
248
|
+
assert_equal ["/parent/child", "/parent/sibling"], aug.match("/parent/*")
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_insert_no_match
|
252
|
+
aug = aug_create
|
253
|
+
assert_raises (Augeas::NoMatchError) { aug.insert "foo", "bar", "baz" }
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_insert_invalid_path
|
257
|
+
aug = aug_create
|
258
|
+
assert_raises (Augeas::InvalidPathError) { aug.insert "//", "bar", "baz" }
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_insert_too_many_matches
|
262
|
+
aug = aug_create
|
263
|
+
assert_raises (Augeas::MultipleMatchesError) { aug.insert "/*", "a", "b" }
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_match
|
267
|
+
aug = aug_create
|
268
|
+
aug.set("/foo/bar", "baz")
|
269
|
+
aug.set("/foo/baz", "qux")
|
270
|
+
aug.set("/foo/qux", "bar")
|
271
|
+
|
272
|
+
assert_equal(["/foo/bar", "/foo/baz", "/foo/qux"], aug.match("/foo/*"))
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_match_empty_list
|
276
|
+
aug = aug_create
|
277
|
+
assert_equal([], aug.match("/nonexistent"))
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_match_invalid_path
|
281
|
+
aug = aug_create
|
282
|
+
assert_raises(Augeas::InvalidPathError) { aug.match('//') }
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_save
|
286
|
+
aug = aug_create
|
287
|
+
aug.set("/files/etc/hosts/1/garbage", "trash")
|
288
|
+
assert_raises(Augeas::CommandExecutionError) { aug.save }
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_save_tree_error
|
292
|
+
aug = aug_create(:no_load => true)
|
293
|
+
aug.set("/files/etc/sysconfig/iptables", "bad")
|
294
|
+
assert_raises(Augeas::CommandExecutionError) {aug.save}
|
295
|
+
assert aug.get("/augeas/files/etc/sysconfig/iptables/error")
|
296
|
+
assert_equal("No such file or directory",
|
297
|
+
aug.get("/augeas/files/etc/sysconfig/iptables/error/message"))
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_set_invalid_path
|
301
|
+
aug = aug_create
|
302
|
+
assert_raises(Augeas::InvalidPathError) { aug.set("files/etc//", nil) }
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_set_multiple_matches_error
|
306
|
+
aug = aug_create
|
307
|
+
# for some reason Augeas does not set aug_error for this,
|
308
|
+
# but just returns -1 from aug_set. Should raise Augeas::MultipleMatchesError instead.
|
309
|
+
assert_raises(Augeas::CommandExecutionError) { aug.set("files/etc/*", nil) }
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_set
|
313
|
+
aug = aug_create
|
314
|
+
aug.set("/files/etc/group/disk/user[last()+1]",["user1","user2"])
|
315
|
+
assert_equal(aug.get("/files/etc/group/disk/user[1]"), "root")
|
316
|
+
assert_equal(aug.get("/files/etc/group/disk/user[2]"), "user1")
|
317
|
+
assert_equal(aug.get("/files/etc/group/disk/user[3]"), "user2")
|
318
|
+
|
319
|
+
aug.set("/files/etc/group/new_group/user[last()+1]",
|
320
|
+
"nuser1",["nuser2","nuser3"])
|
321
|
+
assert_equal(aug.get("/files/etc/group/new_group/user[1]"), "nuser1")
|
322
|
+
assert_equal(aug.get("/files/etc/group/new_group/user[2]"), "nuser2")
|
323
|
+
assert_equal(aug.get("/files/etc/group/new_group/user[3]"), "nuser3")
|
324
|
+
|
325
|
+
aug.rm("/files/etc/group/disk/user")
|
326
|
+
aug.set("/files/etc/group/disk/user[last()+1]", "testuser")
|
327
|
+
assert_equal(aug.get("/files/etc/group/disk/user"), "testuser")
|
328
|
+
|
329
|
+
aug.rm("/files/etc/group/disk/user")
|
330
|
+
aug.set("/files/etc/group/disk/user[last()+1]", nil)
|
331
|
+
assert_equal(aug.get("/files/etc/group/disk/user"), nil)
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_setm_invalid_path
|
335
|
+
aug = aug_create
|
336
|
+
assert_raises (Augeas::InvalidPathError) { aug.setm("[]", "bar", "baz") }
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_exists
|
340
|
+
aug = aug_create
|
341
|
+
assert_equal false, aug.exists("/foo")
|
342
|
+
aug.set("/foo", "bar")
|
343
|
+
assert aug.exists("/foo")
|
344
|
+
end
|
345
|
+
|
346
|
+
def test_exists_invalid_path_error
|
347
|
+
aug = aug_create
|
348
|
+
assert_raises(Augeas::InvalidPathError) {aug.exists("[]")}
|
349
|
+
end
|
350
|
+
|
351
|
+
def test_get_multiple_matches_error
|
352
|
+
aug = aug_create
|
353
|
+
|
354
|
+
# Cause an error
|
355
|
+
assert_raises (Augeas::MultipleMatchesError) {
|
356
|
+
aug.get("/files/etc/hosts/*") }
|
357
|
+
|
358
|
+
err = aug.error
|
359
|
+
assert_equal(Augeas::EMMATCH, err[:code])
|
360
|
+
assert err[:message]
|
361
|
+
assert err[:details]
|
362
|
+
assert err[:minor].nil?
|
363
|
+
end
|
364
|
+
|
365
|
+
def test_get_invalid_path
|
366
|
+
aug = aug_create
|
367
|
+
assert_raises (Augeas::InvalidPathError) { aug.get("//") }
|
368
|
+
|
369
|
+
err = aug.error
|
370
|
+
assert_equal(Augeas::EPATHX, err[:code])
|
371
|
+
assert err[:message]
|
372
|
+
assert err[:details]
|
373
|
+
end
|
374
|
+
|
375
|
+
def test_defvar_invalid_path
|
376
|
+
aug = aug_create
|
377
|
+
assert_raises(Augeas::InvalidPathError) { aug.defvar('var', 'F#@!$#@') }
|
378
|
+
end
|
379
|
+
|
380
|
+
def test_defnode
|
381
|
+
aug = aug_create
|
382
|
+
assert aug.defnode("x", "/files/etc/hosts/*[ipaddr = '127.0.0.1']", nil)
|
383
|
+
assert_equal(["/files/etc/hosts/1"], aug.match("$x"))
|
384
|
+
end
|
385
|
+
|
386
|
+
def test_defnode_invalid_path
|
387
|
+
aug = aug_create
|
388
|
+
assert_raises (Augeas::InvalidPathError) { aug.defnode('x', '//', nil)}
|
389
|
+
end
|
390
|
+
|
391
|
+
def test_span_no_span_info
|
392
|
+
aug = aug_create
|
393
|
+
# this error should be raised because we haven't enabled the span
|
394
|
+
assert_raises(Augeas::NoSpanInfoError) {
|
395
|
+
aug.span("/files/etc/ssh/sshd_config/Protocol") }
|
396
|
+
end
|
397
|
+
|
398
|
+
def test_span_no_matches
|
399
|
+
aug = aug_create
|
400
|
+
assert_raises(Augeas::NoMatchError) { aug.span("bogus") }
|
401
|
+
end
|
402
|
+
|
403
|
+
def test_flag_save_noop
|
404
|
+
aug = aug_create(:save_mode => :noop)
|
405
|
+
assert_equal("noop", aug.get("/augeas/save"))
|
406
|
+
end
|
407
|
+
|
408
|
+
def test_flag_no_load
|
409
|
+
aug = aug_create(:no_load => true)
|
410
|
+
assert_equal([], aug.match("/files/*"))
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_flag_no_modl_autoload
|
414
|
+
aug = aug_create(:no_modl_autoload => true)
|
415
|
+
assert_equal([], aug.match("/files/*"))
|
416
|
+
end
|
417
|
+
|
418
|
+
def test_flag_enable_span
|
419
|
+
aug = aug_create(:enable_span => true)
|
420
|
+
assert_equal("enable", aug.get("/augeas/span"))
|
421
|
+
end
|
422
|
+
|
423
|
+
def test_setm
|
424
|
+
aug = aug_create
|
425
|
+
|
426
|
+
aug.setm("/files/etc/group/*[label() =~ regexp(\"rpc.*\")]","users", "testuser1")
|
427
|
+
assert_equal( aug.get("/files/etc/group/rpc/users"), "testuser1")
|
428
|
+
assert_equal( aug.get("/files/etc/group/rpcuser/users"), "testuser1")
|
429
|
+
|
430
|
+
aug.setm("/files/etc/group/*[label() =~ regexp(\"rpc.*\")]/users",nil, "testuser2")
|
431
|
+
assert_equal( aug.get("/files/etc/group/rpc/users"), "testuser2")
|
432
|
+
assert_equal( aug.get("/files/etc/group/rpcuser/users"), "testuser2")
|
433
|
+
end
|
434
|
+
|
435
|
+
def test_error
|
436
|
+
aug = aug_create
|
437
|
+
|
438
|
+
# Cause an error
|
439
|
+
aug.get("/files/etc/hosts/*") rescue nil
|
440
|
+
err = aug.error
|
441
|
+
assert_equal(Augeas::EMMATCH, err[:code])
|
442
|
+
assert err[:message]
|
443
|
+
assert err[:details]
|
444
|
+
assert err[:minor].nil?
|
445
|
+
end
|
446
|
+
|
447
|
+
def test_span
|
448
|
+
aug = aug_create
|
449
|
+
|
450
|
+
assert_raises(Augeas::NoSpanInfoError) { aug.span("/files/etc/ssh/sshd_config/Protocol") }
|
451
|
+
|
452
|
+
aug.set("/augeas/span", "enable")
|
453
|
+
aug.rm("/files/etc")
|
454
|
+
aug.load
|
455
|
+
|
456
|
+
span = aug.span("/files/etc/ssh/sshd_config/Protocol")
|
457
|
+
assert_not_nil(span[:filename])
|
458
|
+
assert_equal(29..37, span[:label])
|
459
|
+
assert_equal(38..39, span[:value])
|
460
|
+
assert_equal(29..40, span[:span])
|
461
|
+
end
|
462
|
+
|
463
|
+
def test_srun
|
464
|
+
aug = aug_create
|
465
|
+
|
466
|
+
path = "/files/etc/hosts/*[canonical='localhost.localdomain']/ipaddr"
|
467
|
+
r, out = aug.srun("get #{path}\n")
|
468
|
+
assert_equal(1, r)
|
469
|
+
assert_equal("#{path} = 127.0.0.1\n", out)
|
470
|
+
|
471
|
+
assert_equal(0, aug.srun(" ")[0])
|
472
|
+
assert_raises(Augeas::CommandExecutionError) { aug.srun("foo") }
|
473
|
+
assert_raises(Augeas::CommandExecutionError) { aug.srun("set") }
|
474
|
+
assert_equal(-2, aug.srun("quit")[0])
|
475
|
+
end
|
476
|
+
|
477
|
+
def test_label
|
478
|
+
Augeas::create(:root => "/dev/null") do |aug|
|
479
|
+
assert_equal 'augeas', aug.label('/augeas')
|
480
|
+
assert_equal 'files', aug.label('/files')
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
def test_rename
|
485
|
+
Augeas::create(:root => "/dev/null") do |aug|
|
486
|
+
assert_raises(Augeas::InvalidLabelError) { aug.rename('/files', 'invalid/label') }
|
487
|
+
assert_equal 0, aug.rename('/nonexistent', 'label')
|
488
|
+
assert_equal ['/files'], aug.match('/files')
|
489
|
+
assert_equal 1, aug.rename('/files', 'label')
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
def test_text_store_retrieve
|
494
|
+
Augeas::create(:root => "/dev/null") do |aug|
|
495
|
+
# text_store errors
|
496
|
+
assert_raises(Augeas::NoMatchError) { aug.text_store('Simplelines.lns', '/input', '/store') }
|
497
|
+
|
498
|
+
# text_store
|
499
|
+
aug.set('/input', "line1\nline2\n")
|
500
|
+
assert aug.text_store('Simplelines.lns', '/input', '/store')
|
501
|
+
assert_equal 'line2', aug.get('/store/2')
|
502
|
+
|
503
|
+
# text_retrieve errors
|
504
|
+
assert_raises(Augeas::NoMatchError) { aug.text_retrieve('Simplelines.lns', '/unknown', '/store', '/output') }
|
505
|
+
|
506
|
+
# text_retrieve
|
507
|
+
aug.set('/store/3', 'line3')
|
508
|
+
assert aug.text_retrieve('Simplelines.lns', '/input', '/store', '/output')
|
509
|
+
assert_equal "line1\nline2\nline3\n", aug.get('/output')
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
513
|
+
def test_context
|
514
|
+
Augeas::create(:root => "/dev/null") do |aug|
|
515
|
+
aug.context = '/augeas'
|
516
|
+
assert_equal '/augeas', aug.get('/augeas/context')
|
517
|
+
assert_equal '/augeas', aug.get('context')
|
518
|
+
assert_equal '/augeas', aug.context
|
519
|
+
end
|
520
|
+
end
|
521
|
+
|
522
|
+
def test_touch
|
523
|
+
Augeas::create(:root => "/dev/null") do |aug|
|
524
|
+
assert_equal [], aug.match('/foo')
|
525
|
+
aug.touch '/foo'
|
526
|
+
assert_equal ['/foo'], aug.match('/foo')
|
527
|
+
|
528
|
+
aug.set '/foo', 'bar'
|
529
|
+
aug.touch '/foo'
|
530
|
+
assert_equal 'bar', aug.get('/foo')
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
def test_clearm
|
535
|
+
Augeas::create(:root => "/dev/null") do |aug|
|
536
|
+
aug.set('/foo/a', '1')
|
537
|
+
aug.set('/foo/b', '2')
|
538
|
+
aug.clearm('/foo', '*')
|
539
|
+
assert_nil aug.get('/foo/a')
|
540
|
+
assert_nil aug.get('/foo/b')
|
541
|
+
end
|
542
|
+
end
|
543
|
+
|
544
|
+
private
|
545
|
+
def aug_create(flags={})
|
546
|
+
if File::directory?(TST_ROOT)
|
547
|
+
FileUtils::rm_rf(TST_ROOT)
|
548
|
+
end
|
549
|
+
FileUtils::mkdir_p(TST_ROOT)
|
550
|
+
FileUtils::cp_r(SRC_ROOT, TST_ROOT)
|
551
|
+
|
552
|
+
Augeas::create({:root => TST_ROOT, :loadpath => nil}.merge(flags))
|
553
|
+
end
|
554
|
+
end
|
metadata
CHANGED
@@ -1,80 +1,59 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-augeas
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
- 1
|
10
|
-
version: 0.4.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
|
6
|
+
authors:
|
7
|
+
- Bryan Kearney
|
8
|
+
- David Lutterkort
|
14
9
|
autorequire: augeas
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-03-29 00:00:00 -07:00
|
19
|
-
default_executable:
|
12
|
+
date: 2024-08-07 00:00:00.000000000 Z
|
20
13
|
dependencies: []
|
21
|
-
|
22
14
|
description: Provides bindings for augeas.
|
23
15
|
email: augeas-devel@redhat.com
|
24
16
|
executables: []
|
25
|
-
|
26
|
-
extensions:
|
17
|
+
extensions:
|
27
18
|
- ext/augeas/extconf.rb
|
28
19
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
31
|
-
- Rakefile
|
20
|
+
files:
|
32
21
|
- COPYING
|
33
|
-
- README.rdoc
|
34
22
|
- NEWS
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
35
25
|
- ext/augeas/_augeas.c
|
36
|
-
-
|
26
|
+
- ext/augeas/_augeas.h
|
37
27
|
- ext/augeas/extconf.rb
|
38
|
-
-
|
39
|
-
-
|
28
|
+
- lib/augeas.rb
|
29
|
+
- lib/augeas/facade.rb
|
40
30
|
- tests/root/etc/group
|
31
|
+
- tests/root/etc/hosts
|
41
32
|
- tests/root/etc/inittab
|
42
33
|
- tests/root/etc/ssh/sshd_config
|
43
|
-
|
34
|
+
- tests/tc_augeas.rb
|
35
|
+
- tests/tc_facade.rb
|
44
36
|
homepage: http://augeas.net/
|
45
|
-
licenses:
|
46
|
-
|
47
|
-
|
37
|
+
licenses:
|
38
|
+
- LGPL-2.1+
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
48
41
|
rdoc_options: []
|
49
|
-
|
50
|
-
require_paths:
|
42
|
+
require_paths:
|
51
43
|
- lib
|
52
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
-
|
54
|
-
requirements:
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
55
46
|
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
hash: 53
|
58
|
-
segments:
|
59
|
-
- 1
|
60
|
-
- 8
|
61
|
-
- 1
|
47
|
+
- !ruby/object:Gem::Version
|
62
48
|
version: 1.8.1
|
63
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
-
|
65
|
-
requirements:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
66
51
|
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
segments:
|
70
|
-
- 0
|
71
|
-
version: "0"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
72
54
|
requirements: []
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
signing_key:
|
77
|
-
specification_version: 3
|
55
|
+
rubygems_version: 3.4.19
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
78
58
|
summary: Ruby bindings for augeas
|
79
59
|
test_files: []
|
80
|
-
|
data/README.rdoc
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
= Ruby bindings for augeas
|
2
|
-
|
3
|
-
The class Augeas provides bindings to augeas [http://augeas.net] library.
|
4
|
-
|
5
|
-
== Usage: Setting Data
|
6
|
-
Augeas::open do |aug|
|
7
|
-
aug.set("/files/etc/sysconfig/firstboot/RUN_FIRSTBOOT", "YES")
|
8
|
-
unless aug.save
|
9
|
-
raise IOError, "Failed to save changes"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
== Usage: Accessing Data
|
14
|
-
firstboot = Augeas::open { |aug| aug.get("/files/etc/sysconfig/firstboot/RUN_FIRSTBOOT") }
|
15
|
-
|
16
|
-
== Usage: Removing Data
|
17
|
-
Augeas::open do |aug|
|
18
|
-
aug.rm("/files/etc/sysconfig/firstboot/RUN_FIRSTBOOT")
|
19
|
-
unless aug.save
|
20
|
-
raise IOError, "Failed to save changes"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
== Usage: Minimal Setup with a Custom Root
|
25
|
-
|
26
|
-
By passing +NO_MODL_AUTOLOAD+, no files are read on startup; that allows
|
27
|
-
setting up a custom transform.
|
28
|
-
|
29
|
-
Augeas::open("/var/tmp/augeas-root", "/usr/local/share/mylenses",
|
30
|
-
Augeas::NO_MODL_AUTOLOAD) do |aug|
|
31
|
-
aug.transform(:lens => "Aliases.lns", :incl => "/etc/aliases")
|
32
|
-
aug.load
|
33
|
-
aug.get("/files/etc/aliases/*[name = 'postmaster']/value")
|
34
|
-
end
|