class FileCacheMapTest

Constants

TestDir

Public Instance Methods

setup() click to toggle source
# File lib/puppet/vendor/rgen/test/util/file_cache_map_test.rb, line 11
def setup
  FileUtils.rm_r(Dir[TestDir+"/*"])
  # * doesn't include dot files

  FileUtils.rm_r(Dir[TestDir+"/.cache"])
  @cm = RGen::Util::FileCacheMap.new(".cache", ".test")
end
test_changed_version() click to toggle source
# File lib/puppet/vendor/rgen/test/util/file_cache_map_test.rb, line 86
def test_changed_version
  keyFile = TestDir+"/fileA"  
  File.open(keyFile, "w") {|f| f.write("somedata")}
  @cm.version_info = "123"
  @cm.store_data(keyFile, "valuedata")
  @cm.version_info = "456"
  reasons = []
  assert_equal(:invalid, @cm.load_data(keyFile, :invalidation_reasons => reasons))
  assert_equal [:keyfile_changed], reasons
end
test_changedcontent() click to toggle source
# File lib/puppet/vendor/rgen/test/util/file_cache_map_test.rb, line 67
def test_changedcontent
  keyFile = TestDir+"/fileA"
  File.open(keyFile, "w") {|f| f.write("somedata")}
  @cm.store_data(keyFile, "valuedata")
  File.open(keyFile, "a") {|f| f.write("more data")}
  reasons = []
  assert_equal(:invalid, @cm.load_data(keyFile, :invalidation_reasons => reasons))
  assert_equal [:keyfile_changed], reasons
end
test_corruptcache() click to toggle source
# File lib/puppet/vendor/rgen/test/util/file_cache_map_test.rb, line 57
def test_corruptcache
  keyFile = TestDir+"/fileA"
  File.open(keyFile, "w") {|f| f.write("somedata")}
  @cm.store_data(keyFile, "valuedata")
  File.open(TestDir+"/.cache/fileA.test","a") {|f| f.write("more data")}
  reasons = []
  assert_equal(:invalid, @cm.load_data(keyFile, :invalidation_reasons => reasons))
  assert_equal [:cachefile_corrupted], reasons
end
test_nocache() click to toggle source
# File lib/puppet/vendor/rgen/test/util/file_cache_map_test.rb, line 18
def test_nocache
  reasons = []
  assert_equal(:invalid, @cm.load_data(TestDir+"/fileA", :invalidation_reasons => reasons))
  assert_equal [:no_cachefile], reasons
end
test_storeload() click to toggle source
# File lib/puppet/vendor/rgen/test/util/file_cache_map_test.rb, line 24
def test_storeload
  keyFile = TestDir+"/fileA"  
  File.open(keyFile, "w") {|f| f.write("somedata")}
  @cm.store_data(keyFile, "valuedata")
  assert(File.exist?(TestDir+"/.cache/fileA.test"))
  assert_equal("valuedata", @cm.load_data(keyFile))
end
test_storeload_empty() click to toggle source
# File lib/puppet/vendor/rgen/test/util/file_cache_map_test.rb, line 49
def test_storeload_empty
  keyFile = TestDir+"/fileA"  
  File.open(keyFile, "w") {|f| f.write("")}
  @cm.store_data(keyFile, "valuedata")
  assert(File.exist?(TestDir+"/.cache/fileA.test"))
  assert_equal("valuedata", @cm.load_data(keyFile))
end
test_storeload_postfix() click to toggle source
# File lib/puppet/vendor/rgen/test/util/file_cache_map_test.rb, line 41
def test_storeload_postfix
  keyFile = TestDir+"/fileB.txt"  
  File.open(keyFile, "w") {|f| f.write("somedata")}
  @cm.store_data(keyFile, "valuedata")
  assert(File.exist?(TestDir+"/.cache/fileB.txt.test"))
  assert_equal("valuedata", @cm.load_data(keyFile))
end
test_storeload_subdir() click to toggle source
# File lib/puppet/vendor/rgen/test/util/file_cache_map_test.rb, line 32
def test_storeload_subdir
  keyFile = TestDir+"/subdir/fileA"
  FileUtils.mkdir(TestDir+"/subdir")
  File.open(keyFile, "w") {|f| f.write("somedata")}
  @cm.store_data(keyFile, "valuedata")
  assert(File.exist?(TestDir+"/subdir/.cache/fileA.test"))
  assert_equal("valuedata", @cm.load_data(keyFile))
end
test_versioninfo() click to toggle source
# File lib/puppet/vendor/rgen/test/util/file_cache_map_test.rb, line 77
def test_versioninfo
  keyFile = TestDir+"/fileA"  
  File.open(keyFile, "w") {|f| f.write("somedata")}
  @cm.version_info = "123"
  @cm.store_data(keyFile, "valuedata")
  assert(File.exist?(TestDir+"/.cache/fileA.test"))
  assert_equal("valuedata", @cm.load_data(keyFile))
end