Sha256: 9adda33ab19034ddb7316a9709727336c90d9e21994a9a2b7275d0b60468daa4

Contents?: true

Size: 1.98 KB

Versions: 27

Compression:

Stored size: 1.98 KB

Contents

require 'webrick'
require 'webrick/https'

test_name 'dsl::helpers::web_helpers #link_exists?' do
  cert_name = [
      %w[CN localhost],
  ]
  http_cmd = "ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 80, :DocumentRoot => \"/tmp\").start' > /tmp/mylogfile 2>&1 &"
  https_cmd = "ruby -rwebrick/https -e'WEBrick::HTTPServer.new(:SSLEnable => true, :SSLCertName => #{cert_name}, :Port => 555,:DocumentRoot => \"/tmp\").start' > /tmp/mylogfile 2>&1 &"
  on(default, http_cmd)
  on(default, https_cmd)
  #allow web servers to start up
  sleep(3)
  dir = default.tmpdir('test_dir')
  file = default.tmpfile('test_file')
  dir.slice! "/tmp"
  file.slice! "/tmp"
  dst_dir = 'web_helpers'

  step '#port_open_within? can tell if a port is open' do
    assert port_open_within?(default,80)
  end

  step '#link_exists? can tell if a basic link exists' do
    assert link_exists?("http://#{default}")
  end

  step '#link_exists? can tell if a basic link does not exist' do
    assert !link_exists?("http://#{default}/test")
  end

  step '#link_exists? can use an ssl link' do
    assert link_exists?("https://#{default}:555")
  end

  step '#fetch_http_dir can fetch a dir' do
    assert_equal "#{dst_dir}#{dir}", fetch_http_dir("http://#{default}/#{dir}", dst_dir)
  end

  step '#fetch_http_dir will raise an error if unable fetch a dir' do
    exception = assert_raises(RuntimeError) { fetch_http_dir("http://#{default}/tmps", dst_dir) }
    assert_match /Failed to fetch_remote_dir.*/, exception.message, "#fetch_http_dir raised an unexpected RuntimeError"
  end

  step '#fetch_http_file can fetch a file' do
    assert_equal "#{dst_dir}#{file}", fetch_http_file("http://#{default}", file, dst_dir)
  end

  step '#fetch_http_file will raise an error if unable to fetch a file' do
    exception = assert_raises(RuntimeError) { fetch_http_file("http://#{default}", "test2.txt", dst_dir) }
    assert_match /Failed to fetch_remote_file.*/, exception.message, "#fetch_http_dir raised an unexpected RuntimeError"
  end

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
beaker-puppet-0.17.1 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.17.0 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.16.0 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.15.2 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.15.1 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.15.0 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.14.0 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.13.6 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.13.5 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.13.4 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.13.3 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.13.2 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.13.1 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.13.0 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.12.0 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.11.1 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.11.0 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.10.0 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.9.0 acceptance/tests/web_helpers_test.rb
beaker-puppet-0.8.0 acceptance/tests/web_helpers_test.rb