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 | |
| 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')
| -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 | ||||
| -rw-r--r-- | spec/unit/interface_spec.rb | 99 | ||||
| -rw-r--r-- | spec/unit/puppet/provider/README.markdown | 4 | ||||
| -rw-r--r-- | spec/unit/puppet/type/README.markdown | 4 |
6 files changed, 336 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 diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb new file mode 100644 index 000000000..4fe797b6b --- /dev/null +++ b/spec/unit/interface_spec.rb @@ -0,0 +1,99 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') +require 'puppet/interface' + +describe Puppet::Interface do + after do + Puppet::Interface.unload_interface(:me) + end + + describe "at initialization" do + it "should require a name" do + Puppet::Interface.new(:me).name.should == :me + end + + it "should register itself" do + Puppet::Interface.expects(:register_interface).with { |name, inst| name == :me and inst.is_a?(Puppet::Interface) } + Puppet::Interface.new(:me) + end + + it "should load actions" do + Puppet::Interface.expects(:load_actions).with(:me) + Puppet::Interface.new(:me) + end + + it "should instance-eval any provided block" do + face = Puppet::Interface.new(:me) do + action(:something) { "foo" } + end + + face.should be_action(:something) + end + end + + it "should allow overriding of the default format" do + face = Puppet::Interface.new(:me) + face.set_default_format :foo + face.default_format.should == :foo + end + + it "should default to :pson for its format" do + Puppet::Interface.new(:me).default_format.should == :pson + end + + it "should create a class-level autoloader" do + Puppet::Interface.autoloader.should be_instance_of(Puppet::Util::Autoload) + end + + it "should define a class-level 'showconfig' action" do + Puppet::Interface.should be_action(:showconfig) + end + + it "should set any provided options" do + Puppet::Interface.new(:me, :verb => "foo").verb.should == "foo" + end + + it "should be able to register and return interfaces" do + $stderr.stubs(:puts) + face = Puppet::Interface.new(:me) + Puppet::Interface.unload_interface(:me) # to remove from the initial registration + Puppet::Interface.register_interface(:me, face) + Puppet::Interface.interface(:me).should equal(face) + end + + it "should create an associated constant when registering an interface" do + $stderr.stubs(:puts) + face = Puppet::Interface.new(:me) + Puppet::Interface.unload_interface(:me) # to remove from the initial registration + Puppet::Interface.register_interface(:me, face) + Puppet::Interface::Me.should equal(face) + end + + it "should be able to unload interfaces" do + $stderr.stubs(:puts) + face = Puppet::Interface.new(:me) + Puppet::Interface.unload_interface(:me) + Puppet::Interface.interface(:me).should be_nil + end + + it "should remove the associated constant when an interface is unregistered" do + $stderr.stubs(:puts) + face = Puppet::Interface.new(:me) + Puppet::Interface.unload_interface(:me) + lambda { Puppet::Interface.const_get("Me") }.should raise_error(NameError) + end + + it "should try to require interfaces that are not known" do + Puppet::Interface.expects(:require).with "puppet/interface/foo" + Puppet::Interface.interface(:foo) + end + + it "should not fail when requiring an interface fails" do + $stderr.stubs(:puts) + Puppet::Interface.expects(:require).with("puppet/interface/foo").raises LoadError + lambda { Puppet::Interface.interface(:foo) }.should_not raise_error + end + + it "should be able to load all actions in all search paths" +end diff --git a/spec/unit/puppet/provider/README.markdown b/spec/unit/puppet/provider/README.markdown new file mode 100644 index 000000000..702585021 --- /dev/null +++ b/spec/unit/puppet/provider/README.markdown @@ -0,0 +1,4 @@ +Provider Specs +============== + +Define specs for your providers under this directory. diff --git a/spec/unit/puppet/type/README.markdown b/spec/unit/puppet/type/README.markdown new file mode 100644 index 000000000..1ee19ac84 --- /dev/null +++ b/spec/unit/puppet/type/README.markdown @@ -0,0 +1,4 @@ +Resource Type Specs +=================== + +Define specs for your resource types in this directory. |
