Sha256: bda972f7137db2edfa46ef353130a57f9244654ca78a6213cf51e65d1ad10784

Contents?: true

Size: 1.72 KB

Versions: 10

Compression:

Stored size: 1.72 KB

Contents

require 'puppettest'
require 'puppet/network/http_server/webrick'

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], "%ssite.pp" % (self.class.to_s + "test"))
        #@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

        return 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 
        return spid
    end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
puppet-0.24.9 test/lib/puppettest/servertest.rb
puppet-0.24.0 test/lib/puppettest/servertest.rb
puppet-0.24.2 test/lib/puppettest/servertest.rb
puppet-0.24.1 test/lib/puppettest/servertest.rb
puppet-0.24.3 test/lib/puppettest/servertest.rb
puppet-0.24.4 test/lib/puppettest/servertest.rb
puppet-0.24.5 test/lib/puppettest/servertest.rb
puppet-0.24.6 test/lib/puppettest/servertest.rb
puppet-0.24.7 test/lib/puppettest/servertest.rb
puppet-0.24.8 test/lib/puppettest/servertest.rb