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' do
125 it 'clones a repo' do
127 vcsrepo { "#{tmpdir}/testrepo_latest":
130 source => "file://#{tmpdir}/testrepo.git",
131 revision => 'master',
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 'with shallow clone' do
148 it 'does a shallow clone' do
150 vcsrepo { "#{tmpdir}/testrepo_shallow":
153 source => "file://#{tmpdir}/testrepo.git",
158 # Run it twice and test for idempotency
159 apply_manifest(pp, :catch_failures => true)
160 apply_manifest(pp, :catch_changes => true)
163 describe file("#{tmpdir}/testrepo_shallow/.git/shallow") do
164 it { should be_file }
168 context 'path is not empty and not a repository' do
170 shell("mkdir #{tmpdir}/not_a_repo", :acceptable_exit_codes => [0,1])
171 shell("touch #{tmpdir}/not_a_repo/file1.txt", :acceptable_exit_codes => [0,1])
174 it 'should raise an exception' do
176 vcsrepo { "#{tmpdir}/not_a_repo":
179 source => "file://#{tmpdir}/testrepo.git",
182 apply_manifest(pp, :expect_failures => true)
186 context 'with an owner' do
187 it 'clones a repo' do
189 vcsrepo { "#{tmpdir}/testrepo_owner":
192 source => "file://#{tmpdir}/testrepo.git",
197 # Run it twice and test for idempotency
198 apply_manifest(pp, :catch_failures => true)
199 apply_manifest(pp, :catch_changes => true)
202 describe file("#{tmpdir}/testrepo_owner") do
203 it { should be_directory }
204 it { should be_owned_by 'vagrant' }
208 context 'with a group' do
209 it 'clones a repo' do
211 vcsrepo { "/#{tmpdir}/testrepo_group":
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_group") do
225 it { should be_directory }
226 it { should be_grouped_into 'vagrant' }
230 context 'with excludes' do
231 it 'clones a repo' do
233 vcsrepo { "#{tmpdir}/testrepo_excludes":
236 source => "file://#{tmpdir}/testrepo.git",
237 excludes => ['exclude1.txt', 'exclude2.txt'],
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_excludes/.git/info/exclude") do
247 its(:content) { should match /exclude1.txt/ }
248 its(:content) { should match /exclude2.txt/ }
252 context 'with force' do
254 shell("mkdir -p #{tmpdir}/testrepo_force/folder")
255 shell("touch #{tmpdir}/testrepo_force/temp.txt")
258 it 'applies the manifest' do
260 vcsrepo { "#{tmpdir}/testrepo_force":
263 source => "file://#{tmpdir}/testrepo.git",
268 # Run it twice and test for idempotency
269 apply_manifest(pp, :catch_failures => true)
270 apply_manifest(pp, :catch_changes => true)
273 describe file("#{tmpdir}/testrepo_force/folder") do
274 it { should_not be_directory }
277 describe file("#{tmpdir}/testrepo_force/temp.txt") do
278 it { should_not be_file }
281 describe file("#{tmpdir}/testrepo_force/.git") do
282 it { should be_directory }
286 context 'as a user' do
288 shell("chmod 707 #{tmpdir}")
295 apply_manifest(pp, :catch_failures => true)
298 it 'applies the manifest' do
300 vcsrepo { "#{tmpdir}/testrepo_user":
303 source => "file://#{tmpdir}/testrepo.git",
308 # Run it twice and test for idempotency
309 apply_manifest(pp, :catch_failures => true)
310 apply_manifest(pp, :catch_changes => true)
313 describe file("#{tmpdir}/testrepo_user") do
314 it { should be_directory }
315 it { should be_owned_by 'testuser' }
318 describe file("#{tmpdir}/testrepo_user") do
319 it { should be_directory }
320 it { should be_grouped_into 'testuser' }
324 context 'non-origin remote name' do
325 it 'applies the manifest' do
327 vcsrepo { "#{tmpdir}/testrepo_remote":
330 source => "file://#{tmpdir}/testrepo.git",
331 remote => 'testorigin',
335 # Run it twice and test for idempotency
336 apply_manifest(pp, :catch_failures => true)
337 apply_manifest(pp, :catch_changes => true)
340 it 'remote name is "testorigin"' do
341 shell("git --git-dir=#{tmpdir}/testrepo_remote/.git remote | grep 'testorigin'")
345 pp = 'user { "testuser": ensure => absent }'
346 apply_manifest(pp, :catch_failures => true)
350 context 'as a user with ssh' do
354 user { 'testuser-ssh':
359 apply_manifest(pp, :catch_failures => true)
362 shell('mkdir -p /home/testuser-ssh/.ssh')
363 shell('ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""')
365 # copy public key to authorized_keys
366 shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys')
367 shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config')
368 shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh')
371 it 'applies the manifest' do
373 vcsrepo { "#{tmpdir}/testrepo_user_ssh":
376 source => "testuser-ssh@localhost:#{tmpdir}/testrepo.git",
377 user => 'testuser-ssh',
381 # Run it twice and test for idempotency
382 apply_manifest(pp, :catch_failures => true)
383 apply_manifest(pp, :catch_changes => true)
388 user { 'testuser-ssh':
393 apply_manifest(pp, :catch_failures => true)
397 context 'using an identity file' do
401 user { 'testuser-ssh':
406 apply_manifest(pp, :catch_failures => true)
409 shell('mkdir -p /home/testuser-ssh/.ssh')
410 shell('ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""')
412 # copy public key to authorized_keys
413 shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys')
414 shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config')
415 shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh')
418 it 'applies the manifest' do
420 vcsrepo { "#{tmpdir}/testrepo_user_ssh_id":
423 source => "testuser-ssh@localhost:#{tmpdir}/testrepo.git",
424 identity => '/home/testuser-ssh/.ssh/id_rsa',
428 # Run it twice and test for idempotency
429 apply_manifest(pp, :catch_failures => true)
430 apply_manifest(pp, :catch_changes => true)
435 user { 'testuser-ssh':
440 apply_manifest(pp, :catch_failures => true)