3 require File.dirname(__FILE__) + '/../lib/puppettest'
6 require 'puppet/util/filetype'
9 class TestFileType < Test::Unit::TestCase
17 assert_nothing_raised {
18 type = Puppet::Util::FileType.filetype(:flat)
21 assert(type, "Could not retrieve flat filetype")
23 assert_nothing_raised {
27 text = "This is some text\n"
30 assert_nothing_raised {
34 # The base class doesn't allow a return of nil
35 assert_equal("", newtext, "Somehow got some text")
37 assert_nothing_raised {
40 assert_nothing_raised {
44 assert_equal(text, newtext, "Text was changed somehow")
46 File.open(path, "w") { |f| f.puts "someyayness" }
48 text = File.read(path)
49 assert_nothing_raised {
53 assert_equal(text, newtext, "Text was changed somehow")
56 # Make sure that modified files are backed up before they're changed.
57 def test_backup_is_called
59 File.open(path, "w") { |f| f.print 'yay' }
61 obj = Puppet::Util::FileType.filetype(:flat).new(path)
65 obj.write("something")
67 assert_equal("something", File.read(path), "File did not get changed")
72 type = Puppet::Type.type(:filebucket)
74 obj = Puppet::Util::FileType.filetype(:flat).new(path)
76 # First try it when the file does not yet exist.
77 assert_nothing_raised("Could not call backup when file does not exist") do
81 # Then create the file
82 File.open(path, "w") { |f| f.print 'one' }
84 # Then try it with no filebucket objects
85 assert_nothing_raised("Could not call backup with no buckets") do
88 puppet = type["puppet"]
89 assert(puppet, "Did not create default filebucket")
91 assert_equal("one", puppet.bucket.getfile(Digest::MD5.hexdigest(File.read(path))), "Could not get file from backup")
93 # Try it again when the default already exists
94 File.open(path, "w") { |f| f.print 'two' }
95 assert_nothing_raised("Could not call backup with no buckets") do
99 assert_equal("two", puppet.bucket.getfile(Digest::MD5.hexdigest(File.read(path))), "Could not get file from backup")
102 if Facter["operatingsystem"].value == "Darwin"
103 def test_ninfotoarray
107 assert_nothing_raised {
108 type = Puppet::Util::FileType.filetype(:netinfo)
111 assert(type, "Could not retrieve netinfo filetype")
112 %w{users groups aliases}.each do |map|
113 assert_nothing_raised {
117 assert_nothing_raised("could not read map %s" % map) {
123 assert_nothing_raised("Failed to parse %s map" % map) {
127 assert_instance_of(Array, array)
129 array.each do |record|
130 assert_instance_of(Hash, record)
131 assert(record.length != 0)