blob: e737863b23d9f610e930efdbfe07ff4fcad50051 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
$:.unshift '../lib' if __FILE__ == $0 # Make this library first!
require 'blink'
require 'blink/oparse'
require 'test/unit'
# $Id$
class TestOParse < Test::Unit::TestCase
def setup
Blink[:debug] = 1
@passwdtype = Blink::OParse["passwd"]
if @passwdtype.nil?
assert_nothing_raised() {
@passwdtype = Blink::OParse.newtype(
:name => "passwd",
:recordsplit => ":",
:fields => %w{name password uid gid gcos home shell},
:namevar => "name"
)
}
end
@passwdtype = Blink::OParse["passwd"]
if @passwdtype.nil?
assert_nothing_raised() {
@passwdtype = Blink::OParse.newtype(
:name => "passwd",
:recordsplit => ":",
:fields => %w{name password uid gid gcos home shell},
:namevar => "name"
)
}
end
end
def test_passwd1_nochange
file = nil
type = nil
assert_nothing_raised() {
file = @passwdtype.new("/etc/passwd")
}
assert_nothing_raised() {
file.retrieve
}
assert(file.insync?)
contents = ""
File.open("/etc/passwd") { |ofile|
ofile.each { |line|
contents += line
}
}
assert_equal(
contents,
file.to_s
)
end
def test_passwd2_change
file = nil
type = nil
Kernel.system("cp /etc/passwd /tmp/oparsepasswd")
assert_nothing_raised() {
file = @passwdtype.new("/tmp/oparsepasswd")
}
assert_nothing_raised() {
file.retrieve
}
assert(file.insync?)
assert_nothing_raised() {
file.add { |obj|
obj["name"] = "yaytest"
obj["password"] = "x"
obj["uid"] = "10000"
obj["gid"] = "10000"
obj["home"] = "/home/yaytest"
obj["gcos"] = "The Yaytest"
obj["shell"] = "/bin/sh"
}
}
assert(!file.insync?)
assert_nothing_raised() {
file.sync
}
assert(file.insync?)
assert_nothing_raised() {
file.delete("bin")
}
assert(!file.insync?)
assert_nothing_raised() {
file.sync
}
assert(file.insync?)
#Kernel.system("rm /tmp/oparsepasswd")
end
end
|