Sha256: 48ff3782f23a82ff616deba5ea20eb5b65c8ec5bb769329d986e56f1da6d7a65

Contents?: true

Size: 1.44 KB

Versions: 21

Compression:

Stored size: 1.44 KB

Contents

require 'puppettest'

module PuppetTest::ServerTest
  include PuppetTest
  def setup
    super

    if defined?(@@port)
      @@port += 1
    else
      @@port = 20000
    end
  end

  # create a simple manifest that just creates a file
  def mktestmanifest
    file = File.join(Puppet[:confdir], "#{(self.class.to_s + "test")}site.pp")
    #@createdfile = File.join(tmpdir, self.class.to_s + "manifesttesting" +
    #    "_#{@method_name}")
    @createdfile = tempfile

    File.open(file, "w") { |f|
      f.puts "file { \"%s\": ensure => file, mode => 755 }\n" % @createdfile
    }

    @@tmpfiles << @createdfile
    @@tmpfiles << file

    file
  end

  # create a server, forked into the background
  def mkserver(handlers = nil)
    Puppet[:name] = "puppetmasterd"
    # our default handlers
    unless handlers
      handlers = {
        :CA => {}, # so that certs autogenerate
        :Master => {
          :Manifest => mktestmanifest,
          :UseNodes => false
        },
      }
    end

    # then create the actual server
    server = nil
    assert_nothing_raised {

            server = Puppet::Network::HTTPServer::WEBrick.new(
                
        :Port => @@port,
        
        :Handlers => handlers
      )
    }

    # fork it
    spid = fork {
      trap(:INT) { server.shutdown }
      server.start
    }

    # and store its pid for killing
    @@tmppids << spid

    # give the server a chance to do its thing
    sleep 1
    spid
  end

end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
puppet-2.6.12 test/lib/puppettest/servertest.rb