diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-06-10 09:02:34 -0700 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-06-10 09:02:34 -0700 |
commit | 79c58482962bd7ddd4979a4afcd178f697fe84fa (patch) | |
tree | b39538ed8086aa229ee68dddfd9436d0dcab65c0 /spec/gitlab_projects_spec.rb | |
parent | 45881f17d06c860c8fe6a0b0441a847a63b75783 (diff) | |
parent | 45b3a3a7cda1296682a2054abf89c95a55c78f0f (diff) | |
download | gitlab-shell-79c58482962bd7ddd4979a4afcd178f697fe84fa.tar.gz |
Merge pull request #56 from smashwilson/36-logger
Logger
Diffstat (limited to 'spec/gitlab_projects_spec.rb')
-rw-r--r-- | spec/gitlab_projects_spec.rb | 77 |
1 files changed, 75 insertions, 2 deletions
diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb index d0d6764..5bcc5c8 100644 --- a/spec/gitlab_projects_spec.rb +++ b/spec/gitlab_projects_spec.rb @@ -4,6 +4,7 @@ require_relative '../lib/gitlab_projects' describe GitlabProjects do before do FileUtils.mkdir_p(tmp_repos_path) + $logger = double('logger').as_null_object end after do @@ -37,10 +38,16 @@ describe GitlabProjects do gl_projects.should_receive(:system).with(valid_cmd) gl_projects.exec end + + it "should log an add-project event" do + $logger.should_receive(:info).with("Adding project #{repo_name} at <#{tmp_repo_path}>.") + gl_projects.exec + end end describe :mv_project do let(:gl_projects) { build_gitlab_projects('mv-project', repo_name, 'repo.git') } + let(:new_repo_path) { File.join(tmp_repos_path, 'repo.git') } before do FileUtils.mkdir_p(tmp_repo_path) @@ -50,7 +57,33 @@ describe GitlabProjects do File.exists?(tmp_repo_path).should be_true gl_projects.exec File.exists?(tmp_repo_path).should be_false - File.exists?(File.join(tmp_repos_path, 'repo.git')).should be_true + File.exists?(new_repo_path).should be_true + end + + it "should fail if no destination path is provided" do + incomplete = build_gitlab_projects('mv-project', repo_name) + $logger.should_receive(:error).with("mv-project failed: no destination path provided.") + incomplete.exec.should be_false + end + + it "should fail if the source path doesn't exist" do + bad_source = build_gitlab_projects('mv-project', 'bad-src.git', 'dest.git') + $logger.should_receive(:error).with("mv-project failed: source path <#{tmp_repos_path}/bad-src.git> does not exist.") + bad_source.exec.should be_false + end + + it "should fail if the destination path already exists" do + FileUtils.mkdir_p(File.join(tmp_repos_path, 'already-exists.git')) + bad_dest = build_gitlab_projects('mv-project', repo_name, 'already-exists.git') + message = "mv-project failed: destination path <#{tmp_repos_path}/already-exists.git> already exists." + $logger.should_receive(:error).with(message) + bad_dest.exec.should be_false + end + + it "should log an mv-project event" do + message = "Moving project #{repo_name} from <#{tmp_repo_path}> to <#{new_repo_path}>." + $logger.should_receive(:info).with(message) + gl_projects.exec end end @@ -66,6 +99,11 @@ describe GitlabProjects do gl_projects.exec File.exists?(tmp_repo_path).should be_false end + + it "should log an rm-project event" do + $logger.should_receive(:info).with("Removing project #{repo_name} from <#{tmp_repo_path}>.") + gl_projects.exec + end end describe :import_project do @@ -75,6 +113,12 @@ describe GitlabProjects do gl_projects.exec File.exists?(File.join(tmp_repo_path, 'HEAD')).should be_true end + + it "should log an import-project event" do + message = "Importing project #{repo_name} from <https://github.com/randx/six.git> to <#{tmp_repo_path}>." + $logger.should_receive(:info).with(message) + gl_projects.exec + end end describe :fork_project do @@ -87,7 +131,15 @@ describe GitlabProjects do gl_projects_import.exec end + it "should not fork without a destination namespace" do + missing_arg = build_gitlab_projects('fork-project', source_repo_name) + $logger.should_receive(:error).with("fork-project failed: no destination namespace provided.") + missing_arg.exec.should be_false + end + it "should not fork into a namespace that doesn't exist" do + message = "fork-project failed: destination namespace <#{tmp_repos_path}/forked-to-namespace> does not exist." + $logger.should_receive(:error).with(message) gl_projects_fork.exec.should be_false end @@ -101,9 +153,24 @@ describe GitlabProjects do end it "should not fork if a project of the same name already exists" do - #trying to fork again should fail as the repo already exists + # create a fake project at the intended destination + FileUtils.mkdir_p(File.join(tmp_repos_path, 'forked-to-namespace', repo_name)) + + # trying to fork again should fail as the repo already exists + message = "fork-project failed: destination repository <#{tmp_repos_path}/forked-to-namespace/#{repo_name}> " + message << "already exists." + $logger.should_receive(:error).with(message) gl_projects_fork.exec.should be_false end + + it "should log a fork-project event" do + message = "Forking project from <#{File.join(tmp_repos_path, source_repo_name)}> to <#{dest_repo}>." + $logger.should_receive(:info).with(message) + + # create destination namespace + FileUtils.mkdir_p(File.join(tmp_repos_path, 'forked-to-namespace')) + gl_projects_fork.exec.should be_true + end end describe :exec do @@ -112,6 +179,12 @@ describe GitlabProjects do gitlab_projects.should_receive(:puts).with('not allowed') gitlab_projects.exec end + + it 'should log a warning for unknown commands' do + gitlab_projects = build_gitlab_projects('hurf-durf', repo_name) + $logger.should_receive(:warn).with('Attempt to execute invalid gitlab-projects command "hurf-durf".') + gitlab_projects.exec + end end def build_gitlab_projects(*args) |