(PUP-500) Test realize for realz
The realize() spec tests didn't really do much since they mocked out so close to the function itself. This calls it in a manner that puts resources in the catalog and checks that they are there. The accpetance tests for the realize function are no longer needed.
This commit is contained in:
Родитель
1190c46388
Коммит
037b55eacb
|
@ -1,25 +0,0 @@
|
|||
test_name "should realize"
|
||||
|
||||
agents.each do |agent|
|
||||
out = agent.tmpfile('should_realize')
|
||||
name = "test-#{Time.new.to_i}-host"
|
||||
|
||||
manifest = %Q{
|
||||
@host{'#{name}': ip=>'127.0.0.2', target=>'#{out}', ensure=>present}
|
||||
realize(Host['#{name}'])
|
||||
}
|
||||
|
||||
step "clean the system ready for testing"
|
||||
on agent, "rm -f #{out}"
|
||||
|
||||
step "realize the resource on the host"
|
||||
apply_manifest_on agent, manifest
|
||||
|
||||
step "verify the content of the file"
|
||||
on(agent, "cat #{out}") do
|
||||
fail_test "missing host definition" unless stdout.include? name
|
||||
end
|
||||
|
||||
step "final cleanup of the system"
|
||||
on agent, "rm -f #{out}"
|
||||
end
|
|
@ -1,24 +0,0 @@
|
|||
test_name "test that realize function takes a list"
|
||||
|
||||
agents.each do |agent|
|
||||
out = agent.tmpfile('should_realize_many')
|
||||
name = "test-#{Time.new.to_i}-host"
|
||||
|
||||
manifest = %Q{
|
||||
@host{'#{name}1': ip=>'127.0.0.2', target=>'#{out}', ensure=>present}
|
||||
@host{'#{name}2': ip=>'127.0.0.2', target=>'#{out}', ensure=>present}
|
||||
realize(Host['#{name}1'], Host['#{name}2'])
|
||||
}
|
||||
|
||||
step "clean up target system for test"
|
||||
on agent, "rm -f #{out}"
|
||||
|
||||
step "run the manifest"
|
||||
apply_manifest_on agent, manifest
|
||||
|
||||
step "verify the file output"
|
||||
on(agent, "cat #{out}") do
|
||||
fail_test "first host not found in output" unless stdout.include? "#{name}1"
|
||||
fail_test "second host not found in output" unless stdout.include? "#{name}2"
|
||||
end
|
||||
end
|
|
@ -1,53 +1,61 @@
|
|||
#! /usr/bin/env ruby
|
||||
require 'spec_helper'
|
||||
require 'matchers/resource'
|
||||
require 'puppet_spec/compiler'
|
||||
|
||||
describe "the realize function" do
|
||||
before :all do
|
||||
Puppet::Parser::Functions.autoloader.loadall
|
||||
include Matchers::Resource
|
||||
include PuppetSpec::Compiler
|
||||
|
||||
it "realizes a single, referenced resource" do
|
||||
catalog = compile_to_catalog(<<-EOM)
|
||||
@notify { testing: }
|
||||
realize(Notify[testing])
|
||||
EOM
|
||||
|
||||
expect(catalog).to have_resource("Notify[testing]")
|
||||
end
|
||||
|
||||
before :each do
|
||||
@collector = stub_everything 'collector'
|
||||
node = Puppet::Node.new('localhost')
|
||||
@compiler = Puppet::Parser::Compiler.new(node)
|
||||
@scope = Puppet::Parser::Scope.new(@compiler)
|
||||
@compiler.stubs(:add_collection).with(@collector)
|
||||
it "realizes multiple resources" do
|
||||
catalog = compile_to_catalog(<<-EOM)
|
||||
@notify { testing: }
|
||||
@notify { other: }
|
||||
realize(Notify[testing], Notify[other])
|
||||
EOM
|
||||
|
||||
expect(catalog).to have_resource("Notify[testing]")
|
||||
expect(catalog).to have_resource("Notify[other]")
|
||||
end
|
||||
|
||||
it "should exist" do
|
||||
Puppet::Parser::Functions.function("realize").should == "function_realize"
|
||||
it "realizes resources provided in arrays" do
|
||||
catalog = compile_to_catalog(<<-EOM)
|
||||
@notify { testing: }
|
||||
@notify { other: }
|
||||
realize([Notify[testing], [Notify[other]]])
|
||||
EOM
|
||||
|
||||
expect(catalog).to have_resource("Notify[testing]")
|
||||
expect(catalog).to have_resource("Notify[other]")
|
||||
end
|
||||
|
||||
it "should create a Collector when called" do
|
||||
|
||||
Puppet::Parser::Collector.expects(:new).returns(@collector)
|
||||
|
||||
@scope.function_realize(["test"])
|
||||
it "fails when the resource does not exist" do
|
||||
expect do
|
||||
compile_to_catalog(<<-EOM)
|
||||
realize(Notify[missing])
|
||||
EOM
|
||||
end.to raise_error(Puppet::Error, /Failed to realize/)
|
||||
end
|
||||
|
||||
it "should assign the passed-in resources to the collector" do
|
||||
Puppet::Parser::Collector.stubs(:new).returns(@collector)
|
||||
|
||||
@collector.expects(:resources=).with(["test"])
|
||||
|
||||
@scope.function_realize(["test"])
|
||||
it "fails when no parameters given" do
|
||||
expect do
|
||||
compile_to_catalog(<<-EOM)
|
||||
realize()
|
||||
EOM
|
||||
end.to raise_error(Puppet::Error, /Wrong number of arguments/)
|
||||
end
|
||||
|
||||
it "should flatten the resources assigned to the collector" do
|
||||
Puppet::Parser::Collector.stubs(:new).returns(@collector)
|
||||
|
||||
@collector.expects(:resources=).with(["test"])
|
||||
|
||||
@scope.function_realize([["test"]])
|
||||
it "silently does nothing when an empty array of resources is given" do
|
||||
compile_to_catalog(<<-EOM)
|
||||
realize([])
|
||||
EOM
|
||||
end
|
||||
|
||||
it "should let the compiler know this collector" do
|
||||
Puppet::Parser::Collector.stubs(:new).returns(@collector)
|
||||
@collector.stubs(:resources=).with(["test"])
|
||||
|
||||
@compiler.expects(:add_collection).with(@collector)
|
||||
|
||||
@scope.function_realize(["test"])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче