X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/060d38d627bd1e51dd2b3c6e7de9af6aa7d7b6f3..ecdc08f29a97a6127cd36c71cc56683f09907289:/services/api/test/unit/commit_test.rb diff --git a/services/api/test/unit/commit_test.rb b/services/api/test/unit/commit_test.rb index ec7a0b9a5b..c5d72c3bfe 100644 --- a/services/api/test/unit/commit_test.rb +++ b/services/api/test/unit/commit_test.rb @@ -26,6 +26,14 @@ class CommitTest < ActiveSupport::TestCase end end + def must_pipe(cmd) + begin + return IO.read("|#{cmd}") + ensure + assert $?.success? + end + end + [ 'https://github.com/curoverse/arvados.git', 'http://github.com/curoverse/arvados.git', @@ -70,7 +78,7 @@ class CommitTest < ActiveSupport::TestCase 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}" + gitint = "git --git-dir #{Rails.configuration.Containers.JobsAPI.GitInternalDir}" IO.read("|#{gitint} tag -d testtag 2>/dev/null") # "no such tag", fine assert_match(/^fatal: /, IO.read("|#{gitint} show testtag 2>&1")) refute $?.success? @@ -79,6 +87,47 @@ class CommitTest < ActiveSupport::TestCase assert $?.success? end + def with_foo_repository + Dir.chdir("#{Rails.configuration.Git.Repositories}/#{repositories(:foo).uuid}") do + must_pipe("git checkout master 2>&1") + yield + end + end + + test 'tag_in_internal_repository, new non-tip sha1 in local repo' do + tag = "tag#{rand(10**10)}" + sha1 = nil + with_foo_repository do + must_pipe("git checkout -b branch-#{rand(10**10)} 2>&1") + must_pipe("echo -n #{tag.shellescape} >bar") + must_pipe("git add bar") + must_pipe("git -c user.email=x@x -c user.name=X commit -m -") + sha1 = must_pipe("git log -n1 --format=%H").strip + must_pipe("git rm bar") + must_pipe("git -c user.email=x@x -c user.name=X commit -m -") + end + Commit.tag_in_internal_repository 'active/foo', sha1, tag + gitint = "git --git-dir #{Rails.configuration.Containers.JobsAPI.GitInternalDir.shellescape}" + assert_match(/^commit /, IO.read("|#{gitint} show #{tag.shellescape}")) + assert $?.success? + end + + test 'tag_in_internal_repository, new unreferenced sha1 in local repo' do + tag = "tag#{rand(10**10)}" + sha1 = nil + with_foo_repository do + must_pipe("echo -n #{tag.shellescape} >bar") + must_pipe("git add bar") + must_pipe("git -c user.email=x@x -c user.name=X commit -m -") + sha1 = must_pipe("git log -n1 --format=%H").strip + must_pipe("git reset --hard HEAD^") + end + Commit.tag_in_internal_repository 'active/foo', sha1, tag + gitint = "git --git-dir #{Rails.configuration.Containers.JobsAPI.GitInternalDir.shellescape}" + assert_match(/^commit /, IO.read("|#{gitint} show #{tag.shellescape}")) + assert $?.success? + end + # In active/shabranchnames, "7387838c69a21827834586cc42b467ff6c63293b" is # both a commit hash, and the name of a branch that begins from that same # commit.