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
209 it 'clones a repo' do
211 vcsrepo { "#{tmpdir}/testrepo_owner":
214 source => "file://#{tmpdir}/testrepo.git",
219 # Run it twice and test for idempotency
220 apply_manifest(pp, :catch_failures => true)
221 apply_manifest(pp, :catch_changes => true)
224 describe file("#{tmpdir}/testrepo_owner") do
225 it { should be_directory }
226 it { should be_owned_by 'vagrant' }
230 context 'with a group' do
231 it 'clones a repo' do
233 vcsrepo { "/#{tmpdir}/testrepo_group":
236 source => "file://#{tmpdir}/testrepo.git",
241 # Run it twice and test for idempotency
242 apply_manifest(pp, :catch_failures => true)
243 apply_manifest(pp, :catch_changes => true)
246 describe file("#{tmpdir}/testrepo_group") do
247 it { should be_directory }
248 it { should be_grouped_into 'vagrant' }
252 context 'with excludes' do
253 it 'clones a repo' do
255 vcsrepo { "#{tmpdir}/testrepo_excludes":
258 source => "file://#{tmpdir}/testrepo.git",
259 excludes => ['exclude1.txt', 'exclude2.txt'],
263 # Run it twice and test for idempotency
264 apply_manifest(pp, :catch_failures => true)
265 apply_manifest(pp, :catch_changes => true)
268 describe file("#{tmpdir}/testrepo_excludes/.git/info/exclude") do
269 its(:content) { should match /exclude1.txt/ }
270 its(:content) { should match /exclude2.txt/ }
274 context 'with force' do
276 shell("mkdir -p #{tmpdir}/testrepo_force/folder")
277 shell("touch #{tmpdir}/testrepo_force/temp.txt")
280 it 'applies the manifest' do
282 vcsrepo { "#{tmpdir}/testrepo_force":
285 source => "file://#{tmpdir}/testrepo.git",
290 # Run it twice and test for idempotency
291 apply_manifest(pp, :catch_failures => true)
292 apply_manifest(pp, :catch_changes => true)
295 describe file("#{tmpdir}/testrepo_force/folder") do
296 it { should_not be_directory }
299 describe file("#{tmpdir}/testrepo_force/temp.txt") do
300 it { should_not be_file }
303 describe file("#{tmpdir}/testrepo_force/.git") do
304 it { should be_directory }
308 context 'as a user' do
310 shell("chmod 707 #{tmpdir}")
317 apply_manifest(pp, :catch_failures => true)
320 it 'applies the manifest' do
322 vcsrepo { "#{tmpdir}/testrepo_user":
325 source => "file://#{tmpdir}/testrepo.git",
330 # Run it twice and test for idempotency
331 apply_manifest(pp, :catch_failures => true)
332 apply_manifest(pp, :catch_changes => true)
335 describe file("#{tmpdir}/testrepo_user") do
336 it { should be_directory }
337 it { should be_owned_by 'testuser' }
340 describe file("#{tmpdir}/testrepo_user") do
341 it { should be_directory }
342 it { should be_grouped_into 'testuser' }
346 context 'non-origin remote name' do
347 it 'applies the manifest' do
349 vcsrepo { "#{tmpdir}/testrepo_remote":
352 source => "file://#{tmpdir}/testrepo.git",
353 remote => 'testorigin',
357 # Run it twice and test for idempotency
358 apply_manifest(pp, :catch_failures => true)
359 apply_manifest(pp, :catch_changes => true)
362 it 'remote name is "testorigin"' do
363 shell("git --git-dir=#{tmpdir}/testrepo_remote/.git remote | grep 'testorigin'")
367 pp = 'user { "testuser": ensure => absent }'
368 apply_manifest(pp, :catch_failures => true)
372 context 'as a user with ssh' do
376 user { 'testuser-ssh':
381 apply_manifest(pp, :catch_failures => true)
384 shell('mkdir -p /home/testuser-ssh/.ssh')
385 shell('ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""')
387 # copy public key to authorized_keys
388 shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys')
389 shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config')
390 shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh')
393 it 'applies the manifest' do
395 vcsrepo { "#{tmpdir}/testrepo_user_ssh":
398 source => "testuser-ssh@localhost:#{tmpdir}/testrepo.git",
399 user => 'testuser-ssh',
403 # Run it twice and test for idempotency
404 apply_manifest(pp, :catch_failures => true)
405 apply_manifest(pp, :catch_changes => true)
410 user { 'testuser-ssh':
415 apply_manifest(pp, :catch_failures => true)
419 context 'using an identity file' do
423 user { 'testuser-ssh':
428 apply_manifest(pp, :catch_failures => true)
431 shell('mkdir -p /home/testuser-ssh/.ssh')
432 shell('ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""')
434 # copy public key to authorized_keys
435 shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys')
436 shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config')
437 shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh')
440 it 'applies the manifest' do
442 vcsrepo { "#{tmpdir}/testrepo_user_ssh_id":
445 source => "testuser-ssh@localhost:#{tmpdir}/testrepo.git",
446 identity => '/home/testuser-ssh/.ssh/id_rsa',
450 # Run it twice and test for idempotency
451 apply_manifest(pp, :catch_failures => true)
452 apply_manifest(pp, :catch_changes => true)
457 user { 'testuser-ssh':
462 apply_manifest(pp, :catch_failures => true)