X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/528f9bb789c2c7f5fbf0838732d470a332292901..4e2763883588ac691da65ee316a52a052c002aa7:/services/api/test/unit/commit_test.rb?ds=sidebyside diff --git a/services/api/test/unit/commit_test.rb b/services/api/test/unit/commit_test.rb index 1b82dcfbd2..b57c23b453 100644 --- a/services/api/test/unit/commit_test.rb +++ b/services/api/test/unit/commit_test.rb @@ -29,8 +29,8 @@ class CommitTest < ActiveSupport::TestCase ].each do |url| test "find_commit_range uses fetch_remote_repository to get #{url}" do fake_gitdir = repositories(:foo).server_path - Commit.expects(:fetch_remote_repository). - once.with(Commit.cache_dir_for(url), url).returns fake_gitdir + Commit.expects(:cache_dir_for).once.with(url).returns fake_gitdir + Commit.expects(:fetch_remote_repository).once.with(fake_gitdir, url).returns true c = Commit.find_commit_range url, nil, 'master', [] refute_empty c end @@ -64,10 +64,6 @@ class CommitTest < ActiveSupport::TestCase assert_equal [], c end - test 'fetch_remote_repository finds versions' do - skip 'not written yet' - end - test 'tag_in_internal_repository creates and updates tags in internal.git' do authorize_with :active gitint = "git --git-dir #{Rails.configuration.git_internal_dir}" @@ -79,6 +75,66 @@ class CommitTest < ActiveSupport::TestCase assert $?.success? end + # In active/shabranchnames, "7387838c69a21827834586cc42b467ff6c63293b" is + # both a commit hash, and the name of a branch that begins from that same + # commit. + COMMIT_BRANCH_NAME = "7387838c69a21827834586cc42b467ff6c63293b" + # A commit that appears in the branch after 7387838c. + COMMIT_BRANCH_COMMIT_2 = "abec49829bf1758413509b7ffcab32a771b71e81" + # "738783" is another branch that starts from the above commit. + SHORT_COMMIT_BRANCH_NAME = COMMIT_BRANCH_NAME[0, 6] + # A commit that appears in branch 738783 after 7387838c. + SHORT_BRANCH_COMMIT_2 = "77e1a93093663705a63bb4d505698047e109dedd" + + test "find_commit_range min_version prefers commits over branch names" do + assert_equal([COMMIT_BRANCH_NAME], + Commit.find_commit_range("active/shabranchnames", + COMMIT_BRANCH_NAME, nil, nil)) + end + + test "find_commit_range max_version prefers commits over branch names" do + assert_equal([COMMIT_BRANCH_NAME], + Commit.find_commit_range("active/shabranchnames", + nil, COMMIT_BRANCH_NAME, nil)) + end + + test "find_commit_range min_version with short branch name" do + assert_equal([SHORT_BRANCH_COMMIT_2], + Commit.find_commit_range("active/shabranchnames", + SHORT_COMMIT_BRANCH_NAME, nil, nil)) + end + + test "find_commit_range max_version with short branch name" do + assert_equal([SHORT_BRANCH_COMMIT_2], + Commit.find_commit_range("active/shabranchnames", + nil, SHORT_COMMIT_BRANCH_NAME, nil)) + end + + test "find_commit_range min_version with disambiguated branch name" do + assert_equal([COMMIT_BRANCH_COMMIT_2], + Commit.find_commit_range("active/shabranchnames", + "heads/#{COMMIT_BRANCH_NAME}", + nil, nil)) + end + + test "find_commit_range max_version with disambiguated branch name" do + assert_equal([COMMIT_BRANCH_COMMIT_2], + Commit.find_commit_range("active/shabranchnames", nil, + "heads/#{COMMIT_BRANCH_NAME}", nil)) + end + + test "find_commit_range min_version with unambiguous short name" do + assert_equal([COMMIT_BRANCH_NAME], + Commit.find_commit_range("active/shabranchnames", + COMMIT_BRANCH_NAME[0..-2], nil, nil)) + end + + test "find_commit_range max_version with unambiguous short name" do + assert_equal([COMMIT_BRANCH_NAME], + Commit.find_commit_range("active/shabranchnames", nil, + COMMIT_BRANCH_NAME[0..-2], nil)) + end + test "find_commit_range laundry list" do authorize_with :active