📄 test_repos.rb
字号:
require "tempfile"require "my-assertions"require "util"require "svn/core"require "svn/fs"require "svn/repos"require "svn/client"class SvnReposTest < Test::Unit::TestCase include SvnTestUtil def setup setup_basic end def teardown teardown_basic end def test_version assert_equal(Svn::Core.subr_version, Svn::Repos.version) end def test_path assert_equal(@repos_path, @repos.path) assert_equal(File.join(@repos_path, "db"), @repos.db_env) assert_equal(File.join(@repos_path, "conf"), @repos.conf_dir) assert_equal(File.join(@repos_path, "conf", "svnserve.conf"), @repos.svnserve_conf) locks_dir = File.join(@repos_path, "locks") assert_equal(locks_dir, @repos.lock_dir) assert_equal(File.join(locks_dir, "db.lock"), @repos.db_lockfile) assert_equal(File.join(locks_dir, "db-logs.lock"), @repos.db_logs_lockfile) hooks_dir = File.join(@repos_path, "hooks") assert_equal(hooks_dir, @repos.hook_dir) assert_equal(File.join(hooks_dir, "start-commit"), @repos.start_commit_hook) assert_equal(File.join(hooks_dir, "pre-commit"), @repos.pre_commit_hook) assert_equal(File.join(hooks_dir, "post-commit"), @repos.post_commit_hook) assert_equal(File.join(hooks_dir, "pre-revprop-change"), @repos.pre_revprop_change_hook) assert_equal(File.join(hooks_dir, "post-revprop-change"), @repos.post_revprop_change_hook) assert_equal(File.join(hooks_dir, "pre-lock"), @repos.pre_lock_hook) assert_equal(File.join(hooks_dir, "post-lock"), @repos.post_lock_hook) assert_equal(File.join(hooks_dir, "pre-unlock"), @repos.pre_unlock_hook) assert_equal(File.join(hooks_dir, "post-unlock"), @repos.post_unlock_hook) search_path = @repos_path assert_equal(@repos_path, Svn::Repos.find_root_path(search_path)) search_path = "#{@repos_path}/XXX" assert_equal(@repos_path, Svn::Repos.find_root_path(search_path)) search_path = "not-found" assert_equal(nil, Svn::Repos.find_root_path(search_path)) end def test_create tmp_repos_path = File.join(@tmp_path, "repos") fs_config = {Svn::Fs::CONFIG_FS_TYPE => Svn::Fs::TYPE_BDB} repos = Svn::Repos.create(tmp_repos_path, {}, fs_config) assert(File.exist?(tmp_repos_path)) fs_type_path = File.join(repos.fs.path, Svn::Fs::CONFIG_FS_TYPE) assert_equal(Svn::Fs::TYPE_BDB, File.open(fs_type_path) {|f| f.read.chop}) repos.fs.set_warning_func(&warning_func) Svn::Repos.delete(tmp_repos_path) assert(!File.exist?(tmp_repos_path)) end def test_logs log1 = "sample log1" log2 = "sample log2" log3 = "sample log3" file = "file" src = "source" path = File.join(@wc_path, file) ctx = make_context(log1) File.open(path, "w") {|f| f.print(src)} ctx.add(path) info1 = ctx.ci(@wc_path) start_rev = info1.revision ctx = make_context(log2) File.open(path, "a") {|f| f.print(src)} info2 = ctx.ci(@wc_path) ctx = make_context(log3) File.open(path, "a") {|f| f.print(src)} info3 = ctx.ci(@wc_path) end_rev = info3.revision logs = @repos.logs(file, start_rev, end_rev, end_rev - start_rev + 1) logs = logs.collect do |changed_paths, revision, author, date, message| paths = {} changed_paths.each do |key, changed_path| paths[key] = changed_path.action end [paths, revision, author, date, message] end assert_equal([ [ {"/#{file}" => "A"}, info1.revision, @author, info1.date, log1, ], [ {"/#{file}" => "M"}, info2.revision, @author, info2.date, log2, ], [ {"/#{file}" => "M"}, info3.revision, @author, info3.date, log3, ], ], logs) revs = [] @repos.file_revs(file, start_rev, end_rev) do |path, rev, *rest| revs << [path, rev] end assert_equal([ ["/#{file}", info1.revision], ["/#{file}", info2.revision], ["/#{file}", info3.revision], ], revs) rev, date, author = @repos.fs.root.committed_info("/") assert_equal(info3.revision, rev) assert_equal(info3.date, date) assert_equal(info3.author, author) end def test_hotcopy log = "sample log" file = "hello.txt" path = File.join(@wc_path, file) FileUtils.touch(path) ctx = make_context(log) ctx.add(path) commit_info = ctx.commit(@wc_path) rev = commit_info.revision assert_equal(log, ctx.log_message(path, rev)) dest_path = File.join(@tmp_path, "dest") backup_path = File.join(@tmp_path, "back") config = {} fs_config = {} repos = Svn::Repos.create(dest_path, config, fs_config) repos.fs.set_warning_func(&warning_func) FileUtils.mv(@repos.path, backup_path) FileUtils.mv(repos.path, @repos.path) assert_raises(Svn::Error::FS_NO_SUCH_REVISION) do assert_equal(log, ctx.log_message(path, rev)) end FileUtils.rm_r(@repos.path) Svn::Repos.hotcopy(backup_path, @repos.path) assert_equal(log, ctx.log_message(path, rev)) end def test_transaction log = "sample log" ctx = make_context(log) ctx.checkout(@repos_uri, @wc_path) ctx.mkdir(["#{@wc_path}/new_dir"]) prev_rev = @repos.youngest_rev past_date = Time.now @repos.transaction_for_commit(@author, log) do |txn| txn.abort end assert_equal(prev_rev, @repos.youngest_rev) assert_equal(prev_rev, @repos.dated_revision(past_date)) prev_rev = @repos.youngest_rev @repos.transaction_for_commit(@author, log) do |txn| end assert_equal(prev_rev + 1, @repos.youngest_rev) assert_equal(prev_rev, @repos.dated_revision(past_date)) assert_equal(prev_rev + 1, @repos.dated_revision(Time.now)) prev_rev = @repos.youngest_rev @repos.transaction_for_update(@author) do |txn| end assert_equal(prev_rev, @repos.youngest_rev) end def test_trace_node_locations file1 = "file1" file2 = "file2" file3 = "file3" path1 = File.join(@wc_path, file1) path2 = File.join(@wc_path, file2) path3 = File.join(@wc_path, file3) log = "sample log" ctx = make_context(log) FileUtils.touch(path1) ctx.add(path1) rev1 = ctx.ci(@wc_path).revision ctx.mv(path1, path2) rev2 = ctx.ci(@wc_path).revision ctx.cp(path2, path3) rev3 = ctx.ci(@wc_path).revision assert_equal({ rev1 => "/#{file1}", rev2 => "/#{file2}", rev3 => "/#{file2}", }, @repos.fs.trace_node_locations("/#{file2}", [rev1, rev2, rev3])) end def test_report file = "file" file2 = "file2" fs_base = "base" path = File.join(@wc_path, file) path2 = File.join(@wc_path, file2) source = "sample source" log = "sample log" ctx = make_context(log) File.open(path, "w") {|f| f.print(source)} ctx.add(path) rev = ctx.ci(@wc_path).revision assert_equal(Svn::Core::NODE_FILE, @repos.fs.root.stat(file).kind) editor = TestEditor.new @repos.report(rev, @author, fs_base, "/", nil, editor) do |baton| baton.link_path(file, file2, rev) baton.delete_path(file) end assert_equal([ :set_target_revision, :open_root, :close_directory, :close_edit, ],
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -