diff options
author | Luke Kanies <luke@madstop.com> | 2005-04-13 15:23:57 +0000 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2005-04-13 15:23:57 +0000 |
commit | 5416017c05e44fc635ad14ffdf1ac1163a4cc6e5 (patch) | |
tree | 29a33a7dd1389abde8d92219a17beead01ba1f47 /test/tc_oparse.rb | |
parent | 54e9b5e3561977ea063417da12c46aad2a4c1332 (diff) | |
download | puppet-5416017c05e44fc635ad14ffdf1ac1163a4cc6e5.tar.gz puppet-5416017c05e44fc635ad14ffdf1ac1163a4cc6e5.tar.xz puppet-5416017c05e44fc635ad14ffdf1ac1163a4cc6e5.zip |
reorganizing
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@95 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/tc_oparse.rb')
-rw-r--r-- | test/tc_oparse.rb | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/test/tc_oparse.rb b/test/tc_oparse.rb new file mode 100644 index 000000000..e737863b2 --- /dev/null +++ b/test/tc_oparse.rb @@ -0,0 +1,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 |