1 require 'spec_helper_acceptance'
3 tmpdir = default.tmpdir('vcsrepo')
5 describe 'clones a remote repo' do
7 my_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
8 shell("mkdir -p #{tmpdir}") # win test
9 scp_to(default, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
10 shell("cd #{tmpdir} && ./create_git_repo.sh")
14 shell("rm -rf #{tmpdir}/testrepo.git")
17 context 'get the current master HEAD' do
20 vcsrepo { "#{tmpdir}/testrepo":
23 source => "file://#{tmpdir}/testrepo.git",
27 # Run it twice and test for idempotency
28 apply_manifest(pp, :catch_failures => true)
29 apply_manifest(pp, :catch_changes => true)
32 describe file("#{tmpdir}/testrepo/.git") do
33 it { should be_directory }
36 describe file("#{tmpdir}/testrepo/.git/HEAD") do
37 it { should contain 'ref: refs/heads/master' }
41 context 'using a commit SHA' do
43 shell("git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1").stdout.chomp
47 shell("rm -rf #{tmpdir}/testrepo_sha")
52 vcsrepo { "#{tmpdir}/testrepo_sha":
55 source => "file://#{tmpdir}/testrepo.git",
60 # Run it twice and test for idempotency
61 apply_manifest(pp, :catch_failures => true)
62 apply_manifest(pp, :catch_changes => true)
65 describe file("#{tmpdir}/testrepo_sha/.git") do
66 it { should be_directory }
69 describe file("#{tmpdir}/testrepo_sha/.git/HEAD") do
70 it { should contain sha }
74 context 'using a tag' do
77 vcsrepo { "#{tmpdir}/testrepo_tag":
80 source => "file://#{tmpdir}/testrepo.git",
85 # Run it twice and test for idempotency
86 apply_manifest(pp, :catch_failures => true)
87 apply_manifest(pp, :catch_changes => true)
90 describe file("#{tmpdir}/testrepo_tag/.git") do
91 it { should be_directory }
94 it 'should have the tag as the HEAD' do
95 shell("git --git-dir=#{tmpdir}/testrepo_tag/.git name-rev HEAD | grep '0.0.2'")
99 context 'using a branch name' do
100 it 'clones a repo' do
102 vcsrepo { "#{tmpdir}/testrepo_branch":
105 source => "file://#{tmpdir}/testrepo.git",
106 revision => 'a_branch',
110 # Run it twice and test for idempotency
111 apply_manifest(pp, :catch_failures => true)
112 apply_manifest(pp, :catch_changes => true)
115 describe file("#{tmpdir}/testrepo_branch/.git") do
116 it { should be_directory }
119 describe file("#{tmpdir}/testrepo_branch/.git/HEAD") do
120 it { should contain 'ref: refs/heads/a_branch' }
124 context 'ensure latest with branch specified' do
125 it 'clones a repo' do
127 vcsrepo { "#{tmpdir}/testrepo_latest":
130 source => "file://#{tmpdir}/testrepo.git",
131 revision => 'a_branch',
135 # Run it twice and test for idempotency
136 apply_manifest(pp, :catch_failures => true)
137 apply_manifest(pp, :catch_changes => true)
140 it 'verifies the HEAD commit SHA on remote and local match' do
141 remote_commit = shell("git ls-remote file://#{tmpdir}/testrepo_latest HEAD | head -1").stdout
142 local_commit = shell("git --git-dir=#{tmpdir}/testrepo_latest/.git rev-parse HEAD").stdout.chomp
143 expect(remote_commit).to include(local_commit)
147 context 'ensure latest with branch unspecified' do
148 it 'clones a repo' do
150 vcsrepo { "#{tmpdir}/testrepo_latest":
153 source => "file://#{tmpdir}/testrepo.git",
157 # Run it twice and test for idempotency
158 apply_manifest(pp, :catch_failures => true)
159 apply_manifest(pp, :catch_changes => true)
162 it 'verifies the HEAD commit SHA on remote and local match' do
163 remote_commit = shell("git ls-remote file://#{tmpdir}/testrepo_latest HEAD | head -1").stdout
164 local_commit = shell("git --git-dir=#{tmpdir}/testrepo_latest/.git rev-parse HEAD").stdout.chomp
165 expect(remote_commit).to include(local_commit)
169 context 'with shallow clone' do
170 it 'does a shallow clone' do
172 vcsrepo { "#{tmpdir}/testrepo_shallow":
175 source => "file://#{tmpdir}/testrepo.git",
180 # Run it twice and test for idempotency
181 apply_manifest(pp, :catch_failures => true)
182 apply_manifest(pp, :catch_changes => true)
185 describe file("#{tmpdir}/testrepo_shallow/.git/shallow") do
186 it { should be_file }
190 context 'path is not empty and not a repository' do
192 shell("mkdir #{tmpdir}/not_a_repo", :acceptable_exit_codes => [0,1])
193 shell("touch #{tmpdir}/not_a_repo/file1.txt", :acceptable_exit_codes => [0,1])
196 it 'should raise an exception' do
198 vcsrepo { "#{tmpdir}/not_a_repo":
201 source => "file://#{tmpdir}/testrepo.git",
204 apply_manifest(pp, :expect_failures => true)
208 context 'with an owner' do
215 apply_manifest(pp, :catch_failures => true)
216 it 'clones a repo' do
218 vcsrepo { "#{tmpdir}/testrepo_owner":
221 source => "file://#{tmpdir}/testrepo.git",
226 # Run it twice and test for idempotency
227 apply_manifest(pp, :catch_failures => true)
228 apply_manifest(pp, :catch_changes => true)
231 describe file("#{tmpdir}/testrepo_owner") do
232 it { should be_directory }
233 it { should be_owned_by 'vagrant' }
237 context 'with a group' do
244 apply_manifest(pp, :catch_failures => true)
246 it 'clones a repo' do
248 vcsrepo { "/#{tmpdir}/testrepo_group":
251 source => "file://#{tmpdir}/testrepo.git",
256 # Run it twice and test for idempotency
257 apply_manifest(pp, :catch_failures => true)
258 apply_manifest(pp, :catch_changes => true)
261 describe file("#{tmpdir}/testrepo_group") do
262 it { should be_directory }
263 it { should be_grouped_into 'vagrant' }
267 context 'with excludes' do
268 it 'clones a repo' do
270 vcsrepo { "#{tmpdir}/testrepo_excludes":
273 source => "file://#{tmpdir}/testrepo.git",
274 excludes => ['exclude1.txt', 'exclude2.txt'],
278 # Run it twice and test for idempotency
279 apply_manifest(pp, :catch_failures => true)
280 apply_manifest(pp, :catch_changes => true)
283 describe file("#{tmpdir}/testrepo_excludes/.git/info/exclude") do
284 its(:content) { should match /exclude1.txt/ }
285 its(:content) { should match /exclude2.txt/ }
289 context 'with force' do
291 shell("mkdir -p #{tmpdir}/testrepo_force/folder")
292 shell("touch #{tmpdir}/testrepo_force/temp.txt")
295 it 'applies the manifest' do
297 vcsrepo { "#{tmpdir}/testrepo_force":
300 source => "file://#{tmpdir}/testrepo.git",
305 # Run it twice and test for idempotency
306 apply_manifest(pp, :catch_failures => true)
307 apply_manifest(pp, :catch_changes => true)
310 describe file("#{tmpdir}/testrepo_force/folder") do
311 it { should_not be_directory }
314 describe file("#{tmpdir}/testrepo_force/temp.txt") do
315 it { should_not be_file }
318 describe file("#{tmpdir}/testrepo_force/.git") do
319 it { should be_directory }
322 context 'and noop' do
324 'testrepo_already_exists'
327 shell("mkdir #{tmpdir}/#{repo_name}")
328 shell("cd #{tmpdir}/#{repo_name} && git init")
329 shell("cd #{tmpdir}/#{repo_name} && touch a && git add a && git commit -m 'a'")
332 shell("rm -rf #{tmpdir}/#{repo_name}")
335 it 'applies the manifest' do
337 vcsrepo { "#{tmpdir}/#{repo_name}":
339 source => "file://#{tmpdir}/testrepo.git",
346 apply_manifest_on(host, pp, :catch_changes => true) do |r|
347 expect(r.stdout).to match(/Noop Mode/)
353 context 'as a user' do
355 shell("chmod 707 #{tmpdir}")
362 groups => 'testuser',
366 apply_manifest(pp, :catch_failures => true)
369 it 'applies the manifest' do
371 vcsrepo { "#{tmpdir}/testrepo_user":
374 source => "file://#{tmpdir}/testrepo.git",
379 # Run it twice and test for idempotency
380 apply_manifest(pp, :catch_failures => true)
381 apply_manifest(pp, :catch_changes => true)
384 describe file("#{tmpdir}/testrepo_user") do
385 it { should be_directory }
386 it { should be_owned_by 'testuser' }
389 describe file("#{tmpdir}/testrepo_user") do
390 it { should be_directory }
391 it { should be_grouped_into 'testuser' }
395 context 'non-origin remote name' do
396 it 'applies the manifest' do
398 vcsrepo { "#{tmpdir}/testrepo_remote":
401 source => "file://#{tmpdir}/testrepo.git",
402 remote => 'testorigin',
406 # Run it twice and test for idempotency
407 apply_manifest(pp, :catch_failures => true)
408 apply_manifest(pp, :catch_changes => true)
411 it 'remote name is "testorigin"' do
412 shell("git --git-dir=#{tmpdir}/testrepo_remote/.git remote | grep 'testorigin'")
416 pp = 'user { "testuser": ensure => absent }'
417 apply_manifest(pp, :catch_failures => true)
421 context 'as a user with ssh' do
425 group { 'testuser-ssh':
428 user { 'testuser-ssh':
430 groups => 'testuser-ssh',
434 apply_manifest(pp, :catch_failures => true)
437 shell('mkdir -p /home/testuser-ssh/.ssh')
438 shell('ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""')
440 # copy public key to authorized_keys
441 shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys')
442 shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config')
443 shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh')
446 it 'applies the manifest' do
448 vcsrepo { "#{tmpdir}/testrepo_user_ssh":
451 source => "testuser-ssh@localhost:#{tmpdir}/testrepo.git",
452 user => 'testuser-ssh',
456 # Run it twice and test for idempotency
457 apply_manifest(pp, :catch_failures => true)
458 apply_manifest(pp, :catch_changes => true)
463 user { 'testuser-ssh':
468 apply_manifest(pp, :catch_failures => true)
472 context 'using an identity file' do
476 user { 'testuser-ssh':
481 apply_manifest(pp, :catch_failures => true)
484 shell('mkdir -p /home/testuser-ssh/.ssh')
485 shell('ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""')
487 # copy public key to authorized_keys
488 shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys')
489 shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config')
490 shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh')
493 it 'applies the manifest' do
495 vcsrepo { "#{tmpdir}/testrepo_user_ssh_id":
498 source => "testuser-ssh@localhost:#{tmpdir}/testrepo.git",
499 identity => '/home/testuser-ssh/.ssh/id_rsa',
503 # Run it twice and test for idempotency
504 apply_manifest(pp, :catch_failures => true)
505 apply_manifest(pp, :catch_changes => true)