summaryrefslogtreecommitdiff
path: root/spec/unit/module_tool
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/module_tool')
-rw-r--r--spec/unit/module_tool/application_spec.rb29
-rw-r--r--spec/unit/module_tool/metadata_spec.rb11
-rw-r--r--spec/unit/module_tool/repository_spec.rb52
-rw-r--r--spec/unit/module_tool/uninstaller_spec.rb44
4 files changed, 136 insertions, 0 deletions
diff --git a/spec/unit/module_tool/application_spec.rb b/spec/unit/module_tool/application_spec.rb
new file mode 100644
index 000000000..22d3632fd
--- /dev/null
+++ b/spec/unit/module_tool/application_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+require 'puppet/module_tool'
+
+describe Puppet::Module::Tool::Applications::Application do
+ describe 'app' do
+
+ good_versions = %w{ 1.2.4 0.0.1 0.0.0 0.0.2git-8-g3d316d1 0.0.3b1 10.100.10000
+ 0.1.2rc1 0.1.2dev-1 0.1.2svn12345 }
+ bad_versions = %w{ 0.1.2-3 0.1 0 0.1.2.3 dev }
+
+ before do
+ @app = Class.new(described_class).new
+ end
+
+ good_versions.each do |ver|
+ it "should accept version string #{ver}" do
+ @app.instance_eval("@filename=%q{puppetlabs-ntp-#{ver}}")
+ @app.parse_filename!
+ end
+ end
+
+ bad_versions.each do |ver|
+ it "should not accept version string #{ver}" do
+ @app.instance_eval("@filename=%q{puppetlabs-ntp-#{ver}}")
+ lambda { @app.parse_filename! }.should raise_error
+ end
+ end
+ end
+end
diff --git a/spec/unit/module_tool/metadata_spec.rb b/spec/unit/module_tool/metadata_spec.rb
new file mode 100644
index 000000000..85d743fbc
--- /dev/null
+++ b/spec/unit/module_tool/metadata_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+require 'puppet/module_tool'
+
+describe Puppet::Module::Tool::Metadata do
+ context "when using default values" do
+ it "should set license to 'Apache License, Version 2.0'" do
+ metadata = Puppet::Module::Tool::Metadata.new
+ metadata.license.should == "Apache License, Version 2.0"
+ end
+ end
+end
diff --git a/spec/unit/module_tool/repository_spec.rb b/spec/unit/module_tool/repository_spec.rb
new file mode 100644
index 000000000..69be1661e
--- /dev/null
+++ b/spec/unit/module_tool/repository_spec.rb
@@ -0,0 +1,52 @@
+require 'spec_helper'
+require 'net/http'
+require 'puppet/module_tool'
+
+describe Puppet::Module::Tool::Repository do
+ describe 'instances' do
+ before do
+ @repository = described_class.new('http://fake.com')
+ end
+
+ describe '#make_http_request' do
+ before do
+ # Do a mock of the Proxy call so we can do proper expects for
+ # Net::HTTP
+ Net::HTTP.expects(:Proxy).returns(Net::HTTP)
+ Net::HTTP.expects(:start)
+ end
+ context "when not given an :authenticate option" do
+ it "should authenticate" do
+ @repository.expects(:authenticate).never
+ @repository.make_http_request(nil)
+ end
+ end
+ context "when given an :authenticate option" do
+ it "should authenticate" do
+ @repository.expects(:authenticate)
+ @repository.make_http_request(nil, :authenticate => true)
+ end
+ end
+ end
+
+ describe '#authenticate' do
+ it "should set basic auth on the request" do
+ authenticated_request = stub
+ authenticated_request.expects(:basic_auth)
+ @repository.expects(:prompt).twice
+ @repository.authenticate(authenticated_request)
+ end
+ end
+
+ describe '#retrieve' do
+ before do
+ @uri = URI.parse('http://some.url.com')
+ end
+
+ it "should access the cache" do
+ @repository.cache.expects(:retrieve).with(@uri)
+ @repository.retrieve(@uri)
+ end
+ end
+ end
+end
diff --git a/spec/unit/module_tool/uninstaller_spec.rb b/spec/unit/module_tool/uninstaller_spec.rb
new file mode 100644
index 000000000..abf2db0f8
--- /dev/null
+++ b/spec/unit/module_tool/uninstaller_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+require 'puppet/module_tool'
+require 'tmpdir'
+
+describe Puppet::Module::Tool::Applications::Uninstaller do
+ include PuppetSpec::Files
+
+ describe "instances" do
+ let(:tmp_module_path1) { tmpdir("uninstaller_module_path1") }
+ let(:tmp_module_path2) { tmpdir("uninstaller_module_path2") }
+ let(:options) do
+ { :target_directories => [ tmp_module_path1, tmp_module_path2 ] }
+ end
+
+ it "should return an empty list if the module is not installed" do
+ described_class.new('foo', options).run.should == []
+ end
+
+ it "should uninstall an installed module" do
+ foo_module_path = File.join(tmp_module_path1, 'foo')
+ Dir.mkdir(foo_module_path)
+ described_class.new('foo', options).run.should == [ foo_module_path ]
+ end
+
+ it "should only uninstall the requested module" do
+ foo_module_path = File.join(tmp_module_path1, 'foo')
+ bar_module_path = File.join(tmp_module_path1, 'bar')
+ Dir.mkdir(foo_module_path)
+ Dir.mkdir(bar_module_path)
+ described_class.new('foo', options).run.should == [ foo_module_path ]
+ end
+
+ it "should uninstall the module from all target directories" do
+ foo1_module_path = File.join(tmp_module_path1, 'foo')
+ foo2_module_path = File.join(tmp_module_path2, 'foo')
+ Dir.mkdir(foo1_module_path)
+ Dir.mkdir(foo2_module_path)
+ described_class.new('foo', options).run.should == [ foo1_module_path, foo2_module_path ]
+ end
+
+ #11803
+ it "should check for broken dependencies"
+ end
+end