Merge pull request #145 from hunner/fix_beaker_tests
[puppet_vcsrepo.git] / spec / acceptance / beaker / git / branch_checkout / branch_checkout_https.rb
1 test_name 'C3442 - checkout a branch (https protocol)'
2
3 # Globals
4 repo_name = 'testrepo_branch_checkout'
5 branch = 'a_branch'
6
7 hosts.each do |host|
8   ruby = (host.is_pe? && '/opt/puppet/bin/ruby') || 'ruby'
9   tmpdir = host.tmpdir('vcsrepo')
10   step 'setup - create repo' do
11     install_package(host, 'git')
12     my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
13     scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir)
14     on(host, "cd #{tmpdir} && ./create_git_repo.sh")
15   end
16   step 'setup - start https server' do
17     https_daemon =<<-EOF
18     require 'webrick'
19     require 'webrick/https'
20     server = WEBrick::HTTPServer.new(
21     :Port               => 8443,
22     :DocumentRoot       => "#{tmpdir}",
23     :SSLEnable          => true,
24     :SSLVerifyClient    => OpenSSL::SSL::VERIFY_NONE,
25     :SSLCertificate     => OpenSSL::X509::Certificate.new(  File.open("#{tmpdir}/server.crt").read),
26     :SSLPrivateKey      => OpenSSL::PKey::RSA.new(          File.open("#{tmpdir}/server.key").read),
27     :SSLCertName        => [ [ "CN",WEBrick::Utils::getservername ] ])
28     WEBrick::Daemon.start
29     server.start
30     EOF
31     create_remote_file(host, '/tmp/https_daemon.rb', https_daemon)
32     #on(host, "#{ruby} /tmp/https_daemon.rb")
33   end
34
35   teardown do
36     on(host, "rm -fr #{tmpdir}")
37     on(host, "ps ax | grep '#{ruby} /tmp/https_daemon.rb' | grep -v grep | awk '{print \"kill -9 \" $1}' | sh ; sleep 1")
38   end
39
40   step 'checkout a branch with puppet' do
41     pp = <<-EOS
42     vcsrepo { "#{tmpdir}/#{repo_name}":
43       ensure => present,
44       source => "https://github.com/johnduarte/testrepo.git",
45       provider => git,
46       revision => '#{branch}',
47     }
48     EOS
49
50     apply_manifest_on(host, pp, :catch_failures => true)
51     apply_manifest_on(host, pp, :catch_changes  => true)
52   end
53
54   step "verify checkout is on the #{branch} branch" do
55     on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res|
56       fail_test('checkout not found') unless res.stdout.include? "HEAD"
57     end
58
59     on(host, "cat #{tmpdir}/#{repo_name}/.git/HEAD") do |res|
60       fail_test('branch not found') unless res.stdout.include? "ref: refs/heads/#{branch}"
61     end
62   end
63
64 end