summaryrefslogtreecommitdiffstats
path: root/spec/unit/face
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-04-13 00:17:57 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-13 00:17:57 -0700
commit4dd6a77481400b7eeac3377267d092d4c6d22da3 (patch)
treef95d292596144832805a9b57a55bc440f7cfaa43 /spec/unit/face
parent941c56a283265cdf5a951ecaae63580b60486c52 (diff)
downloadpuppet-4dd6a77481400b7eeac3377267d092d4c6d22da3.tar.gz
puppet-4dd6a77481400b7eeac3377267d092d4c6d22da3.tar.xz
puppet-4dd6a77481400b7eeac3377267d092d4c6d22da3.zip
(#7056) Use 'face' rather than 'faces' in the production code.
After some discussion we decided that most uses of the Puppet Face infrastructure were about single faces on their own, not about the collection, and so we were better referring to Puppet::Face[...] in code. This implements that by translating names and references in the Ruby code to the new, s-less, name.
Diffstat (limited to 'spec/unit/face')
-rwxr-xr-xspec/unit/face/catalog_spec.rb4
-rwxr-xr-xspec/unit/face/certificate_request_spec.rb3
-rwxr-xr-xspec/unit/face/certificate_revocation_list_spec.rb3
-rwxr-xr-xspec/unit/face/certificate_spec.rb14
-rwxr-xr-xspec/unit/face/config_spec.rb24
-rwxr-xr-xspec/unit/face/configurer_spec.rb26
-rwxr-xr-xspec/unit/face/facts_spec.rb21
-rwxr-xr-xspec/unit/face/file_spec.rb3
-rw-r--r--spec/unit/face/help_spec.rb112
-rwxr-xr-xspec/unit/face/indirector_spec.rb60
-rwxr-xr-xspec/unit/face/key_spec.rb3
-rwxr-xr-xspec/unit/face/node_spec.rb9
-rwxr-xr-xspec/unit/face/report_spec.rb3
-rwxr-xr-xspec/unit/face/resource_spec.rb3
-rwxr-xr-xspec/unit/face/resource_type_spec.rb3
15 files changed, 291 insertions, 0 deletions
diff --git a/spec/unit/face/catalog_spec.rb b/spec/unit/face/catalog_spec.rb
new file mode 100755
index 000000000..28c2aa9be
--- /dev/null
+++ b/spec/unit/face/catalog_spec.rb
@@ -0,0 +1,4 @@
+require 'puppet/face'
+describe Puppet::Face[:catalog, '0.0.1'] do
+ it "should actually have some testing..."
+end
diff --git a/spec/unit/face/certificate_request_spec.rb b/spec/unit/face/certificate_request_spec.rb
new file mode 100755
index 000000000..a83a92df8
--- /dev/null
+++ b/spec/unit/face/certificate_request_spec.rb
@@ -0,0 +1,3 @@
+describe Puppet::Face[:certificate_request, '0.0.1'] do
+ it "should actually have some tests..."
+end
diff --git a/spec/unit/face/certificate_revocation_list_spec.rb b/spec/unit/face/certificate_revocation_list_spec.rb
new file mode 100755
index 000000000..22c0fa2bf
--- /dev/null
+++ b/spec/unit/face/certificate_revocation_list_spec.rb
@@ -0,0 +1,3 @@
+describe Puppet::Face[:certificate_revocation_list, '0.0.1'] do
+ it "should actually have some tests..."
+end
diff --git a/spec/unit/face/certificate_spec.rb b/spec/unit/face/certificate_spec.rb
new file mode 100755
index 000000000..dbcc888ad
--- /dev/null
+++ b/spec/unit/face/certificate_spec.rb
@@ -0,0 +1,14 @@
+require 'puppet/ssl/host'
+
+describe Puppet::Face[:certificate, '0.0.1'] do
+ it "should have a ca-location option" do
+ subject.should be_option :ca_location
+ end
+
+ it "should set the ca location when invoked" do
+ pending "#6983: This is broken in the actual face..."
+ Puppet::SSL::Host.expects(:ca_location=).with(:foo)
+ Puppet::SSL::Host.indirection.expects(:save)
+ subject.sign :ca_location => :foo
+ end
+end
diff --git a/spec/unit/face/config_spec.rb b/spec/unit/face/config_spec.rb
new file mode 100755
index 000000000..3657b9abd
--- /dev/null
+++ b/spec/unit/face/config_spec.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+require 'spec_helper'
+
+describe Puppet::Face[: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/face/configurer_spec.rb b/spec/unit/face/configurer_spec.rb
new file mode 100755
index 000000000..a404c926f
--- /dev/null
+++ b/spec/unit/face/configurer_spec.rb
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+
+require 'spec_helper'
+require 'puppet/indirector/catalog/rest'
+require 'tempfile'
+
+describe Puppet::Face[:configurer, '0.0.1'] do
+ describe "#synchronize" do
+ it "should retrieve and apply a catalog and return a report" do
+ pending "REVISIT: 2.7 changes broke this, and we want the merge published"
+
+ 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/face/facts_spec.rb b/spec/unit/face/facts_spec.rb
new file mode 100755
index 000000000..f574ac741
--- /dev/null
+++ b/spec/unit/face/facts_spec.rb
@@ -0,0 +1,21 @@
+#!/usr/bin/env ruby
+
+require 'spec_helper'
+
+describe Puppet::Face[: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/face/file_spec.rb b/spec/unit/face/file_spec.rb
new file mode 100755
index 000000000..97e8bcc08
--- /dev/null
+++ b/spec/unit/face/file_spec.rb
@@ -0,0 +1,3 @@
+describe Puppet::Face[:file, '0.0.1'] do
+ it "should actually have some tests..."
+end
diff --git a/spec/unit/face/help_spec.rb b/spec/unit/face/help_spec.rb
new file mode 100644
index 000000000..e67f29e07
--- /dev/null
+++ b/spec/unit/face/help_spec.rb
@@ -0,0 +1,112 @@
+require 'spec_helper'
+require 'puppet/face/help'
+
+describe Puppet::Face[:help, '0.0.1'] do
+ it "should have a help action" do
+ subject.should be_action :help
+ end
+
+ it "should have a default action of help" do
+ pending "REVISIT: we don't support default actions yet"
+ end
+
+ it "should accept a call with no arguments" do
+ expect { subject.help() }.should_not raise_error
+ end
+
+ it "should accept a face name" do
+ expect { subject.help(:help) }.should_not raise_error
+ end
+
+ it "should accept a face and action name" do
+ expect { subject.help(:help, :help) }.should_not raise_error
+ end
+
+ it "should fail if more than a face and action are given" do
+ expect { subject.help(:help, :help, :for_the_love_of_god) }.
+ should raise_error ArgumentError
+ end
+
+ it "should treat :current and 'current' identically" do
+ subject.help(:help, :version => :current).should ==
+ subject.help(:help, :version => 'current')
+ end
+
+ it "should complain when the request version of a face is missing" do
+ expect { subject.help(:huzzah, :bar, :version => '17.0.0') }.
+ should raise_error Puppet::Error
+ end
+
+ it "should find a face by version" do
+ face = Puppet::Face[:huzzah, :current]
+ subject.help(:huzzah, :version => face.version).
+ should == subject.help(:huzzah, :version => :current)
+ end
+
+ context "when listing subcommands" do
+ subject { Puppet::Face[:help, :current].help }
+
+ # Check a precondition for the next block; if this fails you have
+ # something odd in your set of face, and we skip testing things that
+ # matter. --daniel 2011-04-10
+ it "should have at least one face with a summary" do
+ Puppet::Face.faces.should be_any do |name|
+ Puppet::Face[name, :current].summary
+ end
+ end
+
+ Puppet::Face.faces.each do |name|
+ face = Puppet::Face[name, :current]
+ summary = face.summary
+
+ it { should =~ %r{ #{name} } }
+ it { should =~ %r{ #{name} +#{summary}} } if summary
+ end
+
+ Puppet::Face[:help, :current].legacy_applications.each do |appname|
+ it { should =~ %r{ #{appname} } }
+
+ summary = Puppet::Face[:help, :current].horribly_extract_summary_from(appname)
+ summary and it { should =~ %r{ #{summary}\b} }
+ end
+ end
+
+ context "#legacy_applications" do
+ subject { Puppet::Face[:help, :current].legacy_applications }
+
+ # If we don't, these tests are ... less than useful, because they assume
+ # it. When this breaks you should consider ditching the entire feature
+ # and tests, but if not work out how to fake one. --daniel 2011-04-11
+ it { should have_at_least(1).item }
+
+ # Meh. This is nasty, but we can't control the other list; the specific
+ # bug that caused these to be listed is annoyingly subtle and has a nasty
+ # fix, so better to have a "fail if you do something daft" trigger in
+ # place here, I think. --daniel 2011-04-11
+ %w{face_base indirection_base}.each do |name|
+ it { should_not include name }
+ end
+ end
+
+ context "help for legacy applications" do
+ subject { Puppet::Face[:help, :current] }
+ let :appname do subject.legacy_applications.first end
+
+ # This test is purposely generic, so that as we eliminate legacy commands
+ # we don't get into a loop where we either test a face-based replacement
+ # and fail to notice breakage, or where we have to constantly rewrite this
+ # test and all. --daniel 2011-04-11
+ it "should return the legacy help when given the subcommand" do
+ help = subject.help(appname)
+ help.should =~ /puppet-#{appname}/
+ %w{SYNOPSIS USAGE DESCRIPTION OPTIONS COPYRIGHT}.each do |heading|
+ help.should =~ /^#{heading}$/
+ end
+ end
+
+ it "should fail when asked for an action on a legacy command" do
+ expect { subject.help(appname, :whatever) }.
+ to raise_error ArgumentError, /Legacy subcommands don't take actions/
+ end
+ end
+end
diff --git a/spec/unit/face/indirector_spec.rb b/spec/unit/face/indirector_spec.rb
new file mode 100755
index 000000000..269e05543
--- /dev/null
+++ b/spec/unit/face/indirector_spec.rb
@@ -0,0 +1,60 @@
+#!/usr/bin/env ruby
+
+require 'spec_helper'
+require 'puppet/face/indirector'
+
+describe Puppet::Face::Indirector do
+ subject do
+ instance = Puppet::Face::Indirector.new(:test, '0.0.1')
+ indirection = stub('indirection',
+ :name => :stub_indirection,
+ :reset_terminus_class => nil)
+ instance.stubs(:indirection).returns indirection
+ instance
+ end
+
+ it "should be able to return a list of indirections" do
+ Puppet::Face::Indirector.indirections.should be_include("catalog")
+ end
+
+ it "should be able to return a list of terminuses for a given indirection" do
+ Puppet::Face::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::Face.stubs(:load_actions)
+ Puppet::Face::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::Face::Indirector.should be_action(method)
+ end
+
+ it "should call the indirection method with options when the '#{method}' action is invoked" do
+ subject.indirection.expects(method).with(:test, "myargs", {})
+ subject.send(method, :test, "myargs")
+ end
+ it "should forward passed options" do
+ subject.indirection.expects(method).with(:test, "action", {'one'=>'1'})
+ subject.send(method, :test, 'action', {'one'=>'1'})
+ end
+ end
+
+ it "should be able to override its indirection name" do
+ subject.set_indirection_name :foo
+ subject.indirection_name.should == :foo
+ end
+
+ it "should be able to set its terminus class" do
+ subject.indirection.expects(:terminus_class=).with(:myterm)
+ subject.set_terminus(:myterm)
+ end
+
+ it "should define a class-level 'info' action" do
+ Puppet::Face::Indirector.should be_action(:info)
+ end
+end
diff --git a/spec/unit/face/key_spec.rb b/spec/unit/face/key_spec.rb
new file mode 100755
index 000000000..10d664790
--- /dev/null
+++ b/spec/unit/face/key_spec.rb
@@ -0,0 +1,3 @@
+describe Puppet::Face[:key, '0.0.1'] do
+ it "should actually have some tests..."
+end
diff --git a/spec/unit/face/node_spec.rb b/spec/unit/face/node_spec.rb
new file mode 100755
index 000000000..d27f41b56
--- /dev/null
+++ b/spec/unit/face/node_spec.rb
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+
+require 'spec_helper'
+
+describe Puppet::Face[: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/face/report_spec.rb b/spec/unit/face/report_spec.rb
new file mode 100755
index 000000000..b1b28167e
--- /dev/null
+++ b/spec/unit/face/report_spec.rb
@@ -0,0 +1,3 @@
+describe Puppet::Face[:report, '0.0.1'] do
+ it "should actually have some tests..."
+end
diff --git a/spec/unit/face/resource_spec.rb b/spec/unit/face/resource_spec.rb
new file mode 100755
index 000000000..084e2a6a9
--- /dev/null
+++ b/spec/unit/face/resource_spec.rb
@@ -0,0 +1,3 @@
+describe Puppet::Face[:resource, '0.0.1'] do
+ it "should actually have some tests..."
+end
diff --git a/spec/unit/face/resource_type_spec.rb b/spec/unit/face/resource_type_spec.rb
new file mode 100755
index 000000000..2adaedca1
--- /dev/null
+++ b/spec/unit/face/resource_type_spec.rb
@@ -0,0 +1,3 @@
+describe Puppet::Face[:resource_type, '0.0.1'] do
+ it "should actually have some tests..."
+end