|
2 | 2 | require_relative '../lib/gitlab_projects'
|
3 | 3 |
|
4 | 4 | describe GitlabProjects do
|
| 5 | + before do |
| 6 | + FileUtils.mkdir_p(tmp_repos_path) |
| 7 | + end |
| 8 | + |
| 9 | + after do |
| 10 | + FileUtils.rm_rf(tmp_repos_path) |
| 11 | + end |
| 12 | + |
5 | 13 | describe :initialize do
|
6 | 14 | before do
|
7 |
| - argv('add-project', 'gitlab-ci.git') |
| 15 | + argv('add-project', repo_name) |
8 | 16 | @gl_projects = GitlabProjects.new
|
9 | 17 | end
|
10 | 18 |
|
11 |
| - it { @gl_projects.project_name.should == 'gitlab-ci.git' } |
| 19 | + it { @gl_projects.project_name.should == repo_name } |
12 | 20 | it { @gl_projects.instance_variable_get(:@command).should == 'add-project' }
|
13 | 21 | it { @gl_projects.instance_variable_get(:@full_path).should == '/home/git/repositories/gitlab-ci.git' }
|
14 | 22 | end
|
15 | 23 |
|
16 | 24 | describe :add_project do
|
17 |
| - before do |
18 |
| - argv('add-project', 'gitlab-ci.git') |
19 |
| - @gl_projects = GitlabProjects.new |
20 |
| - @gl_projects.stub(full_path: tmp_repo_path) |
21 |
| - end |
22 |
| - |
23 |
| - after do |
24 |
| - FileUtils.rm_rf(tmp_repo_path) |
25 |
| - end |
| 25 | + let(:gl_projects) { build_gitlab_projects('add-project', repo_name) } |
26 | 26 |
|
27 | 27 | it "should create a directory" do
|
28 |
| - @gl_projects.stub(system: true) |
29 |
| - @gl_projects.send :add_project |
| 28 | + gl_projects.stub(system: true) |
| 29 | + gl_projects.exec |
30 | 30 | File.exists?(tmp_repo_path).should be_true
|
31 | 31 | end
|
32 | 32 |
|
33 | 33 | it "should receive valid cmd" do
|
34 | 34 | valid_cmd = "cd #{tmp_repo_path} && git init --bare"
|
35 | 35 | valid_cmd << " && ln -s #{ROOT_PATH}/hooks/post-receive #{tmp_repo_path}/hooks/post-receive"
|
36 | 36 | valid_cmd << " && ln -s #{ROOT_PATH}/hooks/update #{tmp_repo_path}/hooks/update"
|
37 |
| - @gl_projects.should_receive(:system).with(valid_cmd) |
38 |
| - @gl_projects.send :add_project |
| 37 | + gl_projects.should_receive(:system).with(valid_cmd) |
| 38 | + gl_projects.exec |
39 | 39 | end
|
40 | 40 | end
|
41 | 41 |
|
| 42 | + describe :rm_project do |
| 43 | + let(:gl_projects) { build_gitlab_projects('rm-project', repo_name) } |
| 44 | + |
| 45 | + before do |
| 46 | + FileUtils.mkdir_p(tmp_repo_path) |
| 47 | + end |
| 48 | + |
| 49 | + it "should remove a repo directory" do |
| 50 | + File.exists?(tmp_repo_path).should be_true |
| 51 | + gl_projects.exec |
| 52 | + File.exists?(tmp_repo_path).should be_false |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + describe :import_project do |
| 57 | + let(:gl_projects) { build_gitlab_projects('import-project', repo_name, 'https://github.com/randx/six.git') } |
| 58 | + |
| 59 | + it "should import a repo" do |
| 60 | + gl_projects.exec |
| 61 | + File.exists?(File.join(tmp_repo_path, 'HEAD')).should be_true |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + def build_gitlab_projects(*args) |
| 66 | + argv(*args) |
| 67 | + gl_projects = GitlabProjects.new |
| 68 | + gl_projects.stub(repos_path: tmp_repos_path) |
| 69 | + gl_projects.stub(full_path: tmp_repo_path) |
| 70 | + gl_projects |
| 71 | + end |
| 72 | + |
42 | 73 | def argv(*args)
|
43 | 74 | args.each_with_index do |arg, i|
|
44 | 75 | ARGV[i] = arg
|
45 | 76 | end
|
46 | 77 | end
|
47 | 78 |
|
| 79 | + def tmp_repos_path |
| 80 | + File.join(ROOT_PATH, 'tmp', 'repositories') |
| 81 | + end |
| 82 | + |
48 | 83 | def tmp_repo_path
|
49 |
| - File.join(ROOT_PATH, 'tmp', 'gitlab-ci.git') |
| 84 | + File.join(tmp_repos_path, repo_name) |
| 85 | + end |
| 86 | + |
| 87 | + def repo_name |
| 88 | + 'gitlab-ci.git' |
50 | 89 | end
|
51 | 90 | end
|
0 commit comments