📄 test_client.rb
字号:
end def test_uuid log = "sample log" ctx = make_context(log) Svn::Wc::AdmAccess.open(nil, @wc_path, false, 0) do |adm| assert_equal(ctx.uuid_from_url(@repos_uri), ctx.uuid_from_path(@wc_path, adm)) end end def test_open_ra_session log = "sample log" ctx = make_context(log) assert_instance_of(Svn::Ra::Session, ctx.open_ra_session(@repos_uri)) end def test_revprop log = "sample log" new_log = "new sample log" src = "source\n" file = "sample.txt" path = File.join(@wc_path, file) File.open(path, "w") {|f| f.print(src)} ctx = make_context(log) ctx.add(path) info = ctx.commit(@wc_path) assert_equal([ { Svn::Core::PROP_REVISION_AUTHOR => @author, Svn::Core::PROP_REVISION_DATE => info.date, Svn::Core::PROP_REVISION_LOG => log, }, info.revision ], ctx.revprop_list(@repos_uri, info.revision)) assert_equal([log, info.revision], ctx.revprop_get(Svn::Core::PROP_REVISION_LOG, @repos_uri, info.revision)) assert_equal(log, ctx.revprop(Svn::Core::PROP_REVISION_LOG, @repos_uri, info.revision)) assert_equal(info.revision, ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log, @repos_uri, info.revision)) assert_equal([new_log, info.revision], ctx.rpget(Svn::Core::PROP_REVISION_LOG, @repos_uri, info.revision)) assert_equal(new_log, ctx.rp(Svn::Core::PROP_REVISION_LOG, @repos_uri, info.revision)) assert_equal([ { Svn::Core::PROP_REVISION_AUTHOR => @author, Svn::Core::PROP_REVISION_DATE => info.date, Svn::Core::PROP_REVISION_LOG => new_log, }, info.revision ], ctx.rplist(@repos_uri, info.revision)) assert_equal(info.revision, ctx.revprop_del(Svn::Core::PROP_REVISION_LOG, @repos_uri, info.revision)) assert_equal([nil, info.revision], ctx.rpg(Svn::Core::PROP_REVISION_LOG, @repos_uri, info.revision)) assert_equal(nil, ctx.rp(Svn::Core::PROP_REVISION_LOG, @repos_uri, info.revision)) assert_equal(info.revision, ctx.rpset(Svn::Core::PROP_REVISION_LOG, new_log, @repos_uri, info.revision)) assert_equal(new_log, ctx.rp(Svn::Core::PROP_REVISION_LOG, @repos_uri, info.revision)) assert_equal(info.revision, ctx.rps(Svn::Core::PROP_REVISION_LOG, nil, @repos_uri, info.revision)) assert_equal(nil, ctx.rp(Svn::Core::PROP_REVISION_LOG, @repos_uri, info.revision)) assert_equal([ { Svn::Core::PROP_REVISION_AUTHOR => @author, Svn::Core::PROP_REVISION_DATE => info.date, }, info.revision ], ctx.rpl(@repos_uri, info.revision)) end def test_export log = "sample log" src = "source\n" file = "sample.txt" dir = "sample" dir_path = File.join(@wc_path, dir) path = File.join(dir_path, file) tmp_base_path = File.join(@tmp_path, "tmp") tmp_dir_path = File.join(tmp_base_path, dir) tmp_path = File.join(tmp_dir_path, file) ctx = make_context(log) ctx.mkdir(dir_path) File.open(path, "w") {|f| f.print(src)} ctx.add(path) rev = ctx.ci(@wc_path).revision assert_equal(rev, ctx.export(@repos_uri, tmp_base_path)) assert_equal(src, File.open(tmp_path) {|f| f.read}) end def test_ls log = "sample log" src = "source\n" file = "sample.txt" dir = "sample" dir_path = File.join(@wc_path, dir) path = File.join(@wc_path, file) ctx = make_context(log) ctx.mkdir(dir_path) File.open(path, "w") {|f| f.print(src)} ctx.add(path) rev = ctx.ci(@wc_path).revision dirents, locks = ctx.ls(@wc_path, rev) assert_equal([dir, file].sort, dirents.keys.sort) dir_dirent = dirents[dir] assert(dir_dirent.directory?) file_dirent = dirents[file] assert(file_dirent.file?) end def test_list log = "sample log" src = "source\n" file = "sample.txt" dir = "sample" prop_name = "sample-prop" prop_value = "sample value" dir_path = File.join(@wc_path, dir) path = File.join(@wc_path, file) ctx = make_context(log) ctx.mkdir(dir_path) File.open(path, "w") {|f| f.print(src)} ctx.add(path) ctx.prop_set(prop_name, prop_value, path) rev = ctx.ci(@wc_path).revision entries = [] ctx.list(@wc_path, rev) do |path, dirent, lock, abs_path| entries << [path, dirent, lock, abs_path] end paths = entries.collect do |path, dirent, lock, abs_path| [path, abs_path] end assert_equal([["", "/"], [dir, "/"], [file, "/"]].sort, paths.sort) entries.each do |path, dirent, lock, abs_path| case path when dir, "" assert(dirent.directory?) assert_false(dirent.have_props?) when file assert(dirent.file?) assert_true(dirent.have_props?) else flunk end end end def test_switch log = "sample log" trunk_src = "trunk source\n" tag_src = "tag source\n" file = "sample.txt" file = "sample.txt" trunk_dir = "trunk" tag_dir = "tags" tag_name = "0.0.1" trunk_repos_uri = "#{@repos_uri}/#{trunk_dir}" tag_repos_uri = "#{@repos_uri}/#{tag_dir}/#{tag_name}" trunk_dir_path = File.join(@wc_path, trunk_dir) tag_dir_path = File.join(@wc_path, tag_dir) tag_name_dir_path = File.join(@wc_path, tag_dir, tag_name) trunk_path = File.join(trunk_dir_path, file) tag_path = File.join(tag_name_dir_path, file) path = File.join(@wc_path, file) ctx = make_context(log) ctx.mkdir(trunk_dir_path) File.open(trunk_path, "w") {|f| f.print(trunk_src)} ctx.add(trunk_path) trunk_rev = ctx.commit(@wc_path).revision ctx.mkdir(tag_dir_path, tag_name_dir_path) File.open(tag_path, "w") {|f| f.print(tag_src)} ctx.add(tag_path) tag_rev = ctx.commit(@wc_path).revision assert_equal(youngest_rev, ctx.switch(@wc_path, trunk_repos_uri)) assert_equal(trunk_src, ctx.cat(path)) assert_equal(youngest_rev, ctx.switch(@wc_path, tag_repos_uri)) assert_equal(tag_src, ctx.cat(path)) notify_info = [] ctx.set_notify_func do |notify| notify_info << [notify.path, notify.action] end assert_equal(trunk_rev, ctx.switch(@wc_path, trunk_repos_uri, trunk_rev)) assert_equal(trunk_src, ctx.cat(path)) assert_equal([ [path, Svn::Wc::NOTIFY_UPDATE_UPDATE], [@wc_path, Svn::Wc::NOTIFY_UPDATE_UPDATE], [@wc_path, Svn::Wc::NOTIFY_UPDATE_COMPLETED], ], notify_info) notify_info.clear assert_equal(tag_rev, ctx.switch(@wc_path, tag_repos_uri, tag_rev)) assert_equal(tag_src, ctx.cat(path)) assert_equal([ [path, Svn::Wc::NOTIFY_UPDATE_UPDATE], [@wc_path, Svn::Wc::NOTIFY_UPDATE_UPDATE], [@wc_path, Svn::Wc::NOTIFY_UPDATE_COMPLETED], ], notify_info) end def test_authentication log = "sample log" src = "source\n" file = "sample.txt" path = File.join(@wc_path, file) svnserve_uri = "#{@repos_svnserve_uri}/#{file}" File.open(path, "w") {|f| f.print(src)} ctx = make_context(log) ctx.add(path) ctx.commit(@wc_path) ctx = Svn::Client::Context.new assert_raises(Svn::Error::AUTHN_NO_PROVIDER) do ctx.cat(svnserve_uri) end ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save| cred.username = "wrong-#{@author}" cred.password = @password cred.may_save = false end assert_raises(Svn::Error::RA_NOT_AUTHORIZED) do ctx.cat(svnserve_uri) end ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save| cred.username = @author cred.password = "wrong-#{@password}" cred.may_save = false end assert_raises(Svn::Error::RA_NOT_AUTHORIZED) do ctx.cat(svnserve_uri) end ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save| cred.username = @author cred.password = @password cred.may_save = false end assert_equal(src, ctx.cat(svnserve_uri)) end def test_simple_provider log = "sample log" src = "source\n" file = "sample.txt" path = File.join(@wc_path, file) svnserve_uri = "#{@repos_svnserve_uri}/#{file}" File.open(path, "w") {|f| f.print(src)} ctx = make_context(log) setup_auth_baton(ctx.auth_baton) ctx.add(path) ctx.commit(@wc_path) ctx = Svn::Client::Context.new setup_auth_baton(ctx.auth_baton) ctx.add_simple_provider assert_raises(Svn::Error::RA_NOT_AUTHORIZED) do assert_equal(src, ctx.cat(svnserve_uri)) end ctx = Svn::Client::Context.new setup_auth_baton(ctx.auth_baton) ctx.add_simple_provider ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save| cred.username = @author cred.password = @password cred.may_save = true end assert_equal(src, ctx.cat(svnserve_uri)) ctx = Svn::Client::Context.new setup_auth_baton(ctx.auth_baton) ctx.add_simple_provider assert_equal(src, ctx.cat(svnserve_uri)) end def test_windows_simple_provider return unless Svn::Core.respond_to?(:add_windows_simple_provider) log = "sample log" src = "source\n" file = "sample.txt" path = File.join(@wc_path, file) svnserve_uri = "#{@repos_svnserve_uri}/#{file}" File.open(path, "w") {|f| f.print(src)} ctx = make_context(log) setup_auth_baton(ctx.auth_baton) ctx.add(path) ctx.commit(@wc_path) ctx = Svn::Client::Context.new setup_auth_baton(ctx.auth_baton) ctx.add_windows_simple_provider assert_raises(Svn::Error::RA_NOT_AUTHORIZED) do assert_equal(src, ctx.cat(svnserve_uri)) end ctx = Svn::Client::Context.new setup_auth_baton(ctx.auth_baton) ctx.add_simple_provider ctx.add_simple_prompt_provider(0) do |cred, realm, username, may_save| cred.username = @author cred.password = @password cred.may_save = true end assert_equal(src, ctx.cat(svnserve_uri)) ctx = Svn::Client::Context.new setup_auth_baton(ctx.auth_baton) ctx.add_windows_simple_provider assert_equal(src, ctx.cat(svnserve_uri)) end def test_username_provider log = "sample log" new_log = "sample new log" src = "source\n" file = "sample.txt" path = File.join(@wc_path, file) repos_uri = "#{@repos_uri}/#{file}" File.open(path, "w") {|f| f.print(src)} ctx = make_context(log) ctx.add(path) info = ctx.commit(@wc_path) ctx = Svn::Client::Context.new setup_auth_baton(ctx.auth_baton) ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = @author ctx.add_username_provider assert_nothing_raised do ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log, repos_uri, info.revision) end ctx = Svn::Client::Context.new setup_auth_baton(ctx.auth_baton) ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = "#{@author}-NG" ctx.add_username_provider assert_raise(Svn::Error::REPOS_HOOK_FAILURE) do ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log, repos_uri, info.revision) end ctx = Svn::Client::Context.new setup_auth_baton(ctx.auth_baton) ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = nil ctx.add_username_prompt_provider(0) do |cred, realm, may_save| end assert_raise(Svn::Error::REPOS_HOOK_FAILURE) do ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log, repos_uri, info.revision) end ctx = Svn::Client::Context.new setup_auth_baton(ctx.auth_baton) ctx.auth_baton[Svn::Core::AUTH_PARAM_DEFAULT_USERNAME] = nil ctx.add_username_prompt_provider(0) do |cred, realm, may_save| cred.username = @author end assert_nothing_raised do ctx.revprop_set(Svn::Core::PROP_REVISION_LOG, new_log, repos_uri, info.revision) end end def test_add_providers ctx = Svn::Client::Context.new assert_nothing_raised do ctx.add_ssl_client_cert_file_provider ctx.add_ssl_client_cert_pw_file_provider ctx.add_ssl_server_trust_file_provider end end def test_not_new assert_raise(NoMethodError) do Svn::Client::CommitItem.new end end def test_log_msg_func_cancel log = "sample log" dir = "dir" dir_path = File.join(@wc_path, dir) ctx = make_context(log) ctx.set_log_msg_func do |items| raise Svn::Error::CANCELLED end ctx.mkdir(dir_path) assert_raise(Svn::Error::CANCELLED) do ctx.commit(@wc_path) end endend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -