From 04fb6de5e2108799e47a081e5331d932fcf53109 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 22 Feb 2011 11:59:19 -0800 Subject: 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 --- spec/unit/interface/action_manager_spec.rb | 142 +++++++++++++++++++++++++++++ spec/unit/interface/facts_spec.rb | 26 ++++++ spec/unit/interface/indirector_spec.rb | 61 +++++++++++++ 3 files changed, 229 insertions(+) create mode 100644 spec/unit/interface/action_manager_spec.rb create mode 100644 spec/unit/interface/facts_spec.rb create mode 100644 spec/unit/interface/indirector_spec.rb (limited to 'spec/unit/interface') 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 -- cgit From c2715c0f20d916de0284e2d161eb5de32e508244 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 22 Feb 2011 17:13:52 -0800 Subject: Splitting the Application base class We now have an indirection_base class along with interface_base. I've also added some basic tests for most of the interfaces. Signed-off-by: Luke Kanies --- spec/unit/interface/catalog_spec.rb | 24 ++++++++++++++++++++++ spec/unit/interface/certificate_request_spec.rb | 24 ++++++++++++++++++++++ .../interface/certificate_revocation_list_spec.rb | 24 ++++++++++++++++++++++ spec/unit/interface/certificate_spec.rb | 24 ++++++++++++++++++++++ spec/unit/interface/file_spec.rb | 24 ++++++++++++++++++++++ spec/unit/interface/indirector_spec.rb | 2 -- spec/unit/interface/key_spec.rb | 24 ++++++++++++++++++++++ spec/unit/interface/node_spec.rb | 24 ++++++++++++++++++++++ spec/unit/interface/report_spec.rb | 24 ++++++++++++++++++++++ spec/unit/interface/resource_spec.rb | 24 ++++++++++++++++++++++ spec/unit/interface/resource_type_spec.rb | 24 ++++++++++++++++++++++ 11 files changed, 240 insertions(+), 2 deletions(-) create mode 100644 spec/unit/interface/catalog_spec.rb create mode 100644 spec/unit/interface/certificate_request_spec.rb create mode 100644 spec/unit/interface/certificate_revocation_list_spec.rb create mode 100644 spec/unit/interface/certificate_spec.rb create mode 100644 spec/unit/interface/file_spec.rb create mode 100644 spec/unit/interface/key_spec.rb create mode 100644 spec/unit/interface/node_spec.rb create mode 100644 spec/unit/interface/report_spec.rb create mode 100644 spec/unit/interface/resource_spec.rb create mode 100644 spec/unit/interface/resource_type_spec.rb (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/catalog_spec.rb b/spec/unit/interface/catalog_spec.rb new file mode 100644 index 000000000..8eb0040ff --- /dev/null +++ b/spec/unit/interface/catalog_spec.rb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/catalog' + +describe Puppet::Interface.interface(:catalog) do + before do + @interface = Puppet::Interface.interface(:catalog) + end + + it "should be a subclass of 'Indirection'" do + @interface.should be_instance_of(Puppet::Interface::Indirector) + end + + it "should refer to the 'catalog' indirection" do + @interface.indirection.name.should == :catalog + end + + [:find, :save, :search, :save].each do |method| + it "should have #{method} action defined" do + @interface.should be_action(method) + end + end +end diff --git a/spec/unit/interface/certificate_request_spec.rb b/spec/unit/interface/certificate_request_spec.rb new file mode 100644 index 000000000..8a613e5e5 --- /dev/null +++ b/spec/unit/interface/certificate_request_spec.rb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/certificate_request' + +describe Puppet::Interface.interface(:certificate_request) do + before do + @interface = Puppet::Interface.interface(:certificate_request) + end + + it "should be a subclass of 'Indirection'" do + @interface.should be_instance_of(Puppet::Interface::Indirector) + end + + it "should refer to the 'certificate_request' indirection" do + @interface.indirection.name.should == :certificate_request + end + + [:find, :save, :search, :save].each do |method| + it "should have #{method} action defined" do + @interface.should be_action(method) + end + end +end diff --git a/spec/unit/interface/certificate_revocation_list_spec.rb b/spec/unit/interface/certificate_revocation_list_spec.rb new file mode 100644 index 000000000..8ee341bef --- /dev/null +++ b/spec/unit/interface/certificate_revocation_list_spec.rb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/certificate_revocation_list' + +describe Puppet::Interface.interface(:certificate_revocation_list) do + before do + @interface = Puppet::Interface.interface(:certificate_revocation_list) + end + + it "should be a subclass of 'Indirection'" do + @interface.should be_instance_of(Puppet::Interface::Indirector) + end + + it "should refer to the 'certificate_revocation_list' indirection" do + @interface.indirection.name.should == :certificate_revocation_list + end + + [:find, :save, :search, :save].each do |method| + it "should have #{method} action defined" do + @interface.should be_action(method) + end + end +end diff --git a/spec/unit/interface/certificate_spec.rb b/spec/unit/interface/certificate_spec.rb new file mode 100644 index 000000000..47ddcb52e --- /dev/null +++ b/spec/unit/interface/certificate_spec.rb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/certificate' + +describe Puppet::Interface.interface(:certificate) do + before do + @interface = Puppet::Interface.interface(:certificate) + end + + it "should be a subclass of 'Indirection'" do + @interface.should be_instance_of(Puppet::Interface::Indirector) + end + + it "should refer to the 'certificate' indirection" do + @interface.indirection.name.should == :certificate + end + + [:find, :save, :search, :save].each do |method| + it "should have #{method} action defined" do + @interface.should be_action(method) + end + end +end diff --git a/spec/unit/interface/file_spec.rb b/spec/unit/interface/file_spec.rb new file mode 100644 index 000000000..fc7accf0d --- /dev/null +++ b/spec/unit/interface/file_spec.rb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/file' + +describe Puppet::Interface.interface(:file) do + before do + @interface = Puppet::Interface.interface(:file) + end + + it "should be a subclass of 'Indirection'" do + @interface.should be_instance_of(Puppet::Interface::Indirector) + end + + it "should refer to the 'file' indirection" do + @interface.indirection.name.should == :file_bucket_file + end + + [:find, :save, :search, :save].each do |method| + it "should have #{method} action defined" do + @interface.should be_action(method) + end + end +end diff --git a/spec/unit/interface/indirector_spec.rb b/spec/unit/interface/indirector_spec.rb index 1e5ee3068..645c599b3 100644 --- a/spec/unit/interface/indirector_spec.rb +++ b/spec/unit/interface/indirector_spec.rb @@ -29,8 +29,6 @@ describe Puppet::Interface::Indirector do 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) diff --git a/spec/unit/interface/key_spec.rb b/spec/unit/interface/key_spec.rb new file mode 100644 index 000000000..93a7c937c --- /dev/null +++ b/spec/unit/interface/key_spec.rb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/key' + +describe Puppet::Interface.interface(:key) do + before do + @interface = Puppet::Interface.interface(:key) + end + + it "should be a subclass of 'Indirection'" do + @interface.should be_instance_of(Puppet::Interface::Indirector) + end + + it "should refer to the 'key' indirection" do + @interface.indirection.name.should == :key + end + + [:find, :save, :search, :save].each do |method| + it "should have #{method} action defined" do + @interface.should be_action(method) + end + end +end diff --git a/spec/unit/interface/node_spec.rb b/spec/unit/interface/node_spec.rb new file mode 100644 index 000000000..afb609d2b --- /dev/null +++ b/spec/unit/interface/node_spec.rb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/node' + +describe Puppet::Interface.interface(:node) do + before do + @interface = Puppet::Interface.interface(:node) + end + + it "should be a subclass of 'Indirection'" do + @interface.should be_instance_of(Puppet::Interface::Indirector) + end + + it "should refer to the 'node' indirection" do + @interface.indirection.name.should == :node + end + + [:find, :save, :search, :save].each do |method| + it "should have #{method} action defined" do + @interface.should be_action(method) + end + end +end diff --git a/spec/unit/interface/report_spec.rb b/spec/unit/interface/report_spec.rb new file mode 100644 index 000000000..b5bee1a62 --- /dev/null +++ b/spec/unit/interface/report_spec.rb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/report' + +describe Puppet::Interface.interface(:report) do + before do + @interface = Puppet::Interface.interface(:report) + end + + it "should be a subclass of 'Indirection'" do + @interface.should be_instance_of(Puppet::Interface::Indirector) + end + + it "should refer to the 'report' indirection" do + @interface.indirection.name.should == :report + end + + [:find, :save, :search, :save].each do |method| + it "should have #{method} action defined" do + @interface.should be_action(method) + end + end +end diff --git a/spec/unit/interface/resource_spec.rb b/spec/unit/interface/resource_spec.rb new file mode 100644 index 000000000..cad45b66b --- /dev/null +++ b/spec/unit/interface/resource_spec.rb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/resource' + +describe Puppet::Interface.interface(:resource) do + before do + @interface = Puppet::Interface.interface(:resource) + end + + it "should be a subclass of 'Indirection'" do + @interface.should be_instance_of(Puppet::Interface::Indirector) + end + + it "should refer to the 'resource' indirection" do + @interface.indirection.name.should == :resource + end + + [:find, :save, :search, :save].each do |method| + it "should have #{method} action defined" do + @interface.should be_action(method) + end + end +end diff --git a/spec/unit/interface/resource_type_spec.rb b/spec/unit/interface/resource_type_spec.rb new file mode 100644 index 000000000..6c437c475 --- /dev/null +++ b/spec/unit/interface/resource_type_spec.rb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/resource_type' + +describe Puppet::Interface.interface(:resource_type) do + before do + @interface = Puppet::Interface.interface(:resource_type) + end + + it "should be a subclass of 'Indirection'" do + @interface.should be_instance_of(Puppet::Interface::Indirector) + end + + it "should refer to the 'resource_type' indirection" do + @interface.indirection.name.should == :resource_type + end + + [:find, :save, :search, :save].each do |method| + it "should have #{method} action defined" do + @interface.should be_action(method) + end + end +end -- cgit From 368210e8a8a35cf2cae509b1d357337f9958cdff Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 22 Feb 2011 17:38:04 -0800 Subject: Adding a simple "config" app Signed-off-by: Luke Kanies --- spec/unit/interface/config_spec.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 spec/unit/interface/config_spec.rb (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/config_spec.rb b/spec/unit/interface/config_spec.rb new file mode 100644 index 000000000..79c65f2ac --- /dev/null +++ b/spec/unit/interface/config_spec.rb @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/config' + +describe Puppet::Interface.interface(:config) do + before do + @interface = Puppet::Interface.interface(:config) + end + + it "should be a subclass of 'Indirection'" do + @interface.should be_instance_of(Puppet::Interface) + end + + it "should use Settings#print_config_options when asked to print" do + Puppet.settings.stubs(:puts) + Puppet.settings.expects(:print_config_options) + @interface.print + end + + it "should set 'configprint' to all desired values and call print_config_options when a specific value is provided" do + Puppet.settings.stubs(:puts) + Puppet.settings.expects(:print_config_options) + @interface.print("libdir", "ssldir") + Puppet.settings[:configprint].should == "libdir,ssldir" + end +end -- cgit From 63263a41ab361985845ef514a3d1247a41f46475 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 2 Mar 2011 17:19:36 -0800 Subject: Fixing #13 - showconfig moved to indirector I renamed it to 'info', too. It only showed indirector-related info, so this makes sense. Signed-off-by: Luke Kanies --- spec/unit/interface/indirector_spec.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/indirector_spec.rb b/spec/unit/interface/indirector_spec.rb index 645c599b3..c0b738c96 100644 --- a/spec/unit/interface/indirector_spec.rb +++ b/spec/unit/interface/indirector_spec.rb @@ -45,15 +45,19 @@ describe Puppet::Interface::Indirector do @instance.indirection.expects(method).with(:test, "myargs") @instance.send(method, :test, "myargs") end + 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 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 + it "should be able to set its terminus class" do + @instance.indirection.expects(:terminus_class=).with(:myterm) + @instance.set_terminus(:myterm) + end + + it "should define a class-level 'info' action" do + Puppet::Interface::Indirector.should be_action(:info) end end -- cgit From ece0c8e8defeec7af5aa28bb583bbb69aaba79a9 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 2 Mar 2011 17:32:07 -0800 Subject: Fixing #16 - nodes default to yaml We don't have json support for node output yet. Signed-off-by: Luke Kanies --- spec/unit/interface/node_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/node_spec.rb b/spec/unit/interface/node_spec.rb index afb609d2b..63109308d 100644 --- a/spec/unit/interface/node_spec.rb +++ b/spec/unit/interface/node_spec.rb @@ -12,6 +12,10 @@ describe Puppet::Interface.interface(:node) do @interface.should be_instance_of(Puppet::Interface::Indirector) end + it "should set its default format to :yaml" do + @interface.default_format.should == :yaml + end + it "should refer to the 'node' indirection" do @interface.indirection.name.should == :node end -- cgit From a7173dc2054c4167c71a23fb70e3ca54d07c7447 Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Mon, 21 Mar 2011 15:00:17 -0700 Subject: (#6786) Fixing a number of failing tests. The initial merge of this branch hadn't actually been run against the full suite of specs; a number of specs began failing shortly afterward. Reviewed-By: Daniel Pittman --- spec/unit/interface/catalog_spec.rb | 4 ++-- spec/unit/interface/certificate_request_spec.rb | 4 ++-- spec/unit/interface/certificate_revocation_list_spec.rb | 4 ++-- spec/unit/interface/certificate_spec.rb | 4 ++-- spec/unit/interface/config_spec.rb | 4 ++-- spec/unit/interface/facts_spec.rb | 4 ++-- spec/unit/interface/file_spec.rb | 4 ++-- spec/unit/interface/key_spec.rb | 4 ++-- spec/unit/interface/node_spec.rb | 4 ++-- spec/unit/interface/report_spec.rb | 4 ++-- spec/unit/interface/resource_spec.rb | 4 ++-- spec/unit/interface/resource_type_spec.rb | 4 ++-- 12 files changed, 24 insertions(+), 24 deletions(-) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/catalog_spec.rb b/spec/unit/interface/catalog_spec.rb index 8eb0040ff..574842754 100644 --- a/spec/unit/interface/catalog_spec.rb +++ b/spec/unit/interface/catalog_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/catalog' -describe Puppet::Interface.interface(:catalog) do +describe Puppet::Interface::Catalog do before do - @interface = Puppet::Interface.interface(:catalog) + @interface = Puppet::Interface::Catalog end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/certificate_request_spec.rb b/spec/unit/interface/certificate_request_spec.rb index 8a613e5e5..fa9e819b4 100644 --- a/spec/unit/interface/certificate_request_spec.rb +++ b/spec/unit/interface/certificate_request_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/certificate_request' -describe Puppet::Interface.interface(:certificate_request) do +describe Puppet::Interface::CertificateRequest do before do - @interface = Puppet::Interface.interface(:certificate_request) + @interface = Puppet::Interface::CertificateRequest end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/certificate_revocation_list_spec.rb b/spec/unit/interface/certificate_revocation_list_spec.rb index 8ee341bef..3fc981bd4 100644 --- a/spec/unit/interface/certificate_revocation_list_spec.rb +++ b/spec/unit/interface/certificate_revocation_list_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/certificate_revocation_list' -describe Puppet::Interface.interface(:certificate_revocation_list) do +describe Puppet::Interface::CertificateRevocationList do before do - @interface = Puppet::Interface.interface(:certificate_revocation_list) + @interface = Puppet::Interface::CertificateRevocationList end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/certificate_spec.rb b/spec/unit/interface/certificate_spec.rb index 47ddcb52e..6b5f9224b 100644 --- a/spec/unit/interface/certificate_spec.rb +++ b/spec/unit/interface/certificate_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/certificate' -describe Puppet::Interface.interface(:certificate) do +describe Puppet::Interface::Certificate do before do - @interface = Puppet::Interface.interface(:certificate) + @interface = Puppet::Interface::Certificate end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/config_spec.rb b/spec/unit/interface/config_spec.rb index 79c65f2ac..683e8abae 100644 --- a/spec/unit/interface/config_spec.rb +++ b/spec/unit/interface/config_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/config' -describe Puppet::Interface.interface(:config) do +describe Puppet::Interface::Config do before do - @interface = Puppet::Interface.interface(:config) + @interface = Puppet::Interface::Config end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/facts_spec.rb b/spec/unit/interface/facts_spec.rb index 03d6410f9..c311b5d3d 100644 --- a/spec/unit/interface/facts_spec.rb +++ b/spec/unit/interface/facts_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/facts' -describe Puppet::Interface.interface(:facts) do +describe Puppet::Interface::Facts do before do - @interface = Puppet::Interface.interface(:facts) + @interface = Puppet::Interface::Facts end it "should define an 'upload' fact" do diff --git a/spec/unit/interface/file_spec.rb b/spec/unit/interface/file_spec.rb index fc7accf0d..1d9e55752 100644 --- a/spec/unit/interface/file_spec.rb +++ b/spec/unit/interface/file_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/file' -describe Puppet::Interface.interface(:file) do +describe Puppet::Interface::File do before do - @interface = Puppet::Interface.interface(:file) + @interface = Puppet::Interface::File end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/key_spec.rb b/spec/unit/interface/key_spec.rb index 93a7c937c..9be024445 100644 --- a/spec/unit/interface/key_spec.rb +++ b/spec/unit/interface/key_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/key' -describe Puppet::Interface.interface(:key) do +describe Puppet::Interface::Key do before do - @interface = Puppet::Interface.interface(:key) + @interface = Puppet::Interface::Key end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/node_spec.rb b/spec/unit/interface/node_spec.rb index 63109308d..cfb15e38a 100644 --- a/spec/unit/interface/node_spec.rb +++ b/spec/unit/interface/node_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/node' -describe Puppet::Interface.interface(:node) do +describe Puppet::Interface::Node do before do - @interface = Puppet::Interface.interface(:node) + @interface = Puppet::Interface::Node end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/report_spec.rb b/spec/unit/interface/report_spec.rb index b5bee1a62..932fc5cc9 100644 --- a/spec/unit/interface/report_spec.rb +++ b/spec/unit/interface/report_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/report' -describe Puppet::Interface.interface(:report) do +describe Puppet::Interface::Report do before do - @interface = Puppet::Interface.interface(:report) + @interface = Puppet::Interface::Report end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/resource_spec.rb b/spec/unit/interface/resource_spec.rb index cad45b66b..b28b04310 100644 --- a/spec/unit/interface/resource_spec.rb +++ b/spec/unit/interface/resource_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/resource' -describe Puppet::Interface.interface(:resource) do +describe Puppet::Interface::Resource do before do - @interface = Puppet::Interface.interface(:resource) + @interface = Puppet::Interface::Resource end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/resource_type_spec.rb b/spec/unit/interface/resource_type_spec.rb index 6c437c475..95b9ec7f1 100644 --- a/spec/unit/interface/resource_type_spec.rb +++ b/spec/unit/interface/resource_type_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/resource_type' -describe Puppet::Interface.interface(:resource_type) do +describe Puppet::Interface::ResourceType do before do - @interface = Puppet::Interface.interface(:resource_type) + @interface = Puppet::Interface::ResourceType end it "should be a subclass of 'Indirection'" do -- cgit From 63f33d078429a9f589474f9c0778b21d82f38682 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Mon, 21 Mar 2011 14:21:53 -0700 Subject: (#6805) Add a "configurer" application This application is similar in basic functionality to the "agent" application, but implemented in terms of interfaces. It currently will retrieve facts, retrieve a catalog, apply the catalog, and submit a report. Options such as noop and daemonize are still to come. Reviewed-By: Pieter van de Bruggen --- spec/unit/interface/configurer_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/unit/interface/configurer_spec.rb (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/configurer_spec.rb b/spec/unit/interface/configurer_spec.rb new file mode 100644 index 000000000..99f5f7ad7 --- /dev/null +++ b/spec/unit/interface/configurer_spec.rb @@ -0,0 +1,25 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/configurer' +require 'puppet/indirector/catalog/rest' +require 'tempfile' + +describe Puppet::Interface::Configurer do + describe "#synchronize" do + it "should retrieve and apply a catalog and return a report" do + dirname = Dir.mktmpdir("puppetdir") + Puppet[:vardir] = dirname + Puppet[:confdir] = dirname + @catalog = Puppet::Resource::Catalog.new + @file = Puppet::Resource.new(:file, File.join(dirname, "tmp_dir_resource"), :parameters => {:ensure => :present}) + @catalog.add_resource(@file) + Puppet::Resource::Catalog::Rest.any_instance.stubs(:find).returns(@catalog) + + report = Puppet::Interface::Configurer.synchronize("foo") + + report.kind.should == "apply" + report.status.should == "changed" + end + end +end -- cgit From c2627a3229577685a5baef1796f7f5b525fed667 Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Mon, 21 Mar 2011 16:53:49 -0700 Subject: (Maint.) Remove Puppet::Interface#unload_interface Reviewed-By: Nick Lewis --- spec/unit/interface/indirector_spec.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/indirector_spec.rb b/spec/unit/interface/indirector_spec.rb index c0b738c96..c4d93ade3 100644 --- a/spec/unit/interface/indirector_spec.rb +++ b/spec/unit/interface/indirector_spec.rb @@ -12,10 +12,6 @@ describe Puppet::Interface::Indirector do @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 -- cgit From a58bf959ec49c033e0498916a09e77e303c5792e Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Tue, 22 Mar 2011 13:19:25 -0700 Subject: (#6786) Change interface storage and access. Ruby's namespace mechanism introduced a number of problems, including incorrect name resolution for common and simple cases. Given that, we've refactored back to class-level data structures with accessor methods available. The current method names are unlikely to be the final UI. Reviewed-By: Daniel Pittman --- spec/unit/interface/catalog_spec.rb | 4 ++-- spec/unit/interface/certificate_request_spec.rb | 4 ++-- spec/unit/interface/certificate_revocation_list_spec.rb | 4 ++-- spec/unit/interface/certificate_spec.rb | 4 ++-- spec/unit/interface/config_spec.rb | 4 ++-- spec/unit/interface/configurer_spec.rb | 4 ++-- spec/unit/interface/facts_spec.rb | 4 ++-- spec/unit/interface/file_spec.rb | 4 ++-- spec/unit/interface/key_spec.rb | 4 ++-- spec/unit/interface/node_spec.rb | 4 ++-- spec/unit/interface/report_spec.rb | 4 ++-- spec/unit/interface/resource_spec.rb | 4 ++-- spec/unit/interface/resource_type_spec.rb | 4 ++-- 13 files changed, 26 insertions(+), 26 deletions(-) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/catalog_spec.rb b/spec/unit/interface/catalog_spec.rb index 574842754..8eb0040ff 100644 --- a/spec/unit/interface/catalog_spec.rb +++ b/spec/unit/interface/catalog_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/catalog' -describe Puppet::Interface::Catalog do +describe Puppet::Interface.interface(:catalog) do before do - @interface = Puppet::Interface::Catalog + @interface = Puppet::Interface.interface(:catalog) end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/certificate_request_spec.rb b/spec/unit/interface/certificate_request_spec.rb index fa9e819b4..8a613e5e5 100644 --- a/spec/unit/interface/certificate_request_spec.rb +++ b/spec/unit/interface/certificate_request_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/certificate_request' -describe Puppet::Interface::CertificateRequest do +describe Puppet::Interface.interface(:certificate_request) do before do - @interface = Puppet::Interface::CertificateRequest + @interface = Puppet::Interface.interface(:certificate_request) end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/certificate_revocation_list_spec.rb b/spec/unit/interface/certificate_revocation_list_spec.rb index 3fc981bd4..8ee341bef 100644 --- a/spec/unit/interface/certificate_revocation_list_spec.rb +++ b/spec/unit/interface/certificate_revocation_list_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/certificate_revocation_list' -describe Puppet::Interface::CertificateRevocationList do +describe Puppet::Interface.interface(:certificate_revocation_list) do before do - @interface = Puppet::Interface::CertificateRevocationList + @interface = Puppet::Interface.interface(:certificate_revocation_list) end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/certificate_spec.rb b/spec/unit/interface/certificate_spec.rb index 6b5f9224b..47ddcb52e 100644 --- a/spec/unit/interface/certificate_spec.rb +++ b/spec/unit/interface/certificate_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/certificate' -describe Puppet::Interface::Certificate do +describe Puppet::Interface.interface(:certificate) do before do - @interface = Puppet::Interface::Certificate + @interface = Puppet::Interface.interface(:certificate) end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/config_spec.rb b/spec/unit/interface/config_spec.rb index 683e8abae..79c65f2ac 100644 --- a/spec/unit/interface/config_spec.rb +++ b/spec/unit/interface/config_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/config' -describe Puppet::Interface::Config do +describe Puppet::Interface.interface(:config) do before do - @interface = Puppet::Interface::Config + @interface = Puppet::Interface.interface(:config) end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/configurer_spec.rb b/spec/unit/interface/configurer_spec.rb index 99f5f7ad7..4b3532c1b 100644 --- a/spec/unit/interface/configurer_spec.rb +++ b/spec/unit/interface/configurer_spec.rb @@ -5,7 +5,7 @@ require 'puppet/interface/configurer' require 'puppet/indirector/catalog/rest' require 'tempfile' -describe Puppet::Interface::Configurer do +describe Puppet::Interface.interface(:configurer) do describe "#synchronize" do it "should retrieve and apply a catalog and return a report" do dirname = Dir.mktmpdir("puppetdir") @@ -16,7 +16,7 @@ describe Puppet::Interface::Configurer do @catalog.add_resource(@file) Puppet::Resource::Catalog::Rest.any_instance.stubs(:find).returns(@catalog) - report = Puppet::Interface::Configurer.synchronize("foo") + report = Puppet::Interface.interface(:configurer).synchronize("foo") report.kind.should == "apply" report.status.should == "changed" diff --git a/spec/unit/interface/facts_spec.rb b/spec/unit/interface/facts_spec.rb index c311b5d3d..03d6410f9 100644 --- a/spec/unit/interface/facts_spec.rb +++ b/spec/unit/interface/facts_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/facts' -describe Puppet::Interface::Facts do +describe Puppet::Interface.interface(:facts) do before do - @interface = Puppet::Interface::Facts + @interface = Puppet::Interface.interface(:facts) end it "should define an 'upload' fact" do diff --git a/spec/unit/interface/file_spec.rb b/spec/unit/interface/file_spec.rb index 1d9e55752..fc7accf0d 100644 --- a/spec/unit/interface/file_spec.rb +++ b/spec/unit/interface/file_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/file' -describe Puppet::Interface::File do +describe Puppet::Interface.interface(:file) do before do - @interface = Puppet::Interface::File + @interface = Puppet::Interface.interface(:file) end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/key_spec.rb b/spec/unit/interface/key_spec.rb index 9be024445..93a7c937c 100644 --- a/spec/unit/interface/key_spec.rb +++ b/spec/unit/interface/key_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/key' -describe Puppet::Interface::Key do +describe Puppet::Interface.interface(:key) do before do - @interface = Puppet::Interface::Key + @interface = Puppet::Interface.interface(:key) end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/node_spec.rb b/spec/unit/interface/node_spec.rb index cfb15e38a..63109308d 100644 --- a/spec/unit/interface/node_spec.rb +++ b/spec/unit/interface/node_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/node' -describe Puppet::Interface::Node do +describe Puppet::Interface.interface(:node) do before do - @interface = Puppet::Interface::Node + @interface = Puppet::Interface.interface(:node) end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/report_spec.rb b/spec/unit/interface/report_spec.rb index 932fc5cc9..b5bee1a62 100644 --- a/spec/unit/interface/report_spec.rb +++ b/spec/unit/interface/report_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/report' -describe Puppet::Interface::Report do +describe Puppet::Interface.interface(:report) do before do - @interface = Puppet::Interface::Report + @interface = Puppet::Interface.interface(:report) end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/resource_spec.rb b/spec/unit/interface/resource_spec.rb index b28b04310..cad45b66b 100644 --- a/spec/unit/interface/resource_spec.rb +++ b/spec/unit/interface/resource_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/resource' -describe Puppet::Interface::Resource do +describe Puppet::Interface.interface(:resource) do before do - @interface = Puppet::Interface::Resource + @interface = Puppet::Interface.interface(:resource) end it "should be a subclass of 'Indirection'" do diff --git a/spec/unit/interface/resource_type_spec.rb b/spec/unit/interface/resource_type_spec.rb index 95b9ec7f1..6c437c475 100644 --- a/spec/unit/interface/resource_type_spec.rb +++ b/spec/unit/interface/resource_type_spec.rb @@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/resource_type' -describe Puppet::Interface::ResourceType do +describe Puppet::Interface.interface(:resource_type) do before do - @interface = Puppet::Interface::ResourceType + @interface = Puppet::Interface.interface(:resource_type) end it "should be a subclass of 'Indirection'" do -- cgit From e3d24865c89bccd0221f3d6d475d350f577ed3fb Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Tue, 22 Mar 2011 12:54:52 -0700 Subject: (#6814) Create a dedicated Action class This class will represents an action, and allows us to store metadata for an action, and programmatically introspect and invoke them. A helper class ActionBuilder represents the DSL for defining an action. Also defined an "invoke" DSL method to handle the functionality of defining the method for an action. Reviewed-By: Daniel Pittman --- spec/unit/interface/action_builder_spec.rb | 30 ++++++++ spec/unit/interface/action_manager_spec.rb | 113 ++++++++++++++++++++--------- spec/unit/interface/action_spec.rb | 75 +++++++++++++++++++ 3 files changed, 185 insertions(+), 33 deletions(-) create mode 100644 spec/unit/interface/action_builder_spec.rb create mode 100644 spec/unit/interface/action_spec.rb (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb new file mode 100644 index 000000000..39b2386dc --- /dev/null +++ b/spec/unit/interface/action_builder_spec.rb @@ -0,0 +1,30 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/action_builder' + +describe Puppet::Interface::ActionBuilder do + describe "::build" do + it "should build an action" do + action = Puppet::Interface::ActionBuilder.build(nil,:foo) do + end + action.should be_a(Puppet::Interface::Action) + action.name.should == "foo" + end + + it "should define a method on the interface which invokes the action" do + interface = Puppet::Interface.new(:action_builder_test_interface) + action = Puppet::Interface::ActionBuilder.build(interface, :foo) do + invoke do + "invoked the method" + end + end + + interface.foo.should == "invoked the method" + end + + it "should require a block" do + lambda { Puppet::Interface::ActionBuilder.build(nil,:foo) }.should raise_error("Action 'foo' must specify a block") + end + end +end diff --git a/spec/unit/interface/action_manager_spec.rb b/spec/unit/interface/action_manager_spec.rb index b71aecaa2..0b12db317 100644 --- a/spec/unit/interface/action_manager_spec.rb +++ b/spec/unit/interface/action_manager_spec.rb @@ -16,19 +16,28 @@ describe Puppet::Interface::ActionManager do describe "when included in a class" do it "should be able to define an action" do - @tester.action(:foo) { "something "} + @tester.action(:foo) do + invoke { "something "} + end end it "should be able to list defined actions" do - @tester.action(:foo) { "something" } - @tester.action(:bar) { "something" } + @tester.action(:foo) do + invoke { "something" } + end + @tester.action(:bar) do + invoke { "something" } + end - @tester.actions.should be_include(:bar) - @tester.actions.should be_include(:foo) + @tester.actions.should include(:bar) + @tester.actions.should include(:foo) end it "should be able to indicate when an action is defined" do - @tester.action(:foo) { "something" } + @tester.action(:foo) do + invoke { "something" } + end + @tester.should be_action(:foo) end end @@ -40,15 +49,21 @@ describe Puppet::Interface::ActionManager do end it "should be able to define an action" do - @tester.action(:foo) { "something "} + @tester.action(:foo) do + invoke { "something "} + end end it "should be able to list defined actions" do - @tester.action(:foo) { "something" } - @tester.action(:bar) { "something" } + @tester.action(:foo) do + invoke { "something" } + end + @tester.action(:bar) do + invoke { "something" } + end - @tester.actions.should be_include(:bar) - @tester.actions.should be_include(:foo) + @tester.actions.should include(:bar) + @tester.actions.should include(:foo) end it "should be able to indicate when an action is defined" do @@ -67,54 +82,78 @@ describe Puppet::Interface::ActionManager do end it "should be able to define an action at the class level" do - @klass.action(:foo) { "something "} + @klass.action(:foo) do + invoke { "something "} + end end it "should create an instance method when an action is defined at the class level" do - @klass.action(:foo) { "something" } + @klass.action(:foo) do + invoke { "something" } + end @instance.foo.should == "something" end it "should be able to define an action at the instance level" do - @instance.action(:foo) { "something "} + @instance.action(:foo) do + invoke { "something "} + end end it "should create an instance method when an action is defined at the instance level" do - @instance.action(:foo) { "something" } + @instance.action(:foo) do + invoke { "something" } + end @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.action(:foo) do + invoke { "something" } + end + @klass.action(:bar) do + invoke { "something" } + end - @klass.actions.should be_include(:bar) - @klass.actions.should be_include(:foo) + @klass.actions.should include(:bar) + @klass.actions.should 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.action(:foo) do + invoke { "something" } + end + @instance.action(:bar) do + invoke { "something" } + end - @instance.actions.should be_include(:bar) - @instance.actions.should be_include(:foo) + @instance.actions.should include(:bar) + @instance.actions.should 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" } + @klass.action(:foo) do + invoke { "something" } + end + @instance.action(:bar) do + invoke { "something" } + end - @instance.actions.should be_include(:bar) - @instance.actions.should be_include(:foo) + @instance.actions.should include(:bar) + @instance.actions.should include(:foo) end it "should be able to indicate when an action is defined at the class level" do - @klass.action(:foo) { "something" } + @klass.action(:foo) do + invoke { "something" } + end @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" } + @klass.action(:foo) do + invoke { "something" } + end @instance.should be_action(:foo) end @@ -122,9 +161,15 @@ describe Puppet::Interface::ActionManager do @subclass = Class.new(@klass) @instance = @subclass.new - @klass.action(:parent) { "a" } - @subclass.action(:sub) { "a" } - @instance.action(:instance) { "a" } + @klass.action(:parent) do + invoke { "a" } + end + @subclass.action(:sub) do + invoke { "a" } + end + @instance.action(:instance) do + invoke { "a" } + end @instance.should be_action(:parent) @instance.should be_action(:sub) @@ -135,7 +180,9 @@ describe Puppet::Interface::ActionManager do @subclass = Class.new(@klass) @instance = @subclass.new - @klass.action(:foo) { "something" } + @klass.action(:foo) do + invoke { "something" } + end @instance.foo.should == "something" end end diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb new file mode 100644 index 000000000..e74fa9fcc --- /dev/null +++ b/spec/unit/interface/action_spec.rb @@ -0,0 +1,75 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/action' + +describe Puppet::Interface::Action do + describe "when validating the action name" do + it "should require a name" do + lambda { Puppet::Interface::Action.new(nil,nil) }.should raise_error("'' is an invalid action name") + end + + it "should not allow empty names" do + lambda { Puppet::Interface::Action.new(nil,'') }.should raise_error("'' is an invalid action name") + end + + it "should not allow names with whitespace" do + lambda { Puppet::Interface::Action.new(nil,'foo bar') }.should raise_error("'foo bar' is an invalid action name") + end + + it "should not allow names beginning with dashes" do + lambda { Puppet::Interface::Action.new(nil,'-foobar') }.should raise_error("'-foobar' is an invalid action name") + end + end + + describe "when invoking" do + it "should be able to call other actions on the same object" do + interface = Puppet::Interface.new(:my_interface) do + action(:foo) do + invoke { 25 } + end + + action(:bar) do + invoke { "the value of foo is '#{foo}'" } + end + end + interface.foo.should == 25 + interface.bar.should == "the value of foo is '25'" + end + + # bar is a class action calling a class action + # quux is a class action calling an instance action + # baz is an instance action calling a class action + # qux is an instance action calling an instance action + it "should be able to call other actions on the same object when defined on a class" do + class Puppet::Interface::MyInterfaceBaseClass < Puppet::Interface + action(:foo) do + invoke { 25 } + end + + action(:bar) do + invoke { "the value of foo is '#{foo}'" } + end + + action(:quux) do + invoke { "qux told me #{qux}" } + end + end + + interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface) do + action(:baz) do + invoke { "the value of foo in baz is '#{foo}'" } + end + + action(:qux) do + invoke { baz } + end + end + interface.foo.should == 25 + interface.bar.should == "the value of foo is '25'" + interface.quux.should == "qux told me the value of foo in baz is '25'" + interface.baz.should == "the value of foo in baz is '25'" + interface.qux.should == "the value of foo in baz is '25'" + end + end +end -- cgit From 847ac203f9c0b5fce299e87a63b0de5d3ef416f6 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Tue, 22 Mar 2011 16:44:01 -0700 Subject: maint: Implement an InterfaceCollection class to manage interfaces Having an instance variable on class Interface is insufficient for Interface::Indirector. This also changes the semantics of "Interface.interface" to handle registration and loading actions, and for "Interface.new" to only instantiate an Interface. Thus, consumers of the API should typically use "Interface.interface", unless they have reasons to not want an interface automatically registered. Paired-With: Pieter van de Bruggen --- spec/unit/interface/action_manager_spec.rb | 37 ++++----- spec/unit/interface/catalog_spec.rb | 19 +---- spec/unit/interface/certificate_request_spec.rb | 19 +---- .../interface/certificate_revocation_list_spec.rb | 19 +---- spec/unit/interface/certificate_spec.rb | 19 +---- spec/unit/interface/config_spec.rb | 12 +-- spec/unit/interface/facts_spec.rb | 10 +-- spec/unit/interface/file_spec.rb | 19 +---- spec/unit/interface/indirector_spec.rb | 4 - spec/unit/interface/interface_collection_spec.rb | 97 ++++++++++++++++++++++ spec/unit/interface/key_spec.rb | 19 +---- spec/unit/interface/node_spec.rb | 22 +---- spec/unit/interface/report_spec.rb | 19 +---- spec/unit/interface/resource_spec.rb | 19 +---- spec/unit/interface/resource_type_spec.rb | 19 +---- 15 files changed, 129 insertions(+), 224 deletions(-) create mode 100644 spec/unit/interface/interface_collection_spec.rb (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/action_manager_spec.rb b/spec/unit/interface/action_manager_spec.rb index 0b12db317..bf101b344 100644 --- a/spec/unit/interface/action_manager_spec.rb +++ b/spec/unit/interface/action_manager_spec.rb @@ -10,65 +10,60 @@ class ActionManagerTester end describe Puppet::Interface::ActionManager do - before do - @tester = ActionManagerTester.new - end + subject { ActionManagerTester.new } describe "when included in a class" do it "should be able to define an action" do - @tester.action(:foo) do + subject.action(:foo) do invoke { "something "} end end it "should be able to list defined actions" do - @tester.action(:foo) do + subject.action(:foo) do invoke { "something" } end - @tester.action(:bar) do + subject.action(:bar) do invoke { "something" } end - @tester.actions.should include(:bar) - @tester.actions.should include(:foo) + subject.actions.should include(:bar) + subject.actions.should include(:foo) end it "should be able to indicate when an action is defined" do - @tester.action(:foo) do + subject.action(:foo) do invoke { "something" } end - @tester.should be_action(:foo) + subject.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 + subject { Class.new.extend(Puppet::Interface::ActionManager) } it "should be able to define an action" do - @tester.action(:foo) do + subject.action(:foo) do invoke { "something "} end end it "should be able to list defined actions" do - @tester.action(:foo) do + subject.action(:foo) do invoke { "something" } end - @tester.action(:bar) do + subject.action(:bar) do invoke { "something" } end - @tester.actions.should include(:bar) - @tester.actions.should include(:foo) + subject.actions.should include(:bar) + subject.actions.should include(:foo) end it "should be able to indicate when an action is defined" do - @tester.action(:foo) { "something" } - @tester.should be_action(:foo) + subject.action(:foo) { "something" } + subject.should be_action(:foo) end end diff --git a/spec/unit/interface/catalog_spec.rb b/spec/unit/interface/catalog_spec.rb index 8eb0040ff..78d62110f 100644 --- a/spec/unit/interface/catalog_spec.rb +++ b/spec/unit/interface/catalog_spec.rb @@ -3,22 +3,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/catalog' -describe Puppet::Interface.interface(:catalog) do - before do - @interface = Puppet::Interface.interface(:catalog) - end - - it "should be a subclass of 'Indirection'" do - @interface.should be_instance_of(Puppet::Interface::Indirector) - end - - it "should refer to the 'catalog' indirection" do - @interface.indirection.name.should == :catalog - end - - [:find, :save, :search, :save].each do |method| - it "should have #{method} action defined" do - @interface.should be_action(method) - end - end +describe Puppet::Interface::Indirector.interface(:catalog) do end diff --git a/spec/unit/interface/certificate_request_spec.rb b/spec/unit/interface/certificate_request_spec.rb index 8a613e5e5..a6ab8d17e 100644 --- a/spec/unit/interface/certificate_request_spec.rb +++ b/spec/unit/interface/certificate_request_spec.rb @@ -3,22 +3,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/certificate_request' -describe Puppet::Interface.interface(:certificate_request) do - before do - @interface = Puppet::Interface.interface(:certificate_request) - end - - it "should be a subclass of 'Indirection'" do - @interface.should be_instance_of(Puppet::Interface::Indirector) - end - - it "should refer to the 'certificate_request' indirection" do - @interface.indirection.name.should == :certificate_request - end - - [:find, :save, :search, :save].each do |method| - it "should have #{method} action defined" do - @interface.should be_action(method) - end - end +describe Puppet::Interface::Indirector.interface(:certificate_request) do end diff --git a/spec/unit/interface/certificate_revocation_list_spec.rb b/spec/unit/interface/certificate_revocation_list_spec.rb index 8ee341bef..a98b48d90 100644 --- a/spec/unit/interface/certificate_revocation_list_spec.rb +++ b/spec/unit/interface/certificate_revocation_list_spec.rb @@ -3,22 +3,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/certificate_revocation_list' -describe Puppet::Interface.interface(:certificate_revocation_list) do - before do - @interface = Puppet::Interface.interface(:certificate_revocation_list) - end - - it "should be a subclass of 'Indirection'" do - @interface.should be_instance_of(Puppet::Interface::Indirector) - end - - it "should refer to the 'certificate_revocation_list' indirection" do - @interface.indirection.name.should == :certificate_revocation_list - end - - [:find, :save, :search, :save].each do |method| - it "should have #{method} action defined" do - @interface.should be_action(method) - end - end +describe Puppet::Interface::Indirector.interface(:certificate_revocation_list) do end diff --git a/spec/unit/interface/certificate_spec.rb b/spec/unit/interface/certificate_spec.rb index 47ddcb52e..6a325343f 100644 --- a/spec/unit/interface/certificate_spec.rb +++ b/spec/unit/interface/certificate_spec.rb @@ -3,22 +3,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/certificate' -describe Puppet::Interface.interface(:certificate) do - before do - @interface = Puppet::Interface.interface(:certificate) - end - - it "should be a subclass of 'Indirection'" do - @interface.should be_instance_of(Puppet::Interface::Indirector) - end - - it "should refer to the 'certificate' indirection" do - @interface.indirection.name.should == :certificate - end - - [:find, :save, :search, :save].each do |method| - it "should have #{method} action defined" do - @interface.should be_action(method) - end - end +describe Puppet::Interface::Indirector.interface(:certificate) do end diff --git a/spec/unit/interface/config_spec.rb b/spec/unit/interface/config_spec.rb index 79c65f2ac..e8aafd4a3 100644 --- a/spec/unit/interface/config_spec.rb +++ b/spec/unit/interface/config_spec.rb @@ -4,24 +4,16 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/config' describe Puppet::Interface.interface(:config) do - before do - @interface = Puppet::Interface.interface(:config) - end - - it "should be a subclass of 'Indirection'" do - @interface.should be_instance_of(Puppet::Interface) - end - it "should use Settings#print_config_options when asked to print" do Puppet.settings.stubs(:puts) Puppet.settings.expects(:print_config_options) - @interface.print + subject.print end it "should set 'configprint' to all desired values and call print_config_options when a specific value is provided" do Puppet.settings.stubs(:puts) Puppet.settings.expects(:print_config_options) - @interface.print("libdir", "ssldir") + subject.print("libdir", "ssldir") Puppet.settings[:configprint].should == "libdir,ssldir" end end diff --git a/spec/unit/interface/facts_spec.rb b/spec/unit/interface/facts_spec.rb index 03d6410f9..d0f87d3a0 100644 --- a/spec/unit/interface/facts_spec.rb +++ b/spec/unit/interface/facts_spec.rb @@ -3,17 +3,13 @@ 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 - +describe Puppet::Interface::Indirector.interface(:facts) do it "should define an 'upload' fact" do - @interface.should be_action(:upload) + subject.should be_action(:upload) end it "should set its default format to :yaml" do - @interface.default_format.should == :yaml + subject.default_format.should == :yaml end describe "when uploading" do diff --git a/spec/unit/interface/file_spec.rb b/spec/unit/interface/file_spec.rb index fc7accf0d..54427a267 100644 --- a/spec/unit/interface/file_spec.rb +++ b/spec/unit/interface/file_spec.rb @@ -3,22 +3,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/file' -describe Puppet::Interface.interface(:file) do - before do - @interface = Puppet::Interface.interface(:file) - end - - it "should be a subclass of 'Indirection'" do - @interface.should be_instance_of(Puppet::Interface::Indirector) - end - - it "should refer to the 'file' indirection" do - @interface.indirection.name.should == :file_bucket_file - end - - [:find, :save, :search, :save].each do |method| - it "should have #{method} action defined" do - @interface.should be_action(method) - end - end +describe Puppet::Interface::Indirector.interface(:file) do end diff --git a/spec/unit/interface/indirector_spec.rb b/spec/unit/interface/indirector_spec.rb index c4d93ade3..0eb7a9a4f 100644 --- a/spec/unit/interface/indirector_spec.rb +++ b/spec/unit/interface/indirector_spec.rb @@ -12,10 +12,6 @@ describe Puppet::Interface::Indirector do @instance.stubs(:indirection).returns @indirection 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 diff --git a/spec/unit/interface/interface_collection_spec.rb b/spec/unit/interface/interface_collection_spec.rb new file mode 100644 index 000000000..536e694fd --- /dev/null +++ b/spec/unit/interface/interface_collection_spec.rb @@ -0,0 +1,97 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') + +require 'puppet/interface/interface_collection' + +describe Puppet::Interface::InterfaceCollection do + before :each do + subject.instance_variable_set("@interfaces", {}) + end + + after :all do + subject.instance_variable_set("@interfaces", {}) + end + + describe "::interfaces" do + end + + describe "::[]" do + before :each do + subject.instance_variable_set("@interfaces", {:foo => 10}) + end + + it "should return the interface with the given name" do + subject["foo"].should == 10 + end + + it "should attempt to load the interface if it isn't found" do + subject.expects(:require).with('puppet/interface/bar') + subject["bar"] + end + end + + describe "::interface?" do + before :each do + subject.instance_variable_set("@interfaces", {:foo => 10}) + end + + it "should return true if the interface specified is registered" do + subject.interface?("foo").should == true + end + + it "should attempt to require the interface if it is not registered" do + subject.expects(:require).with('puppet/interface/bar') + subject.interface?("bar") + end + + it "should return true if requiring the interface registered it" do + subject.stubs(:require).with do + subject.instance_variable_set("@interfaces", {:bar => 20}) + end + subject.interface?("bar").should == true + end + + it "should return false if the interface is not registered" do + subject.stubs(:require).returns(true) + subject.interface?("bar").should == false + end + + it "should return false if there is a LoadError requiring the interface" do + subject.stubs(:require).raises(LoadError) + subject.interface?("bar").should == false + end + end + + describe "::register" do + it "should store the interface by name" do + interface = Puppet::Interface.new(:my_interface) + subject.register(interface) + subject.instance_variable_get("@interfaces").should == {:my_interface => interface} + end + end + + describe "::underscorize" do + faulty = [1, "#foo", "$bar", "sturm und drang", :"sturm und drang"] + valid = { + "Foo" => :foo, + :Foo => :foo, + "foo_bar" => :foo_bar, + :foo_bar => :foo_bar, + "foo-bar" => :foo_bar, + :"foo-bar" => :foo_bar, + } + + valid.each do |input, expect| + it "should map #{input.inspect} to #{expect.inspect}" do + result = subject.underscorize(input) + result.should == expect + end + end + + faulty.each do |input| + it "should fail when presented with #{input.inspect} (#{input.class})" do + expect { subject.underscorize(input) }. + should raise_error ArgumentError, /not a valid interface name/ + end + end + end +end diff --git a/spec/unit/interface/key_spec.rb b/spec/unit/interface/key_spec.rb index 93a7c937c..4b331d169 100644 --- a/spec/unit/interface/key_spec.rb +++ b/spec/unit/interface/key_spec.rb @@ -3,22 +3,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/key' -describe Puppet::Interface.interface(:key) do - before do - @interface = Puppet::Interface.interface(:key) - end - - it "should be a subclass of 'Indirection'" do - @interface.should be_instance_of(Puppet::Interface::Indirector) - end - - it "should refer to the 'key' indirection" do - @interface.indirection.name.should == :key - end - - [:find, :save, :search, :save].each do |method| - it "should have #{method} action defined" do - @interface.should be_action(method) - end - end +describe Puppet::Interface::Indirector.interface(:key) do end diff --git a/spec/unit/interface/node_spec.rb b/spec/unit/interface/node_spec.rb index 63109308d..b1b4ad421 100644 --- a/spec/unit/interface/node_spec.rb +++ b/spec/unit/interface/node_spec.rb @@ -3,26 +3,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/node' -describe Puppet::Interface.interface(:node) do - before do - @interface = Puppet::Interface.interface(:node) - end - - it "should be a subclass of 'Indirection'" do - @interface.should be_instance_of(Puppet::Interface::Indirector) - end - +describe Puppet::Interface::Indirector.interface(:node) do it "should set its default format to :yaml" do - @interface.default_format.should == :yaml - end - - it "should refer to the 'node' indirection" do - @interface.indirection.name.should == :node - end - - [:find, :save, :search, :save].each do |method| - it "should have #{method} action defined" do - @interface.should be_action(method) - end + subject.default_format.should == :yaml end end diff --git a/spec/unit/interface/report_spec.rb b/spec/unit/interface/report_spec.rb index b5bee1a62..c424880a9 100644 --- a/spec/unit/interface/report_spec.rb +++ b/spec/unit/interface/report_spec.rb @@ -3,22 +3,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/report' -describe Puppet::Interface.interface(:report) do - before do - @interface = Puppet::Interface.interface(:report) - end - - it "should be a subclass of 'Indirection'" do - @interface.should be_instance_of(Puppet::Interface::Indirector) - end - - it "should refer to the 'report' indirection" do - @interface.indirection.name.should == :report - end - - [:find, :save, :search, :save].each do |method| - it "should have #{method} action defined" do - @interface.should be_action(method) - end - end +describe Puppet::Interface::Indirector.interface(:report) do end diff --git a/spec/unit/interface/resource_spec.rb b/spec/unit/interface/resource_spec.rb index cad45b66b..aab2753b1 100644 --- a/spec/unit/interface/resource_spec.rb +++ b/spec/unit/interface/resource_spec.rb @@ -3,22 +3,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/resource' -describe Puppet::Interface.interface(:resource) do - before do - @interface = Puppet::Interface.interface(:resource) - end - - it "should be a subclass of 'Indirection'" do - @interface.should be_instance_of(Puppet::Interface::Indirector) - end - - it "should refer to the 'resource' indirection" do - @interface.indirection.name.should == :resource - end - - [:find, :save, :search, :save].each do |method| - it "should have #{method} action defined" do - @interface.should be_action(method) - end - end +describe Puppet::Interface::Indirector.interface(:resource) do end diff --git a/spec/unit/interface/resource_type_spec.rb b/spec/unit/interface/resource_type_spec.rb index 6c437c475..6e973c98b 100644 --- a/spec/unit/interface/resource_type_spec.rb +++ b/spec/unit/interface/resource_type_spec.rb @@ -3,22 +3,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/resource_type' -describe Puppet::Interface.interface(:resource_type) do - before do - @interface = Puppet::Interface.interface(:resource_type) - end - - it "should be a subclass of 'Indirection'" do - @interface.should be_instance_of(Puppet::Interface::Indirector) - end - - it "should refer to the 'resource_type' indirection" do - @interface.indirection.name.should == :resource_type - end - - [:find, :save, :search, :save].each do |method| - it "should have #{method} action defined" do - @interface.should be_action(method) - end - end +describe Puppet::Interface::Indirector.interface(:resource_type) do end -- cgit From af79d3c63479a77278e174f370b4b3d156bec1a1 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Tue, 22 Mar 2011 18:05:51 -0700 Subject: maint: Fix order-dependent spec failures The specs for InterfaceCollection were clearing the list of interfaces at the end of the spec run, which caused later specs to fail because they couldn't re-require interfaces they needed. This fixes the InterfaceCollection specs to save and restore the interfaces at the end of the file. Reviewed-By: Matt Robinson --- spec/unit/interface/interface_collection_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/interface_collection_spec.rb b/spec/unit/interface/interface_collection_spec.rb index 536e694fd..42a0f2490 100644 --- a/spec/unit/interface/interface_collection_spec.rb +++ b/spec/unit/interface/interface_collection_spec.rb @@ -3,12 +3,18 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/interface/interface_collection' describe Puppet::Interface::InterfaceCollection do + # This is global state that other tests depend on, so we have to save and + # restore it + before :all do + @saved_interfaces = subject.instance_variable_get("@interfaces").dup + end + before :each do subject.instance_variable_set("@interfaces", {}) end after :all do - subject.instance_variable_set("@interfaces", {}) + subject.instance_variable_set("@interfaces", @saved_interfaces) end describe "::interfaces" do -- cgit From 562ae5fb9d78b1a6d46e79bb41d8498f29246f41 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 22 Mar 2011 19:10:35 -0700 Subject: WIP - all tests fail Signed-off-by: Luke Kanies --- spec/unit/interface/action_manager_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/action_manager_spec.rb b/spec/unit/interface/action_manager_spec.rb index bf101b344..d1a7e31be 100644 --- a/spec/unit/interface/action_manager_spec.rb +++ b/spec/unit/interface/action_manager_spec.rb @@ -38,6 +38,14 @@ describe Puppet::Interface::ActionManager do subject.should be_action(:foo) end + + it "should correctly treat action names specified as strings" do + subject.action(:foo) do + invoke { "something" } + end + + subject.should be_action("foo") + end end describe "when used to extend a class" do -- cgit From 1187a0eb2550f04d9b6c3dcfdcacdfbb32de0e56 Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Wed, 23 Mar 2011 13:59:44 -0700 Subject: (#6770) Add basic versioning for interfaces. Reviewed-By: Nick Lewis --- spec/unit/interface/action_builder_spec.rb | 2 +- spec/unit/interface/action_spec.rb | 4 +-- spec/unit/interface/catalog_spec.rb | 3 +- spec/unit/interface/certificate_request_spec.rb | 3 +- .../interface/certificate_revocation_list_spec.rb | 3 +- spec/unit/interface/certificate_spec.rb | 3 +- spec/unit/interface/config_spec.rb | 3 +- spec/unit/interface/configurer_spec.rb | 5 ++- spec/unit/interface/facts_spec.rb | 3 +- spec/unit/interface/file_spec.rb | 3 +- spec/unit/interface/indirector_spec.rb | 4 +-- spec/unit/interface/interface_collection_spec.rb | 40 ++++++++++++---------- spec/unit/interface/key_spec.rb | 3 +- spec/unit/interface/node_spec.rb | 3 +- spec/unit/interface/report_spec.rb | 3 +- spec/unit/interface/resource_spec.rb | 3 +- spec/unit/interface/resource_type_spec.rb | 3 +- 17 files changed, 41 insertions(+), 50 deletions(-) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb index 39b2386dc..ba6618fa4 100644 --- a/spec/unit/interface/action_builder_spec.rb +++ b/spec/unit/interface/action_builder_spec.rb @@ -13,7 +13,7 @@ describe Puppet::Interface::ActionBuilder do end it "should define a method on the interface which invokes the action" do - interface = Puppet::Interface.new(:action_builder_test_interface) + interface = Puppet::Interface.new(:action_builder_test_interface, :version => 1) action = Puppet::Interface::ActionBuilder.build(interface, :foo) do invoke do "invoked the method" diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb index e74fa9fcc..5be6665fb 100644 --- a/spec/unit/interface/action_spec.rb +++ b/spec/unit/interface/action_spec.rb @@ -24,7 +24,7 @@ describe Puppet::Interface::Action do describe "when invoking" do it "should be able to call other actions on the same object" do - interface = Puppet::Interface.new(:my_interface) do + interface = Puppet::Interface.new(:my_interface, :version => 1) do action(:foo) do invoke { 25 } end @@ -56,7 +56,7 @@ describe Puppet::Interface::Action do end end - interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface) do + interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface, :version => 1) do action(:baz) do invoke { "the value of foo in baz is '#{foo}'" } end diff --git a/spec/unit/interface/catalog_spec.rb b/spec/unit/interface/catalog_spec.rb index 78d62110f..a59f9c952 100644 --- a/spec/unit/interface/catalog_spec.rb +++ b/spec/unit/interface/catalog_spec.rb @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/catalog' -describe Puppet::Interface::Indirector.interface(:catalog) do +describe Puppet::Interface.interface(:catalog, 1) do end diff --git a/spec/unit/interface/certificate_request_spec.rb b/spec/unit/interface/certificate_request_spec.rb index a6ab8d17e..e818c301b 100644 --- a/spec/unit/interface/certificate_request_spec.rb +++ b/spec/unit/interface/certificate_request_spec.rb @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/certificate_request' -describe Puppet::Interface::Indirector.interface(:certificate_request) do +describe Puppet::Interface.interface(:certificate_request, 1) do end diff --git a/spec/unit/interface/certificate_revocation_list_spec.rb b/spec/unit/interface/certificate_revocation_list_spec.rb index a98b48d90..0979eda1f 100644 --- a/spec/unit/interface/certificate_revocation_list_spec.rb +++ b/spec/unit/interface/certificate_revocation_list_spec.rb @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/certificate_revocation_list' -describe Puppet::Interface::Indirector.interface(:certificate_revocation_list) do +describe Puppet::Interface.interface(:certificate_revocation_list, 1) do end diff --git a/spec/unit/interface/certificate_spec.rb b/spec/unit/interface/certificate_spec.rb index 6a325343f..51b79e6b0 100644 --- a/spec/unit/interface/certificate_spec.rb +++ b/spec/unit/interface/certificate_spec.rb @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/certificate' -describe Puppet::Interface::Indirector.interface(:certificate) do +describe Puppet::Interface.interface(:certificate, 1) do end diff --git a/spec/unit/interface/config_spec.rb b/spec/unit/interface/config_spec.rb index e8aafd4a3..e1238b925 100644 --- a/spec/unit/interface/config_spec.rb +++ b/spec/unit/interface/config_spec.rb @@ -1,9 +1,8 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/config' -describe Puppet::Interface.interface(:config) do +describe Puppet::Interface.interface(:config, 1) do it "should use Settings#print_config_options when asked to print" do Puppet.settings.stubs(:puts) Puppet.settings.expects(:print_config_options) diff --git a/spec/unit/interface/configurer_spec.rb b/spec/unit/interface/configurer_spec.rb index 4b3532c1b..b592a85bb 100644 --- a/spec/unit/interface/configurer_spec.rb +++ b/spec/unit/interface/configurer_spec.rb @@ -1,11 +1,10 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/configurer' require 'puppet/indirector/catalog/rest' require 'tempfile' -describe Puppet::Interface.interface(:configurer) do +describe Puppet::Interface.interface(:configurer, 1) do describe "#synchronize" do it "should retrieve and apply a catalog and return a report" do dirname = Dir.mktmpdir("puppetdir") @@ -16,7 +15,7 @@ describe Puppet::Interface.interface(:configurer) do @catalog.add_resource(@file) Puppet::Resource::Catalog::Rest.any_instance.stubs(:find).returns(@catalog) - report = Puppet::Interface.interface(:configurer).synchronize("foo") + report = subject.synchronize("foo") report.kind.should == "apply" report.status.should == "changed" diff --git a/spec/unit/interface/facts_spec.rb b/spec/unit/interface/facts_spec.rb index d0f87d3a0..2b5731de5 100644 --- a/spec/unit/interface/facts_spec.rb +++ b/spec/unit/interface/facts_spec.rb @@ -1,9 +1,8 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/facts' -describe Puppet::Interface::Indirector.interface(:facts) do +describe Puppet::Interface.interface(:facts, 1) do it "should define an 'upload' fact" do subject.should be_action(:upload) end diff --git a/spec/unit/interface/file_spec.rb b/spec/unit/interface/file_spec.rb index 54427a267..754b22875 100644 --- a/spec/unit/interface/file_spec.rb +++ b/spec/unit/interface/file_spec.rb @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/file' -describe Puppet::Interface::Indirector.interface(:file) do +describe Puppet::Interface.interface(:file, 1) do end diff --git a/spec/unit/interface/indirector_spec.rb b/spec/unit/interface/indirector_spec.rb index 0eb7a9a4f..abbff150b 100644 --- a/spec/unit/interface/indirector_spec.rb +++ b/spec/unit/interface/indirector_spec.rb @@ -5,7 +5,7 @@ require 'puppet/interface/indirector' describe Puppet::Interface::Indirector do before do - @instance = Puppet::Interface::Indirector.new(:test) + @instance = Puppet::Interface::Indirector.new(:test, :version => 1) @indirection = stub 'indirection', :name => :stub_indirection @@ -24,7 +24,7 @@ describe Puppet::Interface::Indirector do 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) + Puppet::Interface::Indirector.new(:catalog, :version => 1).indirection.should equal(Puppet::Resource::Catalog.indirection) end end diff --git a/spec/unit/interface/interface_collection_spec.rb b/spec/unit/interface/interface_collection_spec.rb index 536e694fd..ae684ca75 100644 --- a/spec/unit/interface/interface_collection_spec.rb +++ b/spec/unit/interface/interface_collection_spec.rb @@ -1,14 +1,18 @@ -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +#!/usr/bin/env ruby -require 'puppet/interface/interface_collection' +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Puppet::Interface::InterfaceCollection do + before :all do + @interfaces = subject.instance_variable_get("@interfaces").dup + end + before :each do - subject.instance_variable_set("@interfaces", {}) + subject.instance_variable_get("@interfaces").clear end after :all do - subject.instance_variable_set("@interfaces", {}) + subject.instance_variable_set("@interfaces", @interfaces) end describe "::interfaces" do @@ -16,56 +20,56 @@ describe Puppet::Interface::InterfaceCollection do describe "::[]" do before :each do - subject.instance_variable_set("@interfaces", {:foo => 10}) + subject.instance_variable_get("@interfaces")[:foo][1] = 10 end it "should return the interface with the given name" do - subject["foo"].should == 10 + subject["foo", 1].should == 10 end it "should attempt to load the interface if it isn't found" do - subject.expects(:require).with('puppet/interface/bar') - subject["bar"] + subject.expects(:require).with('puppet/interface/v1/bar') + subject["bar", 1] end end describe "::interface?" do before :each do - subject.instance_variable_set("@interfaces", {:foo => 10}) + subject.instance_variable_get("@interfaces")[:foo][1] = 10 end it "should return true if the interface specified is registered" do - subject.interface?("foo").should == true + subject.interface?("foo", 1).should == true end it "should attempt to require the interface if it is not registered" do - subject.expects(:require).with('puppet/interface/bar') - subject.interface?("bar") + subject.expects(:require).with('puppet/interface/v1/bar') + subject.interface?("bar", 1) end it "should return true if requiring the interface registered it" do subject.stubs(:require).with do - subject.instance_variable_set("@interfaces", {:bar => 20}) + subject.instance_variable_get("@interfaces")[:bar][1] = 20 end - subject.interface?("bar").should == true + subject.interface?("bar", 1).should == true end it "should return false if the interface is not registered" do subject.stubs(:require).returns(true) - subject.interface?("bar").should == false + subject.interface?("bar", 1).should == false end it "should return false if there is a LoadError requiring the interface" do subject.stubs(:require).raises(LoadError) - subject.interface?("bar").should == false + subject.interface?("bar", 1).should == false end end describe "::register" do it "should store the interface by name" do - interface = Puppet::Interface.new(:my_interface) + interface = Puppet::Interface.new(:my_interface, :version => 1) subject.register(interface) - subject.instance_variable_get("@interfaces").should == {:my_interface => interface} + subject.instance_variable_get("@interfaces").should == {:my_interface => {1 => interface}} end end diff --git a/spec/unit/interface/key_spec.rb b/spec/unit/interface/key_spec.rb index 4b331d169..395fbef4d 100644 --- a/spec/unit/interface/key_spec.rb +++ b/spec/unit/interface/key_spec.rb @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/key' -describe Puppet::Interface::Indirector.interface(:key) do +describe Puppet::Interface.interface(:key, 1) do end diff --git a/spec/unit/interface/node_spec.rb b/spec/unit/interface/node_spec.rb index b1b4ad421..bd4bc9fea 100644 --- a/spec/unit/interface/node_spec.rb +++ b/spec/unit/interface/node_spec.rb @@ -1,9 +1,8 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/node' -describe Puppet::Interface::Indirector.interface(:node) do +describe Puppet::Interface.interface(:node, 1) do it "should set its default format to :yaml" do subject.default_format.should == :yaml end diff --git a/spec/unit/interface/report_spec.rb b/spec/unit/interface/report_spec.rb index c424880a9..0dd3cacf1 100644 --- a/spec/unit/interface/report_spec.rb +++ b/spec/unit/interface/report_spec.rb @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/report' -describe Puppet::Interface::Indirector.interface(:report) do +describe Puppet::Interface.interface(:report, 1) do end diff --git a/spec/unit/interface/resource_spec.rb b/spec/unit/interface/resource_spec.rb index aab2753b1..5101ddbd6 100644 --- a/spec/unit/interface/resource_spec.rb +++ b/spec/unit/interface/resource_spec.rb @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/resource' -describe Puppet::Interface::Indirector.interface(:resource) do +describe Puppet::Interface.interface(:resource, 1) do end diff --git a/spec/unit/interface/resource_type_spec.rb b/spec/unit/interface/resource_type_spec.rb index 6e973c98b..84afa30d4 100644 --- a/spec/unit/interface/resource_type_spec.rb +++ b/spec/unit/interface/resource_type_spec.rb @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/resource_type' -describe Puppet::Interface::Indirector.interface(:resource_type) do +describe Puppet::Interface.interface(:resource_type, 1) do end -- cgit From 7aa8f2252c7b0512c929fb87a6c3a09a952a142a Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Wed, 23 Mar 2011 16:10:45 -0700 Subject: (#6770) Changing versioning to semver. More information about the versioning scheme can be found at http://semver.org. Paired-With: Nick Lewis --- spec/unit/interface/action_builder_spec.rb | 2 +- spec/unit/interface/action_spec.rb | 4 ++-- spec/unit/interface/catalog_spec.rb | 2 +- spec/unit/interface/certificate_request_spec.rb | 2 +- .../interface/certificate_revocation_list_spec.rb | 2 +- spec/unit/interface/certificate_spec.rb | 2 +- spec/unit/interface/config_spec.rb | 2 +- spec/unit/interface/configurer_spec.rb | 2 +- spec/unit/interface/facts_spec.rb | 2 +- spec/unit/interface/file_spec.rb | 2 +- spec/unit/interface/indirector_spec.rb | 4 ++-- spec/unit/interface/interface_collection_spec.rb | 28 +++++++++++----------- spec/unit/interface/key_spec.rb | 2 +- spec/unit/interface/node_spec.rb | 2 +- spec/unit/interface/report_spec.rb | 2 +- spec/unit/interface/resource_spec.rb | 2 +- spec/unit/interface/resource_type_spec.rb | 2 +- 17 files changed, 32 insertions(+), 32 deletions(-) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb index ba6618fa4..2c2f3b14c 100644 --- a/spec/unit/interface/action_builder_spec.rb +++ b/spec/unit/interface/action_builder_spec.rb @@ -13,7 +13,7 @@ describe Puppet::Interface::ActionBuilder do end it "should define a method on the interface which invokes the action" do - interface = Puppet::Interface.new(:action_builder_test_interface, :version => 1) + interface = Puppet::Interface.new(:action_builder_test_interface, :version => '0.0.1') action = Puppet::Interface::ActionBuilder.build(interface, :foo) do invoke do "invoked the method" diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb index 5be6665fb..246ae9622 100644 --- a/spec/unit/interface/action_spec.rb +++ b/spec/unit/interface/action_spec.rb @@ -24,7 +24,7 @@ describe Puppet::Interface::Action do describe "when invoking" do it "should be able to call other actions on the same object" do - interface = Puppet::Interface.new(:my_interface, :version => 1) do + interface = Puppet::Interface.new(:my_interface, :version => '0.0.1') do action(:foo) do invoke { 25 } end @@ -56,7 +56,7 @@ describe Puppet::Interface::Action do end end - interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface, :version => 1) do + interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface, :version => '0.0.1') do action(:baz) do invoke { "the value of foo in baz is '#{foo}'" } end diff --git a/spec/unit/interface/catalog_spec.rb b/spec/unit/interface/catalog_spec.rb index a59f9c952..1d33fed38 100644 --- a/spec/unit/interface/catalog_spec.rb +++ b/spec/unit/interface/catalog_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:catalog, 1) do +describe Puppet::Interface.interface(:catalog, '0.0.1') do end diff --git a/spec/unit/interface/certificate_request_spec.rb b/spec/unit/interface/certificate_request_spec.rb index e818c301b..994a19a55 100644 --- a/spec/unit/interface/certificate_request_spec.rb +++ b/spec/unit/interface/certificate_request_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:certificate_request, 1) do +describe Puppet::Interface.interface(:certificate_request, '0.0.1') do end diff --git a/spec/unit/interface/certificate_revocation_list_spec.rb b/spec/unit/interface/certificate_revocation_list_spec.rb index 0979eda1f..024770e20 100644 --- a/spec/unit/interface/certificate_revocation_list_spec.rb +++ b/spec/unit/interface/certificate_revocation_list_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:certificate_revocation_list, 1) do +describe Puppet::Interface.interface(:certificate_revocation_list, '0.0.1') do end diff --git a/spec/unit/interface/certificate_spec.rb b/spec/unit/interface/certificate_spec.rb index 51b79e6b0..45d33feec 100644 --- a/spec/unit/interface/certificate_spec.rb +++ b/spec/unit/interface/certificate_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:certificate, 1) do +describe Puppet::Interface.interface(:certificate, '0.0.1') do end diff --git a/spec/unit/interface/config_spec.rb b/spec/unit/interface/config_spec.rb index e1238b925..20a92bf47 100644 --- a/spec/unit/interface/config_spec.rb +++ b/spec/unit/interface/config_spec.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:config, 1) do +describe Puppet::Interface.interface(:config, '0.0.1') do it "should use Settings#print_config_options when asked to print" do Puppet.settings.stubs(:puts) Puppet.settings.expects(:print_config_options) diff --git a/spec/unit/interface/configurer_spec.rb b/spec/unit/interface/configurer_spec.rb index b592a85bb..589e6be95 100644 --- a/spec/unit/interface/configurer_spec.rb +++ b/spec/unit/interface/configurer_spec.rb @@ -4,7 +4,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/indirector/catalog/rest' require 'tempfile' -describe Puppet::Interface.interface(:configurer, 1) do +describe Puppet::Interface.interface(:configurer, '0.0.1') do describe "#synchronize" do it "should retrieve and apply a catalog and return a report" do dirname = Dir.mktmpdir("puppetdir") diff --git a/spec/unit/interface/facts_spec.rb b/spec/unit/interface/facts_spec.rb index 2b5731de5..4782ecb85 100644 --- a/spec/unit/interface/facts_spec.rb +++ b/spec/unit/interface/facts_spec.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:facts, 1) do +describe Puppet::Interface.interface(:facts, '0.0.1') do it "should define an 'upload' fact" do subject.should be_action(:upload) end diff --git a/spec/unit/interface/file_spec.rb b/spec/unit/interface/file_spec.rb index 754b22875..4b776fbbc 100644 --- a/spec/unit/interface/file_spec.rb +++ b/spec/unit/interface/file_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:file, 1) do +describe Puppet::Interface.interface(:file, '0.0.1') do end diff --git a/spec/unit/interface/indirector_spec.rb b/spec/unit/interface/indirector_spec.rb index abbff150b..b14058eca 100644 --- a/spec/unit/interface/indirector_spec.rb +++ b/spec/unit/interface/indirector_spec.rb @@ -5,7 +5,7 @@ require 'puppet/interface/indirector' describe Puppet::Interface::Indirector do before do - @instance = Puppet::Interface::Indirector.new(:test, :version => 1) + @instance = Puppet::Interface::Indirector.new(:test, :version => '0.0.1') @indirection = stub 'indirection', :name => :stub_indirection @@ -24,7 +24,7 @@ describe Puppet::Interface::Indirector do 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, :version => 1).indirection.should equal(Puppet::Resource::Catalog.indirection) + Puppet::Interface::Indirector.new(:catalog, :version => '0.0.1').indirection.should equal(Puppet::Resource::Catalog.indirection) end end diff --git a/spec/unit/interface/interface_collection_spec.rb b/spec/unit/interface/interface_collection_spec.rb index ae684ca75..193d31b1e 100644 --- a/spec/unit/interface/interface_collection_spec.rb +++ b/spec/unit/interface/interface_collection_spec.rb @@ -20,56 +20,56 @@ describe Puppet::Interface::InterfaceCollection do describe "::[]" do before :each do - subject.instance_variable_get("@interfaces")[:foo][1] = 10 + subject.instance_variable_get("@interfaces")[:foo]['0.0.1'] = 10 end it "should return the interface with the given name" do - subject["foo", 1].should == 10 + subject["foo", '0.0.1'].should == 10 end it "should attempt to load the interface if it isn't found" do - subject.expects(:require).with('puppet/interface/v1/bar') - subject["bar", 1] + subject.expects(:require).with('puppet/interface/v0.0.1/bar') + subject["bar", '0.0.1'] end end describe "::interface?" do before :each do - subject.instance_variable_get("@interfaces")[:foo][1] = 10 + subject.instance_variable_get("@interfaces")[:foo]['0.0.1'] = 10 end it "should return true if the interface specified is registered" do - subject.interface?("foo", 1).should == true + subject.interface?("foo", '0.0.1').should == true end it "should attempt to require the interface if it is not registered" do - subject.expects(:require).with('puppet/interface/v1/bar') - subject.interface?("bar", 1) + subject.expects(:require).with('puppet/interface/v0.0.1/bar') + subject.interface?("bar", '0.0.1') end it "should return true if requiring the interface registered it" do subject.stubs(:require).with do - subject.instance_variable_get("@interfaces")[:bar][1] = 20 + subject.instance_variable_get("@interfaces")[:bar]['0.0.1'] = 20 end - subject.interface?("bar", 1).should == true + subject.interface?("bar", '0.0.1').should == true end it "should return false if the interface is not registered" do subject.stubs(:require).returns(true) - subject.interface?("bar", 1).should == false + subject.interface?("bar", '0.0.1').should == false end it "should return false if there is a LoadError requiring the interface" do subject.stubs(:require).raises(LoadError) - subject.interface?("bar", 1).should == false + subject.interface?("bar", '0.0.1').should == false end end describe "::register" do it "should store the interface by name" do - interface = Puppet::Interface.new(:my_interface, :version => 1) + interface = Puppet::Interface.new(:my_interface, :version => '0.0.1') subject.register(interface) - subject.instance_variable_get("@interfaces").should == {:my_interface => {1 => interface}} + subject.instance_variable_get("@interfaces").should == {:my_interface => {'0.0.1' => interface}} end end diff --git a/spec/unit/interface/key_spec.rb b/spec/unit/interface/key_spec.rb index 395fbef4d..8c950baa1 100644 --- a/spec/unit/interface/key_spec.rb +++ b/spec/unit/interface/key_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:key, 1) do +describe Puppet::Interface.interface(:key, '0.0.1') do end diff --git a/spec/unit/interface/node_spec.rb b/spec/unit/interface/node_spec.rb index bd4bc9fea..104081838 100644 --- a/spec/unit/interface/node_spec.rb +++ b/spec/unit/interface/node_spec.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:node, 1) do +describe Puppet::Interface.interface(:node, '0.0.1') do it "should set its default format to :yaml" do subject.default_format.should == :yaml end diff --git a/spec/unit/interface/report_spec.rb b/spec/unit/interface/report_spec.rb index 0dd3cacf1..0a7acfac3 100644 --- a/spec/unit/interface/report_spec.rb +++ b/spec/unit/interface/report_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:report, 1) do +describe Puppet::Interface.interface(:report, '0.0.1') do end diff --git a/spec/unit/interface/resource_spec.rb b/spec/unit/interface/resource_spec.rb index 5101ddbd6..afaed67b7 100644 --- a/spec/unit/interface/resource_spec.rb +++ b/spec/unit/interface/resource_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:resource, 1) do +describe Puppet::Interface.interface(:resource, '0.0.1') do end diff --git a/spec/unit/interface/resource_type_spec.rb b/spec/unit/interface/resource_type_spec.rb index 84afa30d4..f689accc3 100644 --- a/spec/unit/interface/resource_type_spec.rb +++ b/spec/unit/interface/resource_type_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:resource_type, 1) do +describe Puppet::Interface.interface(:resource_type, '0.0.1') do end -- cgit From c25fb94725c9abfb36e67938356f97823f8b605e Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Wed, 23 Mar 2011 16:28:28 -0700 Subject: (#6770) Rename Puppet::Interface::interface method. Puppet::Interface::interface is now Puppet::Interface::define, also aliased to Puppet::Interface::[] for convenience. Paired-With: Nick Lewis --- spec/unit/interface/catalog_spec.rb | 2 +- spec/unit/interface/certificate_request_spec.rb | 2 +- spec/unit/interface/certificate_revocation_list_spec.rb | 2 +- spec/unit/interface/certificate_spec.rb | 2 +- spec/unit/interface/config_spec.rb | 2 +- spec/unit/interface/configurer_spec.rb | 2 +- spec/unit/interface/facts_spec.rb | 2 +- spec/unit/interface/file_spec.rb | 2 +- spec/unit/interface/key_spec.rb | 2 +- spec/unit/interface/node_spec.rb | 2 +- spec/unit/interface/report_spec.rb | 2 +- spec/unit/interface/resource_spec.rb | 2 +- spec/unit/interface/resource_type_spec.rb | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/catalog_spec.rb b/spec/unit/interface/catalog_spec.rb index 1d33fed38..c615181ed 100644 --- a/spec/unit/interface/catalog_spec.rb +++ b/spec/unit/interface/catalog_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:catalog, '0.0.1') do +describe Puppet::Interface.define(:catalog, '0.0.1') do end diff --git a/spec/unit/interface/certificate_request_spec.rb b/spec/unit/interface/certificate_request_spec.rb index 994a19a55..0143ebc85 100644 --- a/spec/unit/interface/certificate_request_spec.rb +++ b/spec/unit/interface/certificate_request_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:certificate_request, '0.0.1') do +describe Puppet::Interface.define(:certificate_request, '0.0.1') do end diff --git a/spec/unit/interface/certificate_revocation_list_spec.rb b/spec/unit/interface/certificate_revocation_list_spec.rb index 024770e20..9655dd3fa 100644 --- a/spec/unit/interface/certificate_revocation_list_spec.rb +++ b/spec/unit/interface/certificate_revocation_list_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:certificate_revocation_list, '0.0.1') do +describe Puppet::Interface.define(:certificate_revocation_list, '0.0.1') do end diff --git a/spec/unit/interface/certificate_spec.rb b/spec/unit/interface/certificate_spec.rb index 45d33feec..e5c63e456 100644 --- a/spec/unit/interface/certificate_spec.rb +++ b/spec/unit/interface/certificate_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:certificate, '0.0.1') do +describe Puppet::Interface.define(:certificate, '0.0.1') do end diff --git a/spec/unit/interface/config_spec.rb b/spec/unit/interface/config_spec.rb index 20a92bf47..a2ec7b528 100644 --- a/spec/unit/interface/config_spec.rb +++ b/spec/unit/interface/config_spec.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:config, '0.0.1') do +describe Puppet::Interface.define(:config, '0.0.1') do it "should use Settings#print_config_options when asked to print" do Puppet.settings.stubs(:puts) Puppet.settings.expects(:print_config_options) diff --git a/spec/unit/interface/configurer_spec.rb b/spec/unit/interface/configurer_spec.rb index 589e6be95..e97e63b65 100644 --- a/spec/unit/interface/configurer_spec.rb +++ b/spec/unit/interface/configurer_spec.rb @@ -4,7 +4,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') require 'puppet/indirector/catalog/rest' require 'tempfile' -describe Puppet::Interface.interface(:configurer, '0.0.1') do +describe Puppet::Interface.define(:configurer, '0.0.1') do describe "#synchronize" do it "should retrieve and apply a catalog and return a report" do dirname = Dir.mktmpdir("puppetdir") diff --git a/spec/unit/interface/facts_spec.rb b/spec/unit/interface/facts_spec.rb index 4782ecb85..5f0214fd5 100644 --- a/spec/unit/interface/facts_spec.rb +++ b/spec/unit/interface/facts_spec.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:facts, '0.0.1') do +describe Puppet::Interface.define(:facts, '0.0.1') do it "should define an 'upload' fact" do subject.should be_action(:upload) end diff --git a/spec/unit/interface/file_spec.rb b/spec/unit/interface/file_spec.rb index 4b776fbbc..bd6e31c0e 100644 --- a/spec/unit/interface/file_spec.rb +++ b/spec/unit/interface/file_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:file, '0.0.1') do +describe Puppet::Interface.define(:file, '0.0.1') do end diff --git a/spec/unit/interface/key_spec.rb b/spec/unit/interface/key_spec.rb index 8c950baa1..519497808 100644 --- a/spec/unit/interface/key_spec.rb +++ b/spec/unit/interface/key_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:key, '0.0.1') do +describe Puppet::Interface.define(:key, '0.0.1') do end diff --git a/spec/unit/interface/node_spec.rb b/spec/unit/interface/node_spec.rb index 104081838..91914c3ae 100644 --- a/spec/unit/interface/node_spec.rb +++ b/spec/unit/interface/node_spec.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:node, '0.0.1') do +describe Puppet::Interface.define(:node, '0.0.1') do it "should set its default format to :yaml" do subject.default_format.should == :yaml end diff --git a/spec/unit/interface/report_spec.rb b/spec/unit/interface/report_spec.rb index 0a7acfac3..23855db09 100644 --- a/spec/unit/interface/report_spec.rb +++ b/spec/unit/interface/report_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:report, '0.0.1') do +describe Puppet::Interface.define(:report, '0.0.1') do end diff --git a/spec/unit/interface/resource_spec.rb b/spec/unit/interface/resource_spec.rb index afaed67b7..408be250c 100644 --- a/spec/unit/interface/resource_spec.rb +++ b/spec/unit/interface/resource_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:resource, '0.0.1') do +describe Puppet::Interface.define(:resource, '0.0.1') do end diff --git a/spec/unit/interface/resource_type_spec.rb b/spec/unit/interface/resource_type_spec.rb index f689accc3..860be282c 100644 --- a/spec/unit/interface/resource_type_spec.rb +++ b/spec/unit/interface/resource_type_spec.rb @@ -2,5 +2,5 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Puppet::Interface.interface(:resource_type, '0.0.1') do +describe Puppet::Interface.define(:resource_type, '0.0.1') do end -- cgit From 633f63cdbc1d5630e546041bb0c1e714216158d0 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Thu, 24 Mar 2011 13:33:30 -0700 Subject: (#6833) support 'script' as a short form of 'action' At the moment the action method is a fairly heavy tool: it provides a DSL, and is designed to allow substantial metadata to be added to the action. For some users this is low on value, since they just want to write a little script that drives things a bit differently. Which there is substantial value in the metadata, adding the capability to do these light-weight things quickly is valid. To meet this we add a script action; the contrast is: action :foo do # other metadata goes here invoke do |args| # method body goes here end end script :bar do |args| # method body goes here end # ...and if you want metadata, you have to add it in more ugly, procedural # ways, which we are not going to encourage. Reviewed-By: Pieter van de Bruggen --- spec/unit/interface/action_manager_spec.rb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) mode change 100644 => 100755 spec/unit/interface/action_manager_spec.rb (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/action_manager_spec.rb b/spec/unit/interface/action_manager_spec.rb old mode 100644 new mode 100755 index d1a7e31be..3aff7ac11 --- a/spec/unit/interface/action_manager_spec.rb +++ b/spec/unit/interface/action_manager_spec.rb @@ -19,6 +19,12 @@ describe Puppet::Interface::ActionManager do end end + it "should be able to define a 'script' style action" do + subject.script :bar do + "a bar is where beer is found" + end + end + it "should be able to list defined actions" do subject.action(:foo) do invoke { "something" } @@ -27,8 +33,21 @@ describe Puppet::Interface::ActionManager do invoke { "something" } end - subject.actions.should include(:bar) - subject.actions.should include(:foo) + subject.actions.should =~ [:foo, :bar] + end + + it "should list 'script' actions" do + subject.script :foo do "foo" end + subject.actions.should =~ [:foo] + end + + it "should list both script and normal actions" do + subject.action :foo do + invoke do "foo" end + end + subject.script :bar do "a bar is where beer is found" end + + subject.actions.should =~ [:foo, :bar] end it "should be able to indicate when an action is defined" do @@ -39,6 +58,11 @@ describe Puppet::Interface::ActionManager do subject.should be_action(:foo) end + it "should indicate an action is defined for script actions" do + subject.script :foo do "foo" end + subject.should be_action :foo + end + it "should correctly treat action names specified as strings" do subject.action(:foo) do invoke { "something" } -- cgit From 53b0656048c3227048bdc317c5e917ad0c39e850 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 25 Mar 2011 08:55:24 -0700 Subject: Config#print action always returns nil We were returning 'true', which was getting printed unnecessarily. Signed-off-by: Luke Kanies --- spec/unit/interface/config_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/config_spec.rb b/spec/unit/interface/config_spec.rb index a2ec7b528..2e82b0b08 100644 --- a/spec/unit/interface/config_spec.rb +++ b/spec/unit/interface/config_spec.rb @@ -15,4 +15,10 @@ describe Puppet::Interface.define(:config, '0.0.1') do subject.print("libdir", "ssldir") Puppet.settings[:configprint].should == "libdir,ssldir" end + + it "should always return nil" do + Puppet.settings.stubs(:puts) + Puppet.settings.expects(:print_config_options) + subject.print("libdir").should be_nil + end end -- cgit From 78371a739bcf1b1d76496e9038fa4b076a27032f Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Thu, 24 Mar 2011 09:25:33 -0700 Subject: (#6770) Refactor Puppet::Interface#initialize. P::I#initialize now takes a name and a version (and an optional block). The options hash has been removed, though it may be reintroduced if a legitimate use case can be made for it (so far, it's only been used for the version number). Reviewed-By: Jacob Helwig --- spec/unit/interface/action_builder_spec.rb | 2 +- spec/unit/interface/action_spec.rb | 4 ++-- spec/unit/interface/indirector_spec.rb | 4 ++-- spec/unit/interface/interface_collection_spec.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb index 2c2f3b14c..27e817fe9 100644 --- a/spec/unit/interface/action_builder_spec.rb +++ b/spec/unit/interface/action_builder_spec.rb @@ -13,7 +13,7 @@ describe Puppet::Interface::ActionBuilder do end it "should define a method on the interface which invokes the action" do - interface = Puppet::Interface.new(:action_builder_test_interface, :version => '0.0.1') + interface = Puppet::Interface.new(:action_builder_test_interface, '0.0.1') action = Puppet::Interface::ActionBuilder.build(interface, :foo) do invoke do "invoked the method" diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb index 246ae9622..292caabb9 100644 --- a/spec/unit/interface/action_spec.rb +++ b/spec/unit/interface/action_spec.rb @@ -24,7 +24,7 @@ describe Puppet::Interface::Action do describe "when invoking" do it "should be able to call other actions on the same object" do - interface = Puppet::Interface.new(:my_interface, :version => '0.0.1') do + interface = Puppet::Interface.new(:my_interface, '0.0.1') do action(:foo) do invoke { 25 } end @@ -56,7 +56,7 @@ describe Puppet::Interface::Action do end end - interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface, :version => '0.0.1') do + interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface, '0.0.1') do action(:baz) do invoke { "the value of foo in baz is '#{foo}'" } end diff --git a/spec/unit/interface/indirector_spec.rb b/spec/unit/interface/indirector_spec.rb index b14058eca..4b2beaefc 100644 --- a/spec/unit/interface/indirector_spec.rb +++ b/spec/unit/interface/indirector_spec.rb @@ -5,7 +5,7 @@ require 'puppet/interface/indirector' describe Puppet::Interface::Indirector do before do - @instance = Puppet::Interface::Indirector.new(:test, :version => '0.0.1') + @instance = Puppet::Interface::Indirector.new(:test, '0.0.1') @indirection = stub 'indirection', :name => :stub_indirection @@ -24,7 +24,7 @@ describe Puppet::Interface::Indirector do 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, :version => '0.0.1').indirection.should equal(Puppet::Resource::Catalog.indirection) + Puppet::Interface::Indirector.new(:catalog, '0.0.1').indirection.should equal(Puppet::Resource::Catalog.indirection) end end diff --git a/spec/unit/interface/interface_collection_spec.rb b/spec/unit/interface/interface_collection_spec.rb index 193d31b1e..a404d85a6 100644 --- a/spec/unit/interface/interface_collection_spec.rb +++ b/spec/unit/interface/interface_collection_spec.rb @@ -67,7 +67,7 @@ describe Puppet::Interface::InterfaceCollection do describe "::register" do it "should store the interface by name" do - interface = Puppet::Interface.new(:my_interface, :version => '0.0.1') + interface = Puppet::Interface.new(:my_interface, '0.0.1') subject.register(interface) subject.instance_variable_get("@interfaces").should == {:my_interface => {'0.0.1' => interface}} end -- cgit From 1af9bb232ed73f16789f465e89a0d498c39e1b78 Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Thu, 24 Mar 2011 15:06:21 -0700 Subject: (#6770) Add version lookup and comparison. Reviewed-By: Jacob Helwig --- spec/unit/interface/interface_collection_spec.rb | 102 +++++++++++++++++++++++ 1 file changed, 102 insertions(+) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/interface_collection_spec.rb b/spec/unit/interface/interface_collection_spec.rb index a404d85a6..a943c2ec2 100644 --- a/spec/unit/interface/interface_collection_spec.rb +++ b/spec/unit/interface/interface_collection_spec.rb @@ -1,6 +1,7 @@ #!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'tmpdir' describe Puppet::Interface::InterfaceCollection do before :all do @@ -18,6 +19,107 @@ describe Puppet::Interface::InterfaceCollection do describe "::interfaces" do end + describe "::versions" do + before :each do + @dir = Dir.mktmpdir + @lib = FileUtils.mkdir_p(File.join @dir, 'puppet', 'interface') + $LOAD_PATH.push(@dir) + end + + after :each do + FileUtils.remove_entry_secure @dir + $LOAD_PATH.pop + end + + it "should return an empty array when no versions are loadable" do + subject.versions(:fozzie).should == [] + end + + it "should return versions loadable as puppet/interface/v{version}/{name}" do + FileUtils.mkdir_p(File.join @lib, 'v1.0.0') + FileUtils.touch(File.join @lib, 'v1.0.0', 'fozzie.rb') + subject.versions(:fozzie).should == ['1.0.0'] + end + + it "should an ordered list of all versions loadable as puppet/interface/v{version}/{name}" do + %w[ 1.2.1rc2 1.2.1beta1 1.2.1rc1 1.2.1 1.2.2 ].each do |version| + FileUtils.mkdir_p(File.join @lib, "v#{version}") + FileUtils.touch(File.join @lib, "v#{version}", 'fozzie.rb') + end + subject.versions(:fozzie).should == %w[ 1.2.1beta1 1.2.1rc1 1.2.1rc2 1.2.1 1.2.2 ] + end + + it "should not return a version for an empty puppet/interface/v{version}/{name}" do + FileUtils.mkdir_p(File.join @lib, 'v1.0.0', 'fozzie') + subject.versions(:fozzie).should == [] + end + + it "should an ordered list of all versions loadable as puppet/interface/v{version}/{name}/*.rb" do + %w[ 1.2.1rc2 1.2.1beta1 1.2.1rc1 1.2.1 1.2.2 ].each do |version| + FileUtils.mkdir_p(File.join @lib, "v#{version}", "fozzie") + FileUtils.touch(File.join @lib, "v#{version}", 'fozzie', 'action.rb') + end + subject.versions(:fozzie).should == %w[ 1.2.1beta1 1.2.1rc1 1.2.1rc2 1.2.1 1.2.2 ] + end + end + + describe "::compare_versions" do + # (a <=> b) should be: + # -1 if a < b + # 0 if a == b + # 1 if a > b + it 'should sort major version numbers numerically' do + subject.compare_versions('1.0.0', '2.0.0').should == -1 + subject.compare_versions('2.0.0', '1.1.1').should == 1 + subject.compare_versions('2.0.0', '10.0.0').should == -1 + end + + it 'should sort minor version numbers numerically' do + subject.compare_versions('0.1.0', '0.2.0').should == -1 + subject.compare_versions('0.2.0', '0.1.1').should == 1 + subject.compare_versions('0.2.0', '0.10.0').should == -1 + end + + it 'should sort tiny version numbers numerically' do + subject.compare_versions('0.0.1', '0.0.2').should == -1 + subject.compare_versions('0.0.2', '0.0.1').should == 1 + subject.compare_versions('0.0.2', '0.0.10').should == -1 + end + + it 'should sort major version before minor version' do + subject.compare_versions('1.1.0', '1.2.0').should == -1 + subject.compare_versions('1.2.0', '1.1.1').should == 1 + subject.compare_versions('1.2.0', '1.10.0').should == -1 + + subject.compare_versions('1.1.0', '2.2.0').should == -1 + subject.compare_versions('2.2.0', '1.1.1').should == 1 + subject.compare_versions('2.2.0', '1.10.0').should == 1 + end + + it 'should sort minor version before tiny version' do + subject.compare_versions('0.1.1', '0.1.2').should == -1 + subject.compare_versions('0.1.2', '0.1.1').should == 1 + subject.compare_versions('0.1.2', '0.1.10').should == -1 + + subject.compare_versions('0.1.1', '0.2.2').should == -1 + subject.compare_versions('0.2.2', '0.1.1').should == 1 + subject.compare_versions('0.2.2', '0.1.10').should == 1 + end + + it 'should sort appended strings asciibetically' do + subject.compare_versions('0.0.0a', '0.0.0b').should == -1 + subject.compare_versions('0.0.0beta1', '0.0.0beta2').should == -1 + subject.compare_versions('0.0.0beta1', '0.0.0rc1').should == -1 + subject.compare_versions('0.0.0beta1', '0.0.0alpha1').should == 1 + subject.compare_versions('0.0.0beta1', '0.0.0beta1').should == 0 + end + + it "should sort appended strings before 'whole' versions" do + subject.compare_versions('0.0.1a', '0.0.1').should == -1 + subject.compare_versions('0.0.1', '0.0.1beta').should == 1 + end + end + describe "::[]" do before :each do subject.instance_variable_get("@interfaces")[:foo]['0.0.1'] = 10 -- cgit From 6aea116701b8e03558ef7a5a15766b267af14281 Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Thu, 24 Mar 2011 18:55:32 -0700 Subject: (#6770) Add support for version :latest. Specifying a version of `:latest` will find the most recent version of the named interface installed in your RUBYLIB, and attempt to load that. This is unlikely to provide a stable dependency in the future, so should be used sparingly, acknowledging the dangers. Reviewed-By: Daniel Pittman --- spec/unit/interface/interface_collection_spec.rb | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/interface_collection_spec.rb b/spec/unit/interface/interface_collection_spec.rb index a943c2ec2..3e4b9d624 100644 --- a/spec/unit/interface/interface_collection_spec.rb +++ b/spec/unit/interface/interface_collection_spec.rb @@ -63,6 +63,32 @@ describe Puppet::Interface::InterfaceCollection do end end + describe "::validate_version" do + it 'should permit three number versions' do + subject.validate_version('10.10.10').should == true + end + + it 'should permit versions with appended descriptions' do + subject.validate_version('10.10.10beta').should == true + end + + it 'should not permit versions with more than three numbers' do + subject.validate_version('1.2.3.4').should == false + end + + it 'should not permit versions with only two numbers' do + subject.validate_version('10.10').should == false + end + + it 'should not permit versions with only one number' do + subject.validate_version('123').should == false + end + + it 'should not permit versions with text in any position but at the end' do + subject.validate_version('v1.1.1').should == false + end + end + describe "::compare_versions" do # (a <=> b) should be: # -1 if a < b @@ -125,6 +151,17 @@ describe Puppet::Interface::InterfaceCollection do subject.instance_variable_get("@interfaces")[:foo]['0.0.1'] = 10 end + before :each do + @dir = Dir.mktmpdir + @lib = FileUtils.mkdir_p(File.join @dir, 'puppet', 'interface') + $LOAD_PATH.push(@dir) + end + + after :each do + FileUtils.remove_entry_secure @dir + $LOAD_PATH.pop + end + it "should return the interface with the given name" do subject["foo", '0.0.1'].should == 10 end @@ -133,6 +170,15 @@ describe Puppet::Interface::InterfaceCollection do subject.expects(:require).with('puppet/interface/v0.0.1/bar') subject["bar", '0.0.1'] end + + it "should attempt to load the interface with the greatest version for specified version :latest" do + %w[ 1.2.1 1.2.2 ].each do |version| + FileUtils.mkdir_p(File.join @lib, "v#{version}") + FileUtils.touch(File.join @lib, "v#{version}", 'fozzie.rb') + end + subject.expects(:require).with('puppet/interface/v1.2.2/fozzie') + subject['fozzie', :latest] + end end describe "::interface?" do -- cgit From b859baa04737644e40002f511c5941d002a956e3 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Sat, 26 Mar 2011 00:12:17 -0700 Subject: MAINT: the API is officially named "string" as of this moment. Now that we have settled on the final public name for the API, "Puppet::String", mass-rename and mass-edit all the files to follow. Reviewed-By: Randall Hansen --- spec/unit/interface/action_builder_spec.rb | 30 --- spec/unit/interface/action_manager_spec.rb | 216 ------------------ spec/unit/interface/action_spec.rb | 75 ------- spec/unit/interface/catalog_spec.rb | 6 - spec/unit/interface/certificate_request_spec.rb | 6 - .../interface/certificate_revocation_list_spec.rb | 6 - spec/unit/interface/certificate_spec.rb | 6 - spec/unit/interface/config_spec.rb | 24 -- spec/unit/interface/configurer_spec.rb | 24 -- spec/unit/interface/facts_spec.rb | 21 -- spec/unit/interface/file_spec.rb | 6 - spec/unit/interface/indirector_spec.rb | 55 ----- spec/unit/interface/interface_collection_spec.rb | 249 --------------------- spec/unit/interface/key_spec.rb | 6 - spec/unit/interface/node_spec.rb | 9 - spec/unit/interface/report_spec.rb | 6 - spec/unit/interface/resource_spec.rb | 6 - spec/unit/interface/resource_type_spec.rb | 6 - 18 files changed, 757 deletions(-) delete mode 100644 spec/unit/interface/action_builder_spec.rb delete mode 100755 spec/unit/interface/action_manager_spec.rb delete mode 100644 spec/unit/interface/action_spec.rb delete mode 100644 spec/unit/interface/catalog_spec.rb delete mode 100644 spec/unit/interface/certificate_request_spec.rb delete mode 100644 spec/unit/interface/certificate_revocation_list_spec.rb delete mode 100644 spec/unit/interface/certificate_spec.rb delete mode 100644 spec/unit/interface/config_spec.rb delete mode 100644 spec/unit/interface/configurer_spec.rb delete mode 100644 spec/unit/interface/facts_spec.rb delete mode 100644 spec/unit/interface/file_spec.rb delete mode 100644 spec/unit/interface/indirector_spec.rb delete mode 100644 spec/unit/interface/interface_collection_spec.rb delete mode 100644 spec/unit/interface/key_spec.rb delete mode 100644 spec/unit/interface/node_spec.rb delete mode 100644 spec/unit/interface/report_spec.rb delete mode 100644 spec/unit/interface/resource_spec.rb delete mode 100644 spec/unit/interface/resource_type_spec.rb (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb deleted file mode 100644 index 27e817fe9..000000000 --- a/spec/unit/interface/action_builder_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/action_builder' - -describe Puppet::Interface::ActionBuilder do - describe "::build" do - it "should build an action" do - action = Puppet::Interface::ActionBuilder.build(nil,:foo) do - end - action.should be_a(Puppet::Interface::Action) - action.name.should == "foo" - end - - it "should define a method on the interface which invokes the action" do - interface = Puppet::Interface.new(:action_builder_test_interface, '0.0.1') - action = Puppet::Interface::ActionBuilder.build(interface, :foo) do - invoke do - "invoked the method" - end - end - - interface.foo.should == "invoked the method" - end - - it "should require a block" do - lambda { Puppet::Interface::ActionBuilder.build(nil,:foo) }.should raise_error("Action 'foo' must specify a block") - end - end -end diff --git a/spec/unit/interface/action_manager_spec.rb b/spec/unit/interface/action_manager_spec.rb deleted file mode 100755 index 3aff7ac11..000000000 --- a/spec/unit/interface/action_manager_spec.rb +++ /dev/null @@ -1,216 +0,0 @@ -#!/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 - subject { ActionManagerTester.new } - - describe "when included in a class" do - it "should be able to define an action" do - subject.action(:foo) do - invoke { "something "} - end - end - - it "should be able to define a 'script' style action" do - subject.script :bar do - "a bar is where beer is found" - end - end - - it "should be able to list defined actions" do - subject.action(:foo) do - invoke { "something" } - end - subject.action(:bar) do - invoke { "something" } - end - - subject.actions.should =~ [:foo, :bar] - end - - it "should list 'script' actions" do - subject.script :foo do "foo" end - subject.actions.should =~ [:foo] - end - - it "should list both script and normal actions" do - subject.action :foo do - invoke do "foo" end - end - subject.script :bar do "a bar is where beer is found" end - - subject.actions.should =~ [:foo, :bar] - end - - it "should be able to indicate when an action is defined" do - subject.action(:foo) do - invoke { "something" } - end - - subject.should be_action(:foo) - end - - it "should indicate an action is defined for script actions" do - subject.script :foo do "foo" end - subject.should be_action :foo - end - - it "should correctly treat action names specified as strings" do - subject.action(:foo) do - invoke { "something" } - end - - subject.should be_action("foo") - end - end - - describe "when used to extend a class" do - subject { Class.new.extend(Puppet::Interface::ActionManager) } - - it "should be able to define an action" do - subject.action(:foo) do - invoke { "something "} - end - end - - it "should be able to list defined actions" do - subject.action(:foo) do - invoke { "something" } - end - subject.action(:bar) do - invoke { "something" } - end - - subject.actions.should include(:bar) - subject.actions.should include(:foo) - end - - it "should be able to indicate when an action is defined" do - subject.action(:foo) { "something" } - subject.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) do - invoke { "something "} - end - end - - it "should create an instance method when an action is defined at the class level" do - @klass.action(:foo) do - invoke { "something" } - end - @instance.foo.should == "something" - end - - it "should be able to define an action at the instance level" do - @instance.action(:foo) do - invoke { "something "} - end - end - - it "should create an instance method when an action is defined at the instance level" do - @instance.action(:foo) do - invoke { "something" } - end - @instance.foo.should == "something" - end - - it "should be able to list actions defined at the class level" do - @klass.action(:foo) do - invoke { "something" } - end - @klass.action(:bar) do - invoke { "something" } - end - - @klass.actions.should include(:bar) - @klass.actions.should include(:foo) - end - - it "should be able to list actions defined at the instance level" do - @instance.action(:foo) do - invoke { "something" } - end - @instance.action(:bar) do - invoke { "something" } - end - - @instance.actions.should include(:bar) - @instance.actions.should include(:foo) - end - - it "should be able to list actions defined at both instance and class level" do - @klass.action(:foo) do - invoke { "something" } - end - @instance.action(:bar) do - invoke { "something" } - end - - @instance.actions.should include(:bar) - @instance.actions.should include(:foo) - end - - it "should be able to indicate when an action is defined at the class level" do - @klass.action(:foo) do - invoke { "something" } - end - @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) do - invoke { "something" } - end - @instance.should be_action(:foo) - end - - it "should list actions defined in superclasses" do - @subclass = Class.new(@klass) - @instance = @subclass.new - - @klass.action(:parent) do - invoke { "a" } - end - @subclass.action(:sub) do - invoke { "a" } - end - @instance.action(:instance) do - invoke { "a" } - end - - @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) do - invoke { "something" } - end - @instance.foo.should == "something" - end - end -end diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb deleted file mode 100644 index 292caabb9..000000000 --- a/spec/unit/interface/action_spec.rb +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/interface/action' - -describe Puppet::Interface::Action do - describe "when validating the action name" do - it "should require a name" do - lambda { Puppet::Interface::Action.new(nil,nil) }.should raise_error("'' is an invalid action name") - end - - it "should not allow empty names" do - lambda { Puppet::Interface::Action.new(nil,'') }.should raise_error("'' is an invalid action name") - end - - it "should not allow names with whitespace" do - lambda { Puppet::Interface::Action.new(nil,'foo bar') }.should raise_error("'foo bar' is an invalid action name") - end - - it "should not allow names beginning with dashes" do - lambda { Puppet::Interface::Action.new(nil,'-foobar') }.should raise_error("'-foobar' is an invalid action name") - end - end - - describe "when invoking" do - it "should be able to call other actions on the same object" do - interface = Puppet::Interface.new(:my_interface, '0.0.1') do - action(:foo) do - invoke { 25 } - end - - action(:bar) do - invoke { "the value of foo is '#{foo}'" } - end - end - interface.foo.should == 25 - interface.bar.should == "the value of foo is '25'" - end - - # bar is a class action calling a class action - # quux is a class action calling an instance action - # baz is an instance action calling a class action - # qux is an instance action calling an instance action - it "should be able to call other actions on the same object when defined on a class" do - class Puppet::Interface::MyInterfaceBaseClass < Puppet::Interface - action(:foo) do - invoke { 25 } - end - - action(:bar) do - invoke { "the value of foo is '#{foo}'" } - end - - action(:quux) do - invoke { "qux told me #{qux}" } - end - end - - interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface, '0.0.1') do - action(:baz) do - invoke { "the value of foo in baz is '#{foo}'" } - end - - action(:qux) do - invoke { baz } - end - end - interface.foo.should == 25 - interface.bar.should == "the value of foo is '25'" - interface.quux.should == "qux told me the value of foo in baz is '25'" - interface.baz.should == "the value of foo in baz is '25'" - interface.qux.should == "the value of foo in baz is '25'" - end - end -end diff --git a/spec/unit/interface/catalog_spec.rb b/spec/unit/interface/catalog_spec.rb deleted file mode 100644 index c615181ed..000000000 --- a/spec/unit/interface/catalog_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::Interface.define(:catalog, '0.0.1') do -end diff --git a/spec/unit/interface/certificate_request_spec.rb b/spec/unit/interface/certificate_request_spec.rb deleted file mode 100644 index 0143ebc85..000000000 --- a/spec/unit/interface/certificate_request_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::Interface.define(:certificate_request, '0.0.1') do -end diff --git a/spec/unit/interface/certificate_revocation_list_spec.rb b/spec/unit/interface/certificate_revocation_list_spec.rb deleted file mode 100644 index 9655dd3fa..000000000 --- a/spec/unit/interface/certificate_revocation_list_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::Interface.define(:certificate_revocation_list, '0.0.1') do -end diff --git a/spec/unit/interface/certificate_spec.rb b/spec/unit/interface/certificate_spec.rb deleted file mode 100644 index e5c63e456..000000000 --- a/spec/unit/interface/certificate_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::Interface.define(:certificate, '0.0.1') do -end diff --git a/spec/unit/interface/config_spec.rb b/spec/unit/interface/config_spec.rb deleted file mode 100644 index 2e82b0b08..000000000 --- a/spec/unit/interface/config_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::Interface.define(:config, '0.0.1') do - it "should use Settings#print_config_options when asked to print" do - Puppet.settings.stubs(:puts) - Puppet.settings.expects(:print_config_options) - subject.print - end - - it "should set 'configprint' to all desired values and call print_config_options when a specific value is provided" do - Puppet.settings.stubs(:puts) - Puppet.settings.expects(:print_config_options) - subject.print("libdir", "ssldir") - Puppet.settings[:configprint].should == "libdir,ssldir" - end - - it "should always return nil" do - Puppet.settings.stubs(:puts) - Puppet.settings.expects(:print_config_options) - subject.print("libdir").should be_nil - end -end diff --git a/spec/unit/interface/configurer_spec.rb b/spec/unit/interface/configurer_spec.rb deleted file mode 100644 index e97e63b65..000000000 --- a/spec/unit/interface/configurer_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'puppet/indirector/catalog/rest' -require 'tempfile' - -describe Puppet::Interface.define(:configurer, '0.0.1') do - describe "#synchronize" do - it "should retrieve and apply a catalog and return a report" do - dirname = Dir.mktmpdir("puppetdir") - Puppet[:vardir] = dirname - Puppet[:confdir] = dirname - @catalog = Puppet::Resource::Catalog.new - @file = Puppet::Resource.new(:file, File.join(dirname, "tmp_dir_resource"), :parameters => {:ensure => :present}) - @catalog.add_resource(@file) - Puppet::Resource::Catalog::Rest.any_instance.stubs(:find).returns(@catalog) - - report = subject.synchronize("foo") - - report.kind.should == "apply" - report.status.should == "changed" - end - end -end diff --git a/spec/unit/interface/facts_spec.rb b/spec/unit/interface/facts_spec.rb deleted file mode 100644 index 5f0214fd5..000000000 --- a/spec/unit/interface/facts_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::Interface.define(:facts, '0.0.1') do - it "should define an 'upload' fact" do - subject.should be_action(:upload) - end - - it "should set its default format to :yaml" do - subject.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/file_spec.rb b/spec/unit/interface/file_spec.rb deleted file mode 100644 index bd6e31c0e..000000000 --- a/spec/unit/interface/file_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::Interface.define(:file, '0.0.1') do -end diff --git a/spec/unit/interface/indirector_spec.rb b/spec/unit/interface/indirector_spec.rb deleted file mode 100644 index 4b2beaefc..000000000 --- a/spec/unit/interface/indirector_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/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, '0.0.1') - - @indirection = stub 'indirection', :name => :stub_indirection - - @instance.stubs(:indirection).returns @indirection - 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 - 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, '0.0.1').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 - 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 - - it "should define a class-level 'info' action" do - Puppet::Interface::Indirector.should be_action(:info) - end -end diff --git a/spec/unit/interface/interface_collection_spec.rb b/spec/unit/interface/interface_collection_spec.rb deleted file mode 100644 index 3e4b9d624..000000000 --- a/spec/unit/interface/interface_collection_spec.rb +++ /dev/null @@ -1,249 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -require 'tmpdir' - -describe Puppet::Interface::InterfaceCollection do - before :all do - @interfaces = subject.instance_variable_get("@interfaces").dup - end - - before :each do - subject.instance_variable_get("@interfaces").clear - end - - after :all do - subject.instance_variable_set("@interfaces", @interfaces) - end - - describe "::interfaces" do - end - - describe "::versions" do - before :each do - @dir = Dir.mktmpdir - @lib = FileUtils.mkdir_p(File.join @dir, 'puppet', 'interface') - $LOAD_PATH.push(@dir) - end - - after :each do - FileUtils.remove_entry_secure @dir - $LOAD_PATH.pop - end - - it "should return an empty array when no versions are loadable" do - subject.versions(:fozzie).should == [] - end - - it "should return versions loadable as puppet/interface/v{version}/{name}" do - FileUtils.mkdir_p(File.join @lib, 'v1.0.0') - FileUtils.touch(File.join @lib, 'v1.0.0', 'fozzie.rb') - subject.versions(:fozzie).should == ['1.0.0'] - end - - it "should an ordered list of all versions loadable as puppet/interface/v{version}/{name}" do - %w[ 1.2.1rc2 1.2.1beta1 1.2.1rc1 1.2.1 1.2.2 ].each do |version| - FileUtils.mkdir_p(File.join @lib, "v#{version}") - FileUtils.touch(File.join @lib, "v#{version}", 'fozzie.rb') - end - subject.versions(:fozzie).should == %w[ 1.2.1beta1 1.2.1rc1 1.2.1rc2 1.2.1 1.2.2 ] - end - - it "should not return a version for an empty puppet/interface/v{version}/{name}" do - FileUtils.mkdir_p(File.join @lib, 'v1.0.0', 'fozzie') - subject.versions(:fozzie).should == [] - end - - it "should an ordered list of all versions loadable as puppet/interface/v{version}/{name}/*.rb" do - %w[ 1.2.1rc2 1.2.1beta1 1.2.1rc1 1.2.1 1.2.2 ].each do |version| - FileUtils.mkdir_p(File.join @lib, "v#{version}", "fozzie") - FileUtils.touch(File.join @lib, "v#{version}", 'fozzie', 'action.rb') - end - subject.versions(:fozzie).should == %w[ 1.2.1beta1 1.2.1rc1 1.2.1rc2 1.2.1 1.2.2 ] - end - end - - describe "::validate_version" do - it 'should permit three number versions' do - subject.validate_version('10.10.10').should == true - end - - it 'should permit versions with appended descriptions' do - subject.validate_version('10.10.10beta').should == true - end - - it 'should not permit versions with more than three numbers' do - subject.validate_version('1.2.3.4').should == false - end - - it 'should not permit versions with only two numbers' do - subject.validate_version('10.10').should == false - end - - it 'should not permit versions with only one number' do - subject.validate_version('123').should == false - end - - it 'should not permit versions with text in any position but at the end' do - subject.validate_version('v1.1.1').should == false - end - end - - describe "::compare_versions" do - # (a <=> b) should be: - # -1 if a < b - # 0 if a == b - # 1 if a > b - it 'should sort major version numbers numerically' do - subject.compare_versions('1.0.0', '2.0.0').should == -1 - subject.compare_versions('2.0.0', '1.1.1').should == 1 - subject.compare_versions('2.0.0', '10.0.0').should == -1 - end - - it 'should sort minor version numbers numerically' do - subject.compare_versions('0.1.0', '0.2.0').should == -1 - subject.compare_versions('0.2.0', '0.1.1').should == 1 - subject.compare_versions('0.2.0', '0.10.0').should == -1 - end - - it 'should sort tiny version numbers numerically' do - subject.compare_versions('0.0.1', '0.0.2').should == -1 - subject.compare_versions('0.0.2', '0.0.1').should == 1 - subject.compare_versions('0.0.2', '0.0.10').should == -1 - end - - it 'should sort major version before minor version' do - subject.compare_versions('1.1.0', '1.2.0').should == -1 - subject.compare_versions('1.2.0', '1.1.1').should == 1 - subject.compare_versions('1.2.0', '1.10.0').should == -1 - - subject.compare_versions('1.1.0', '2.2.0').should == -1 - subject.compare_versions('2.2.0', '1.1.1').should == 1 - subject.compare_versions('2.2.0', '1.10.0').should == 1 - end - - it 'should sort minor version before tiny version' do - subject.compare_versions('0.1.1', '0.1.2').should == -1 - subject.compare_versions('0.1.2', '0.1.1').should == 1 - subject.compare_versions('0.1.2', '0.1.10').should == -1 - - subject.compare_versions('0.1.1', '0.2.2').should == -1 - subject.compare_versions('0.2.2', '0.1.1').should == 1 - subject.compare_versions('0.2.2', '0.1.10').should == 1 - end - - it 'should sort appended strings asciibetically' do - subject.compare_versions('0.0.0a', '0.0.0b').should == -1 - subject.compare_versions('0.0.0beta1', '0.0.0beta2').should == -1 - subject.compare_versions('0.0.0beta1', '0.0.0rc1').should == -1 - subject.compare_versions('0.0.0beta1', '0.0.0alpha1').should == 1 - subject.compare_versions('0.0.0beta1', '0.0.0beta1').should == 0 - end - - it "should sort appended strings before 'whole' versions" do - subject.compare_versions('0.0.1a', '0.0.1').should == -1 - subject.compare_versions('0.0.1', '0.0.1beta').should == 1 - end - end - - describe "::[]" do - before :each do - subject.instance_variable_get("@interfaces")[:foo]['0.0.1'] = 10 - end - - before :each do - @dir = Dir.mktmpdir - @lib = FileUtils.mkdir_p(File.join @dir, 'puppet', 'interface') - $LOAD_PATH.push(@dir) - end - - after :each do - FileUtils.remove_entry_secure @dir - $LOAD_PATH.pop - end - - it "should return the interface with the given name" do - subject["foo", '0.0.1'].should == 10 - end - - it "should attempt to load the interface if it isn't found" do - subject.expects(:require).with('puppet/interface/v0.0.1/bar') - subject["bar", '0.0.1'] - end - - it "should attempt to load the interface with the greatest version for specified version :latest" do - %w[ 1.2.1 1.2.2 ].each do |version| - FileUtils.mkdir_p(File.join @lib, "v#{version}") - FileUtils.touch(File.join @lib, "v#{version}", 'fozzie.rb') - end - subject.expects(:require).with('puppet/interface/v1.2.2/fozzie') - subject['fozzie', :latest] - end - end - - describe "::interface?" do - before :each do - subject.instance_variable_get("@interfaces")[:foo]['0.0.1'] = 10 - end - - it "should return true if the interface specified is registered" do - subject.interface?("foo", '0.0.1').should == true - end - - it "should attempt to require the interface if it is not registered" do - subject.expects(:require).with('puppet/interface/v0.0.1/bar') - subject.interface?("bar", '0.0.1') - end - - it "should return true if requiring the interface registered it" do - subject.stubs(:require).with do - subject.instance_variable_get("@interfaces")[:bar]['0.0.1'] = 20 - end - subject.interface?("bar", '0.0.1').should == true - end - - it "should return false if the interface is not registered" do - subject.stubs(:require).returns(true) - subject.interface?("bar", '0.0.1').should == false - end - - it "should return false if there is a LoadError requiring the interface" do - subject.stubs(:require).raises(LoadError) - subject.interface?("bar", '0.0.1').should == false - end - end - - describe "::register" do - it "should store the interface by name" do - interface = Puppet::Interface.new(:my_interface, '0.0.1') - subject.register(interface) - subject.instance_variable_get("@interfaces").should == {:my_interface => {'0.0.1' => interface}} - end - end - - describe "::underscorize" do - faulty = [1, "#foo", "$bar", "sturm und drang", :"sturm und drang"] - valid = { - "Foo" => :foo, - :Foo => :foo, - "foo_bar" => :foo_bar, - :foo_bar => :foo_bar, - "foo-bar" => :foo_bar, - :"foo-bar" => :foo_bar, - } - - valid.each do |input, expect| - it "should map #{input.inspect} to #{expect.inspect}" do - result = subject.underscorize(input) - result.should == expect - end - end - - faulty.each do |input| - it "should fail when presented with #{input.inspect} (#{input.class})" do - expect { subject.underscorize(input) }. - should raise_error ArgumentError, /not a valid interface name/ - end - end - end -end diff --git a/spec/unit/interface/key_spec.rb b/spec/unit/interface/key_spec.rb deleted file mode 100644 index 519497808..000000000 --- a/spec/unit/interface/key_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::Interface.define(:key, '0.0.1') do -end diff --git a/spec/unit/interface/node_spec.rb b/spec/unit/interface/node_spec.rb deleted file mode 100644 index 91914c3ae..000000000 --- a/spec/unit/interface/node_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::Interface.define(:node, '0.0.1') do - it "should set its default format to :yaml" do - subject.default_format.should == :yaml - end -end diff --git a/spec/unit/interface/report_spec.rb b/spec/unit/interface/report_spec.rb deleted file mode 100644 index 23855db09..000000000 --- a/spec/unit/interface/report_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::Interface.define(:report, '0.0.1') do -end diff --git a/spec/unit/interface/resource_spec.rb b/spec/unit/interface/resource_spec.rb deleted file mode 100644 index 408be250c..000000000 --- a/spec/unit/interface/resource_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::Interface.define(:resource, '0.0.1') do -end diff --git a/spec/unit/interface/resource_type_spec.rb b/spec/unit/interface/resource_type_spec.rb deleted file mode 100644 index 860be282c..000000000 --- a/spec/unit/interface/resource_type_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') - -describe Puppet::Interface.define(:resource_type, '0.0.1') do -end -- cgit From 87ed3188e65d3f5f9c2c32a409b271d1b39684b9 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Thu, 7 Apr 2011 15:44:28 -0700 Subject: (#7012) Split plumbing into Puppet::Interface This splits out the plumbing into the Puppet::Interface namespace, and uses Puppet::Faces for all the public-facing code. The fault line is "what you care about if you are using or writing a face", which is public, against "what you care about to enable either of those two", which is the plumbing. --- spec/unit/interface/action_builder_spec.rb | 59 +++++++ spec/unit/interface/action_manager_spec.rb | 233 ++++++++++++++++++++++++++++ spec/unit/interface/action_spec.rb | 173 +++++++++++++++++++++ spec/unit/interface/face_collection_spec.rb | 184 ++++++++++++++++++++++ spec/unit/interface/option_builder_spec.rb | 29 ++++ spec/unit/interface/option_spec.rb | 75 +++++++++ 6 files changed, 753 insertions(+) create mode 100755 spec/unit/interface/action_builder_spec.rb create mode 100755 spec/unit/interface/action_manager_spec.rb create mode 100755 spec/unit/interface/action_spec.rb create mode 100755 spec/unit/interface/face_collection_spec.rb create mode 100644 spec/unit/interface/option_builder_spec.rb create mode 100644 spec/unit/interface/option_spec.rb (limited to 'spec/unit/interface') diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb new file mode 100755 index 000000000..ae9cc83d4 --- /dev/null +++ b/spec/unit/interface/action_builder_spec.rb @@ -0,0 +1,59 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/action_builder' + +describe Puppet::Interface::ActionBuilder do + describe "::build" do + it "should build an action" do + action = Puppet::Interface::ActionBuilder.build(nil, :foo) do + end + action.should be_a(Puppet::Interface::Action) + action.name.should == :foo + end + + it "should define a method on the face which invokes the action" do + face = Puppet::Interface.new(:action_builder_test_interface, '0.0.1') + action = Puppet::Interface::ActionBuilder.build(face, :foo) do + when_invoked do + "invoked the method" + end + end + + face.foo.should == "invoked the method" + end + + it "should require a block" do + expect { Puppet::Interface::ActionBuilder.build(nil, :foo) }. + should raise_error("Action :foo must specify a block") + end + + describe "when handling options" do + let :face do Puppet::Interface.new(:option_handling, '0.0.1') end + + it "should have a #option DSL function" do + method = nil + Puppet::Interface::ActionBuilder.build(face, :foo) do + method = self.method(:option) + end + method.should be + end + + it "should define an option without a block" do + action = Puppet::Interface::ActionBuilder.build(face, :foo) do + option "--bar" + end + action.should be_option :bar + end + + it "should accept an empty block" do + action = Puppet::Interface::ActionBuilder.build(face, :foo) do + option "--bar" do + # This space left deliberately blank. + end + end + action.should be_option :bar + end + end + end +end diff --git a/spec/unit/interface/action_manager_spec.rb b/spec/unit/interface/action_manager_spec.rb new file mode 100755 index 000000000..50bea5f89 --- /dev/null +++ b/spec/unit/interface/action_manager_spec.rb @@ -0,0 +1,233 @@ +#!/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 + subject { ActionManagerTester.new } + + describe "when included in a class" do + it "should be able to define an action" do + subject.action(:foo) do + when_invoked { "something "} + end + end + + it "should be able to define a 'script' style action" do + subject.script :bar do + "a bar is where beer is found" + end + end + + it "should be able to list defined actions" do + subject.action(:foo) do + when_invoked { "something" } + end + subject.action(:bar) do + when_invoked { "something" } + end + + subject.actions.should =~ [:foo, :bar] + end + + it "should list 'script' actions" do + subject.script :foo do "foo" end + subject.actions.should =~ [:foo] + end + + it "should list both script and normal actions" do + subject.action :foo do + when_invoked do "foo" end + end + subject.script :bar do "a bar is where beer is found" end + + subject.actions.should =~ [:foo, :bar] + end + + it "should be able to indicate when an action is defined" do + subject.action(:foo) do + when_invoked { "something" } + end + + subject.should be_action(:foo) + end + + it "should indicate an action is defined for script actions" do + subject.script :foo do "foo" end + subject.should be_action :foo + end + + it "should correctly treat action names specified as strings" do + subject.action(:foo) do + when_invoked { "something" } + end + + subject.should be_action("foo") + end + end + + describe "when used to extend a class" do + subject { Class.new.extend(Puppet::Interface::ActionManager) } + + it "should be able to define an action" do + subject.action(:foo) do + when_invoked { "something "} + end + end + + it "should be able to list defined actions" do + subject.action(:foo) do + when_invoked { "something" } + end + subject.action(:bar) do + when_invoked { "something" } + end + + subject.actions.should include(:bar) + subject.actions.should include(:foo) + end + + it "should be able to indicate when an action is defined" do + subject.action(:foo) { "something" } + subject.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) do + when_invoked { "something "} + end + end + + it "should create an instance method when an action is defined at the class level" do + @klass.action(:foo) do + when_invoked { "something" } + end + @instance.foo.should == "something" + end + + it "should be able to define an action at the instance level" do + @instance.action(:foo) do + when_invoked { "something "} + end + end + + it "should create an instance method when an action is defined at the instance level" do + @instance.action(:foo) do + when_invoked { "something" } + end + @instance.foo.should == "something" + end + + it "should be able to list actions defined at the class level" do + @klass.action(:foo) do + when_invoked { "something" } + end + @klass.action(:bar) do + when_invoked { "something" } + end + + @klass.actions.should include(:bar) + @klass.actions.should include(:foo) + end + + it "should be able to list actions defined at the instance level" do + @instance.action(:foo) do + when_invoked { "something" } + end + @instance.action(:bar) do + when_invoked { "something" } + end + + @instance.actions.should include(:bar) + @instance.actions.should include(:foo) + end + + it "should be able to list actions defined at both instance and class level" do + @klass.action(:foo) do + when_invoked { "something" } + end + @instance.action(:bar) do + when_invoked { "something" } + end + + @instance.actions.should include(:bar) + @instance.actions.should include(:foo) + end + + it "should be able to indicate when an action is defined at the class level" do + @klass.action(:foo) do + when_invoked { "something" } + end + @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) do + when_invoked { "something" } + end + @instance.should be_action(:foo) + end + + it "should list actions defined in superclasses" do + @subclass = Class.new(@klass) + @instance = @subclass.new + + @klass.action(:parent) do + when_invoked { "a" } + end + @subclass.action(:sub) do + when_invoked { "a" } + end + @instance.action(:instance) do + when_invoked { "a" } + end + + @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) do + when_invoked { "something" } + end + @instance.foo.should == "something" + end + end + + describe "#get_action" do + let :parent_class do + parent_class = Class.new(Puppet::Interface) + parent_class.action(:foo) {} + parent_class + end + + it "should check that we can find inherited actions when we are a class" do + Class.new(parent_class).get_action(:foo).name.should == :foo + end + + it "should check that we can find inherited actions when we are an instance" do + instance = parent_class.new(:foo, '0.0.0') + instance.get_action(:foo).name.should == :foo + end + end +end diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb new file mode 100755 index 000000000..4801a3cc8 --- /dev/null +++ b/spec/unit/interface/action_spec.rb @@ -0,0 +1,173 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'puppet/interface/action' + +describe Puppet::Interface::Action do + describe "when validating the action name" do + [nil, '', 'foo bar', '-foobar'].each do |input| + it "should treat #{input.inspect} as an invalid name" do + expect { Puppet::Interface::Action.new(nil, input) }. + should raise_error(/is an invalid action name/) + end + end + end + + describe "when invoking" do + it "should be able to call other actions on the same object" do + face = Puppet::Interface.new(:my_face, '0.0.1') do + action(:foo) do + when_invoked { 25 } + end + + action(:bar) do + when_invoked { "the value of foo is '#{foo}'" } + end + end + face.foo.should == 25 + face.bar.should == "the value of foo is '25'" + end + + # bar is a class action calling a class action + # quux is a class action calling an instance action + # baz is an instance action calling a class action + # qux is an instance action calling an instance action + it "should be able to call other actions on the same object when defined on a class" do + class Puppet::Interface::MyInterfaceBaseClass < Puppet::Interface + action(:foo) do + when_invoked { 25 } + end + + action(:bar) do + when_invoked { "the value of foo is '#{foo}'" } + end + + action(:quux) do + when_invoked { "qux told me #{qux}" } + end + end + + face = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_face, '0.0.1') do + action(:baz) do + when_invoked { "the value of foo in baz is '#{foo}'" } + end + + action(:qux) do + when_invoked { baz } + end + end + face.foo.should == 25 + face.bar.should == "the value of foo is '25'" + face.quux.should == "qux told me the value of foo in baz is '25'" + face.baz.should == "the value of foo in baz is '25'" + face.qux.should == "the value of foo in baz is '25'" + end + + context "when calling the Ruby API" do + let :face do + Puppet::Interface.new(:ruby_api, '1.0.0') do + action :bar do + when_invoked do |options| + options + end + end + end + end + + it "should work when no options are supplied" do + options = face.bar + options.should == {} + end + + it "should work when options are supplied" do + options = face.bar :bar => "beer" + options.should == { :bar => "beer" } + end + end + end + + describe "with action-level options" do + it "should support options with an empty block" do + face = Puppet::Interface.new(:action_level_options, '0.0.1') do + action :foo do + option "--bar" do + # this line left deliberately blank + end + end + end + + face.should_not be_option :bar + face.get_action(:foo).should be_option :bar + end + + it "should return only action level options when there are no face options" do + face = Puppet::Interface.new(:action_level_options, '0.0.1') do + action :foo do option "--bar" end + end + + face.get_action(:foo).options.should =~ [:bar] + end + + describe "with both face and action options" do + let :face do + Puppet::Interface.new(:action_level_options, '0.0.1') do + action :foo do option "--bar" end + action :baz do option "--bim" end + option "--quux" + end + end + + it "should return combined face and action options" do + face.get_action(:foo).options.should =~ [:bar, :quux] + end + + it "should fetch options that the face inherited" do + parent = Class.new(Puppet::Interface) + parent.option "--foo" + child = parent.new(:inherited_options, '0.0.1') do + option "--bar" + action :action do option "--baz" end + end + + action = child.get_action(:action) + action.should be + + [:baz, :bar, :foo].each do |name| + action.get_option(name).should be_an_instance_of Puppet::Interface::Option + end + end + + it "should get an action option when asked" do + face.get_action(:foo).get_option(:bar). + should be_an_instance_of Puppet::Interface::Option + end + + it "should get a face option when asked" do + face.get_action(:foo).get_option(:quux). + should be_an_instance_of Puppet::Interface::Option + end + + it "should return options only for this action" do + face.get_action(:baz).options.should =~ [:bim, :quux] + end + end + + it_should_behave_like "things that declare options" do + def add_options_to(&block) + face = Puppet::Interface.new(:with_options, '0.0.1') do + action(:foo, &block) + end + face.get_action(:foo) + end + end + + it "should fail when a face option duplicates an action option" do + expect { + Puppet::Interface.new(:action_level_options, '0.0.1') do + option "--foo" + action :bar do option "--foo" end + end + }.should raise_error ArgumentError, /Option foo conflicts with existing option foo/i + end + end +end diff --git a/spec/unit/interface/face_collection_spec.rb b/spec/unit/interface/face_collection_spec.rb new file mode 100755 index 000000000..de6d29cee --- /dev/null +++ b/spec/unit/interface/face_collection_spec.rb @@ -0,0 +1,184 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') +require 'tmpdir' + +describe Puppet::Interface::FaceCollection do + # To avoid cross-pollution we have to save and restore both the hash + # containing all the interface data, and the array used by require. Restoring + # both means that we don't leak side-effects across the code. --daniel 2011-04-06 + before :each do + @original_faces = subject.instance_variable_get("@faces").dup + @original_required = $".dup + subject.instance_variable_get("@faces").clear + end + + after :each do + subject.instance_variable_set("@faces", @original_faces) + $".clear ; @original_required.each do |item| $" << item end + end + + describe "::faces" do + it "REVISIT: should have some tests here, if we describe it" + end + + describe "::validate_version" do + it 'should permit three number versions' do + subject.validate_version('10.10.10').should == true + end + + it 'should permit versions with appended descriptions' do + subject.validate_version('10.10.10beta').should == true + end + + it 'should not permit versions with more than three numbers' do + subject.validate_version('1.2.3.4').should == false + end + + it 'should not permit versions with only two numbers' do + subject.validate_version('10.10').should == false + end + + it 'should not permit versions with only one number' do + subject.validate_version('123').should == false + end + + it 'should not permit versions with text in any position but at the end' do + subject.validate_version('v1.1.1').should == false + end + end + + describe "::[]" do + before :each do + subject.instance_variable_get("@faces")[:foo]['0.0.1'] = 10 + end + + before :each do + @dir = Dir.mktmpdir + @lib = FileUtils.mkdir_p(File.join @dir, 'puppet', 'faces') + $LOAD_PATH.push(@dir) + end + + after :each do + FileUtils.remove_entry_secure @dir + $LOAD_PATH.pop + end + + it "should return the faces with the given name" do + subject["foo", '0.0.1'].should == 10 + end + + it "should attempt to load the faces if it isn't found" do + subject.expects(:require).with('puppet/faces/bar') + subject["bar", '0.0.1'] + end + + it "should attempt to load the default faces for the specified version :current" do + subject.expects(:require).never # except... + subject.expects(:require).with('puppet/faces/fozzie') + subject['fozzie', :current] + end + end + + describe "::face?" do + before :each do + subject.instance_variable_get("@faces")[:foo]['0.0.1'] = 10 + end + + it "should return true if the faces specified is registered" do + subject.face?("foo", '0.0.1').should == true + end + + it "should attempt to require the faces if it is not registered" do + subject.expects(:require).with do |file| + subject.instance_variable_get("@faces")[:bar]['0.0.1'] = true + file == 'puppet/faces/bar' + end + subject.face?("bar", '0.0.1').should == true + end + + it "should return true if requiring the faces registered it" do + subject.stubs(:require).with do + subject.instance_variable_get("@faces")[:bar]['0.0.1'] = 20 + end + end + + it "should return false if the faces is not registered" do + subject.stubs(:require).returns(true) + subject.face?("bar", '0.0.1').should be_false + end + + it "should return false if the faces file itself is missing" do + subject.stubs(:require). + raises(LoadError, 'no such file to load -- puppet/faces/bar') + subject.face?("bar", '0.0.1').should be_false + end + + it "should register the version loaded by `:current` as `:current`" do + subject.expects(:require).with do |file| + subject.instance_variable_get("@faces")[:huzzah]['2.0.1'] = :huzzah_faces + file == 'puppet/faces/huzzah' + end + subject.face?("huzzah", :current) + subject.instance_variable_get("@faces")[:huzzah][:current].should == :huzzah_faces + end + + context "with something on disk" do + before :each do + write_scratch_faces :huzzah do |fh| + fh.puts < {'0.0.1' => faces}} + end + end + + describe "::underscorize" do + faulty = [1, "#foo", "$bar", "sturm und drang", :"sturm und drang"] + valid = { + "Foo" => :foo, + :Foo => :foo, + "foo_bar" => :foo_bar, + :foo_bar => :foo_bar, + "foo-bar" => :foo_bar, + :"foo-bar" => :foo_bar, + } + + valid.each do |input, expect| + it "should map #{input.inspect} to #{expect.inspect}" do + result = subject.underscorize(input) + result.should == expect + end + end + + faulty.each do |input| + it "should fail when presented with #{input.inspect} (#{input.class})" do + expect { subject.underscorize(input) }. + should raise_error ArgumentError, /not a valid face name/ + end + end + end +end diff --git a/spec/unit/interface/option_builder_spec.rb b/spec/unit/interface/option_builder_spec.rb new file mode 100644 index 000000000..fae48324e --- /dev/null +++ b/spec/unit/interface/option_builder_spec.rb @@ -0,0 +1,29 @@ +require 'puppet/interface/option_builder' + +describe Puppet::Interface::OptionBuilder do + let :face do Puppet::Interface.new(:option_builder_testing, '0.0.1') end + + it "should be able to construct an option without a block" do + Puppet::Interface::OptionBuilder.build(face, "--foo"). + should be_an_instance_of Puppet::Interface::Option + end + + describe "when using the DSL block" do + it "should work with an empty block" do + option = Puppet::Interface::OptionBuilder.build(face, "--foo") do + # This block deliberately left blank. + end + + option.should be_an_instance_of Puppet::Interface::Option + end + + it "should support documentation declarations" do + text = "this is the description" + option = Puppet::Interface::OptionBuilder.build(face, "--foo") do + desc text + end + option.should be_an_instance_of Puppet::Interface::Option + option.desc.should == text + end + end +end diff --git a/spec/unit/interface/option_spec.rb b/spec/unit/interface/option_spec.rb new file mode 100644 index 000000000..3bcd121e2 --- /dev/null +++ b/spec/unit/interface/option_spec.rb @@ -0,0 +1,75 @@ +require 'puppet/interface/option' + +describe Puppet::Interface::Option do + let :face do Puppet::Interface.new(:option_testing, '0.0.1') end + + describe "#optparse_to_name" do + ["", "=BAR", " BAR", "=bar", " bar"].each do |postfix| + { "--foo" => :foo, "-f" => :f }.each do |base, expect| + input = base + postfix + it "should map #{input.inspect} to #{expect.inspect}" do + option = Puppet::Interface::Option.new(face, input) + option.name.should == expect + end + end + end + + [:foo, 12, nil, {}, []].each do |input| + it "should fail sensible when given #{input.inspect}" do + expect { Puppet::Interface::Option.new(face, input) }. + should raise_error ArgumentError, /is not valid for an option argument/ + end + end + + ["-foo", "-foo=BAR", "-foo BAR"].each do |input| + it "should fail with a single dash for long option #{input.inspect}" do + expect { Puppet::Interface::Option.new(face, input) }. + should raise_error ArgumentError, /long options need two dashes \(--\)/ + end + end + end + + it "requires a face when created" do + expect { Puppet::Interface::Option.new }. + should raise_error ArgumentError, /wrong number of arguments/ + end + + it "also requires some declaration arguments when created" do + expect { Puppet::Interface::Option.new(face) }. + should raise_error ArgumentError, /No option declarations found/ + end + + it "should infer the name from an optparse string" do + option = Puppet::Interface::Option.new(face, "--foo") + option.name.should == :foo + end + + it "should infer the name when multiple optparse string are given" do + option = Puppet::Interface::Option.new(face, "--foo", "-f") + option.name.should == :foo + end + + it "should prefer the first long option name over a short option name" do + option = Puppet::Interface::Option.new(face, "-f", "--foo") + option.name.should == :foo + end + + it "should create an instance when given a face and name" do + Puppet::Interface::Option.new(face, "--foo"). + should be_instance_of Puppet::Interface::Option + end + + describe "#to_s" do + it "should transform a symbol into a string" do + option = Puppet::Interface::Option.new(face, "--foo") + option.name.should == :foo + option.to_s.should == "foo" + end + + it "should use - rather than _ to separate words in strings but not symbols" do + option = Puppet::Interface::Option.new(face, "--foo-bar") + option.name.should == :foo_bar + option.to_s.should == "foo-bar" + end + end +end -- cgit