summaryrefslogtreecommitdiff
path: root/spec/acceptance/git_clone_protocols_spec.rb
blob: 96638898e3e5d8f99ed4132542635075faa8905b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require 'spec_helper_acceptance'

hosts.each do |host|

describe 'clones a repo with git' do
  tmpdir = host.tmpdir('vcsrepo')
  before(:all) do
    pp = <<-EOS
    user { 'testuser':
      ensure => absent,
      managehome => true,
    }
    EOS
    on(host,apply_manifest(pp, :catch_failures => true))
    on(host,apply_manifest("file {'#{tmpdir}': ensure => absent}", :catch_failures => true))
    # {{{ setup
    # install git
    install_package(host, 'git')

    # create git repo
    my_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
    #shell("mkdir -p #{tmpdir}") # win test
    scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
    host.execute("cd #{tmpdir} && ./create_git_repo.sh")

    # copy ssl keys
    scp_to(host, "#{my_root}/acceptance/files/server.crt", tmpdir)
    scp_to(host, "#{my_root}/acceptance/files/server.key", tmpdir)

    # hack for non-vagrant deploys (deleteme)
    on(host,apply_manifest("user{'vagrant': ensure => present, }"))

    # create user
    pp = <<-EOS
    user { 'testuser':
      ensure => present,
      managehome => true,
    }
    EOS
    on(host,apply_manifest(pp, :catch_failures => true))

    # create ssh keys
    host.execute('mkdir -p /home/testuser/.ssh')
    host.execute('ssh-keygen -q -t rsa -f /home/testuser/.ssh/id_rsa -N ""')

    # copy public key to authorized_keys
    host.execute('cat /home/testuser/.ssh/id_rsa.pub > /home/testuser/.ssh/authorized_keys')
    host.execute('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser/.ssh/config')
    host.execute('chown -R testuser:testuser /home/testuser/.ssh')
    # }}}
  end

  after(:all) do
    # {{{ teardown
    pp = <<-EOS
    user { 'testuser':
      ensure => absent,
      managehome => true,
    }
    EOS
    on(host,apply_manifest(pp, :catch_failures => true))
    on(host,apply_manifest("file {'#{tmpdir}': ensure => absent}", :catch_failures => true))
    # }}}
  end

  after(:each) do
    on(host,apply_manifest("file {'#{tmpdir}/testrepo': ensure => absent}", :catch_failures => true))
  end

  #---------------  TESTS ----------------------#

  context 'using local protocol (file URL)' do
    it 'should have HEAD pointing to master' do
      pp = <<-EOS
      vcsrepo { "#{tmpdir}/testrepo":
        ensure => present,
        provider => git,
        source => "file://#{tmpdir}/testrepo.git",
      }
      EOS

      # Run it twice and test for idempotency
      on(host,apply_manifest(pp, :catch_failures => true))
      on(host,apply_manifest(pp, :catch_changes => true))
    end

    describe file("#{tmpdir}/testrepo/.git/HEAD") do
      it { should contain 'ref: refs/heads/master' }
    end

  end

end
end