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 }
323 context 'as a user' do
325 shell("chmod 707 #{tmpdir}")
332 groups => 'testuser',
336 apply_manifest(pp, :catch_failures => true)
339 it 'applies the manifest' do
341 vcsrepo { "#{tmpdir}/testrepo_user":
344 source => "file://#{tmpdir}/testrepo.git",
349 # Run it twice and test for idempotency
350 apply_manifest(pp, :catch_failures => true)
351 apply_manifest(pp, :catch_changes => true)
354 describe file("#{tmpdir}/testrepo_user") do
355 it { should be_directory }
356 it { should be_owned_by 'testuser' }
359 describe file("#{tmpdir}/testrepo_user") do
360 it { should be_directory }
361 it { should be_grouped_into 'testuser' }
365 context 'non-origin remote name' do
366 it 'applies the manifest' do
368 vcsrepo { "#{tmpdir}/testrepo_remote":
371 source => "file://#{tmpdir}/testrepo.git",
372 remote => 'testorigin',
376 # Run it twice and test for idempotency
377 apply_manifest(pp, :catch_failures => true)
378 apply_manifest(pp, :catch_changes => true)
381 it 'remote name is "testorigin"' do
382 shell("git --git-dir=#{tmpdir}/testrepo_remote/.git remote | grep 'testorigin'")
386 pp = 'user { "testuser": ensure => absent }'
387 apply_manifest(pp, :catch_failures => true)
391 context 'as a user with ssh' do
395 group { 'testuser-ssh':
398 user { 'testuser-ssh':
400 groups => 'testuser-ssh',
404 apply_manifest(pp, :catch_failures => true)
407 shell('mkdir -p /home/testuser-ssh/.ssh')
408 shell('ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""')
410 # copy public key to authorized_keys
411 shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys')
412 shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config')
413 shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh')
416 it 'applies the manifest' do
418 vcsrepo { "#{tmpdir}/testrepo_user_ssh":
421 source => "testuser-ssh@localhost:#{tmpdir}/testrepo.git",
422 user => 'testuser-ssh',
426 # Run it twice and test for idempotency
427 apply_manifest(pp, :catch_failures => true)
428 apply_manifest(pp, :catch_changes => true)
433 user { 'testuser-ssh':
438 apply_manifest(pp, :catch_failures => true)
442 context 'using an identity file' do
446 user { 'testuser-ssh':
451 apply_manifest(pp, :catch_failures => true)
454 shell('mkdir -p /home/testuser-ssh/.ssh')
455 shell('ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""')
457 # copy public key to authorized_keys
458 shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys')
459 shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config')
460 shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh')
463 it 'applies the manifest' do
465 vcsrepo { "#{tmpdir}/testrepo_user_ssh_id":
468 source => "testuser-ssh@localhost:#{tmpdir}/testrepo.git",
469 identity => '/home/testuser-ssh/.ssh/id_rsa',
473 # Run it twice and test for idempotency
474 apply_manifest(pp, :catch_failures => true)
475 apply_manifest(pp, :catch_changes => true)
480 user { 'testuser-ssh':
485 apply_manifest(pp, :catch_failures => true)