Alien-SVN

 view release on metacpan or  search on metacpan

src/subversion/subversion/bindings/swig/ruby/test/test_fs.rb  view on Meta::CPAN

  def setup
    setup_basic
  end

  def teardown
    teardown_basic
  end

  def test_version
    assert_equal(Svn::Core.subr_version, Svn::Fs.version)
  end

  def assert_create
    path = File.join(@tmp_path, "fs")
    fs_type = Svn::Fs::TYPE_FSFS
    config = {Svn::Fs::CONFIG_FS_TYPE => fs_type}

    assert(!File.exist?(path))
    fs = nil
    callback = Proc.new do |t_fs|
      assert(File.exist?(path))
      assert_equal(fs_type, Svn::Fs.type(path))
      t_fs.set_warning_func do |err|
        p err
        abort
      end
      assert_equal(path, t_fs.path)
      fs = t_fs
    end
    yield(:create, [path, config], callback)

    assert(fs.closed?)
    assert_raises(Svn::Error::FsAlreadyClose) do
      fs.path
    end

    yield(:delete, [path])
    assert(!File.exist?(path))
  end

  def test_create
    assert_create do |method, args, callback|
      Svn::Fs.__send__(method, *args, &callback)
    end
  end

  def test_create_for_backward_compatibility
    assert_create do |method, args, callback|
      Svn::Fs::FileSystem.__send__(method, *args, &callback)
    end
  end

  def assert_hotcopy
    log = "sample log"
    file = "hello.txt"
    path = File.join(@wc_path, file)
    FileUtils.touch(path)

    rev = nil

    backup_path = make_context(log) do |ctx|
      ctx.add(path)
      commit_info = ctx.commit(@wc_path)
      rev = commit_info.revision

      assert_equal(log, ctx.log_message(path, rev))

      backup_path = File.join(@tmp_path, "back")
    end

    fs_path = @fs.path
    @fs.close
    @fs = nil
    @repos.close
    @repos = nil

    FileUtils.mv(fs_path, backup_path)
    FileUtils.mkdir_p(fs_path)

    make_context(log) do |ctx|
      assert_raises(Svn::Error::RaLocalReposOpenFailed) do
        ctx.log_message(path, rev)
      end

      yield(backup_path, fs_path)
      assert_equal(log, ctx.log_message(path, rev))
    end
  end

  def test_hotcopy
    assert_hotcopy do |src, dest|
      Svn::Fs.hotcopy(src, dest)
    end
  end

  def test_hotcopy_for_backward_compatibility
    assert_hotcopy do |src, dest|
      Svn::Fs::FileSystem.hotcopy(src, dest)
    end
  end

  def test_root
    log = "sample log"
    file = "sample.txt"
    src = "sample source"
    path_in_repos = "/#{file}"
    path = File.join(@wc_path, file)

    assert_nil(@fs.root.name)
    assert_equal(Svn::Core::INVALID_REVNUM, @fs.root.base_revision)

    make_context(log) do |ctx|
      FileUtils.touch(path)
      ctx.add(path)
      rev1 = ctx.commit(@wc_path).revision
      file_id1 = @fs.root.node_id(path_in_repos)

      assert_equal(rev1, @fs.root.revision)
      assert_equal(Svn::Core::NODE_FILE, @fs.root.check_path(path_in_repos))
      assert(@fs.root.file?(path_in_repos))
      assert(!@fs.root.dir?(path_in_repos))

      assert_equal([path_in_repos], @fs.root.paths_changed.keys)
      info = @fs.root.paths_changed[path_in_repos]
      assert(info.text_mod?)
      assert(info.add?)

      File.open(path, "w") {|f| f.print(src)}
      rev2 = ctx.commit(@wc_path).revision
      file_id2 = @fs.root.node_id(path_in_repos)

      assert_equal(src, @fs.root.file_contents(path_in_repos){|f| f.read})
      assert_equal(src.length, @fs.root.file_length(path_in_repos))
      assert_equal(Digest::MD5.hexdigest(src),
                   @fs.root.file_md5_checksum(path_in_repos))

      assert_equal([path_in_repos], @fs.root.paths_changed.keys)
      info = @fs.root.paths_changed[path_in_repos]
      assert(info.text_mod?)
      assert(info.modify?)

      assert_equal([path_in_repos, rev2],
                   @fs.root.node_history(file).location)
      assert_equal([path_in_repos, rev2],
                   @fs.root.node_history(file).prev.location)



( run in 0.429 second using v1.01-cache-2.11-cpan-97f6503c9c8 )