diff options
| author | Luke Kanies <luke@puppetlabs.com> | 2011-02-22 11:59:19 -0800 |
|---|---|---|
| committer | Luke Kanies <luke@puppetlabs.com> | 2011-02-22 11:59:19 -0800 |
| commit | 04fb6de5e2108799e47a081e5331d932fcf53109 (patch) | |
| tree | 5df833d9972067992d361accca4729c3073c1fc4 /spec/unit/interface | |
| parent | 0cbdbce0f518d43f0d0160a58dd5ec7253a5af87 (diff) | |
| download | puppet-04fb6de5e2108799e47a081e5331d932fcf53109.tar.gz puppet-04fb6de5e2108799e47a081e5331d932fcf53109.tar.xz puppet-04fb6de5e2108799e47a081e5331d932fcf53109.zip | |
Switching Interfaces to be instances
They were previously classes, which made a lot of things stupider
than they needed to be.
This will likely involve some porting, but not much.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'spec/unit/interface')
| -rw-r--r-- | spec/unit/interface/action_manager_spec.rb | 142 | ||||
| -rw-r--r-- | spec/unit/interface/facts_spec.rb | 26 | ||||
| -rw-r--r-- | spec/unit/interface/indirector_spec.rb | 61 |
3 files changed, 229 insertions, 0 deletions
diff --git a/spec/unit/interface/action_manager_spec.rb b/spec/unit/interface/action_manager_spec.rb new file mode 100644 index 000000000..b71aecaa2 --- /dev/null +++ b/spec/unit/interface/action_manager_spec.rb @@ -0,0 +1,142 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') + +# This is entirely an internal class for Interface, so we have to load it instead of our class. +require 'puppet/interface' + +class ActionManagerTester + include Puppet::Interface::ActionManager +end + +describe Puppet::Interface::ActionManager do + before do + @tester = ActionManagerTester.new + end + + describe "when included in a class" do + it "should be able to define an action" do + @tester.action(:foo) { "something "} + end + + it "should be able to list defined actions" do + @tester.action(:foo) { "something" } + @tester.action(:bar) { "something" } + + @tester.actions.should be_include(:bar) + @tester.actions.should be_include(:foo) + end + + it "should be able to indicate when an action is defined" do + @tester.action(:foo) { "something" } + @tester.should be_action(:foo) + end + end + + describe "when used to extend a class" do + before do + @tester = Class.new + @tester.extend(Puppet::Interface::ActionManager) + end + + it "should be able to define an action" do + @tester.action(:foo) { "something "} + end + + it "should be able to list defined actions" do + @tester.action(:foo) { "something" } + @tester.action(:bar) { "something" } + + @tester.actions.should be_include(:bar) + @tester.actions.should be_include(:foo) + end + + it "should be able to indicate when an action is defined" do + @tester.action(:foo) { "something" } + @tester.should be_action(:foo) + end + end + + describe "when used both at the class and instance level" do + before do + @klass = Class.new do + include Puppet::Interface::ActionManager + extend Puppet::Interface::ActionManager + end + @instance = @klass.new + end + + it "should be able to define an action at the class level" do + @klass.action(:foo) { "something "} + end + + it "should create an instance method when an action is defined at the class level" do + @klass.action(:foo) { "something" } + @instance.foo.should == "something" + end + + it "should be able to define an action at the instance level" do + @instance.action(:foo) { "something "} + end + + it "should create an instance method when an action is defined at the instance level" do + @instance.action(:foo) { "something" } + @instance.foo.should == "something" + end + + it "should be able to list actions defined at the class level" do + @klass.action(:foo) { "something" } + @klass.action(:bar) { "something" } + + @klass.actions.should be_include(:bar) + @klass.actions.should be_include(:foo) + end + + it "should be able to list actions defined at the instance level" do + @instance.action(:foo) { "something" } + @instance.action(:bar) { "something" } + + @instance.actions.should be_include(:bar) + @instance.actions.should be_include(:foo) + end + + it "should be able to list actions defined at both instance and class level" do + @klass.action(:foo) { "something" } + @instance.action(:bar) { "something" } + + @instance.actions.should be_include(:bar) + @instance.actions.should be_include(:foo) + end + + it "should be able to indicate when an action is defined at the class level" do + @klass.action(:foo) { "something" } + @instance.should be_action(:foo) + end + + it "should be able to indicate when an action is defined at the instance level" do + @klass.action(:foo) { "something" } + @instance.should be_action(:foo) + end + + it "should list actions defined in superclasses" do + @subclass = Class.new(@klass) + @instance = @subclass.new + + @klass.action(:parent) { "a" } + @subclass.action(:sub) { "a" } + @instance.action(:instance) { "a" } + + @instance.should be_action(:parent) + @instance.should be_action(:sub) + @instance.should be_action(:instance) + end + + it "should create an instance method when an action is defined in a superclass" do + @subclass = Class.new(@klass) + @instance = @subclass.new + + @klass.action(:foo) { "something" } + @instance.foo.should == "something" + end + end +end diff --git a/spec/unit/interface/facts_spec.rb b/spec/unit/interface/facts_spec.rb new file mode 100644 index 000000000..03d6410f9 --- /dev/null +++ b/spec/unit/interface/facts_spec.rb @@ -0,0 +1,26 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/facts' + +describe Puppet::Interface.interface(:facts) do + before do + @interface = Puppet::Interface.interface(:facts) + end + + it "should define an 'upload' fact" do + @interface.should be_action(:upload) + end + + it "should set its default format to :yaml" do + @interface.default_format.should == :yaml + end + + describe "when uploading" do + it "should set the terminus_class to :facter" + + it "should set the cach_eclass to :rest" + + it "should find the current certname" + end +end diff --git a/spec/unit/interface/indirector_spec.rb b/spec/unit/interface/indirector_spec.rb new file mode 100644 index 000000000..1e5ee3068 --- /dev/null +++ b/spec/unit/interface/indirector_spec.rb @@ -0,0 +1,61 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/indirector' + +describe Puppet::Interface::Indirector do + before do + @instance = Puppet::Interface::Indirector.new(:test) + + @indirection = stub 'indirection', :name => :stub_indirection + + @instance.stubs(:indirection).returns @indirection + end + + after do + Puppet::Interface.unload_interface(:test) + end + + it "should be a subclass of Interface" do + Puppet::Interface::Indirector.superclass.should equal(Puppet::Interface) + end + + it "should be able to return a list of indirections" do + Puppet::Interface::Indirector.indirections.should be_include("catalog") + end + + it "should be able to return a list of terminuses for a given indirection" do + Puppet::Interface::Indirector.terminus_classes(:catalog).should be_include("compiler") + end + + describe "as an instance" do + after { Puppet::Interface.unload_interface(:catalog) } + + it "should be able to determine its indirection" do + # Loading actions here an get, um, complicated + Puppet::Interface.stubs(:load_actions) + Puppet::Interface::Indirector.new(:catalog).indirection.should equal(Puppet::Resource::Catalog.indirection) + end + end + + [:find, :search, :save, :destroy].each do |method| + it "should define a '#{method}' action" do + Puppet::Interface::Indirector.should be_action(method) + end + + it "should just call the indirection method when the '#{method}' action is invoked" do + @instance.indirection.expects(method).with(:test, "myargs") + @instance.send(method, :test, "myargs") + end + + it "should be able to override its indirection name" do + @instance.set_indirection_name :foo + @instance.indirection_name.should == :foo + end + + it "should be able to set its terminus class" do + @instance.indirection.expects(:terminus_class=).with(:myterm) + @instance.set_terminus(:myterm) + end + end +end |
