puppet 2.6.7 → 2.6.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (80) hide show
  1. data/CHANGELOG +49 -0
  2. data/install.rb +6 -2
  3. data/lib/puppet.rb +1 -1
  4. data/lib/puppet/application.rb +16 -8
  5. data/lib/puppet/application/agent.rb +2 -0
  6. data/lib/puppet/application/apply.rb +3 -0
  7. data/lib/puppet/application/master.rb +1 -1
  8. data/lib/puppet/configurer.rb +10 -1
  9. data/lib/puppet/defaults.rb +9 -0
  10. data/lib/puppet/file_serving/fileset.rb +1 -0
  11. data/lib/puppet/indirector/exec.rb +1 -2
  12. data/lib/puppet/indirector/report/yaml.rb +11 -0
  13. data/lib/puppet/node/environment.rb +1 -1
  14. data/lib/puppet/parameter.rb +2 -0
  15. data/lib/puppet/parameter/path.rb +42 -0
  16. data/lib/puppet/parser/compiler.rb +1 -1
  17. data/lib/puppet/parser/lexer.rb +3 -2
  18. data/lib/puppet/parser/parser_support.rb +0 -1
  19. data/lib/puppet/provider/exec/posix.rb +112 -0
  20. data/lib/puppet/provider/exec/shell.rb +17 -0
  21. data/lib/puppet/provider/group/groupadd.rb +3 -0
  22. data/lib/puppet/provider/nameservice/#directoryservice.rb# +519 -0
  23. data/lib/puppet/provider/package/gem.rb +2 -2
  24. data/lib/puppet/provider/package/macports.rb +106 -0
  25. data/lib/puppet/provider/service/debian.rb +6 -2
  26. data/lib/puppet/rails/inventory_node.rb +5 -0
  27. data/lib/puppet/reference/#providers.rb# +123 -0
  28. data/lib/puppet/resource/type_collection.rb +6 -1
  29. data/lib/puppet/simple_graph.rb +1 -1
  30. data/lib/puppet/transaction.rb +1 -1
  31. data/lib/puppet/transaction/report.rb +28 -10
  32. data/lib/puppet/type/cron.rb +3 -1
  33. data/lib/puppet/type/exec.rb +30 -167
  34. data/lib/puppet/type/file.rb +12 -1
  35. data/lib/puppet/type/file/source.rb +1 -0
  36. data/lib/puppet/type/group.rb +11 -1
  37. data/lib/puppet/type/service.rb +19 -11
  38. data/lib/puppet/util/command_line.rb +15 -12
  39. data/lib/puppet/util/command_line/puppetrun +0 -1
  40. data/lib/puppet/util/loadedfile.rb +1 -5
  41. data/lib/puppet/util/metric.rb +3 -5
  42. data/lib/puppet/util/plugins.rb +82 -0
  43. data/spec/integration/configurer_spec.rb +38 -5
  44. data/spec/integration/transaction_spec.rb +43 -42
  45. data/spec/lib/puppet_spec/verbose.rb +9 -0
  46. data/spec/shared_behaviours/path_parameters.rb +185 -0
  47. data/spec/spec_helper.rb +6 -0
  48. data/spec/unit/application/agent_spec.rb +7 -0
  49. data/spec/unit/application/apply_spec.rb +6 -0
  50. data/spec/unit/application/master_spec.rb +2 -2
  51. data/spec/unit/configurer_spec.rb +48 -0
  52. data/spec/unit/file_serving/fileset_spec.rb +8 -0
  53. data/spec/unit/indirector/certificate_status/#file_spec.rb# +188 -0
  54. data/spec/unit/indirector/exec_spec.rb +2 -3
  55. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +5 -1
  56. data/spec/unit/indirector/report/yaml_spec.rb +38 -0
  57. data/spec/unit/node/environment_spec.rb +15 -14
  58. data/spec/unit/parameter/path_spec.rb +24 -0
  59. data/spec/unit/parser/compiler_spec.rb +1 -2
  60. data/spec/unit/parser/lexer_spec.rb +12 -0
  61. data/spec/unit/provider/exec/posix_spec.rb +120 -0
  62. data/spec/unit/provider/exec/shell_spec.rb +50 -0
  63. data/spec/unit/provider/group/groupadd_spec.rb +11 -1
  64. data/spec/unit/provider/package/gem_spec.rb +11 -1
  65. data/spec/unit/provider/package/macports_spec.rb +122 -0
  66. data/spec/unit/provider/service/debian_spec.rb +14 -2
  67. data/spec/unit/resource/#type_collection_spec.rb# +463 -0
  68. data/spec/unit/resource/type_collection_spec.rb +21 -17
  69. data/spec/unit/transaction/report_spec.rb +13 -2
  70. data/spec/unit/type/cron_spec.rb +466 -18
  71. data/spec/unit/type/exec_spec.rb +633 -106
  72. data/spec/unit/type/file/source_spec.rb +1 -0
  73. data/spec/unit/type/group_spec.rb +8 -1
  74. data/spec/unit/type_spec.rb +1 -1
  75. data/spec/unit/util/loadedfile_spec.rb +7 -0
  76. data/spec/unit/util/rdoc/parser_spec.rb +2 -1
  77. data/tasks/rake/git_workflow.rake +3 -1
  78. data/test/ral/type/exec.rb +87 -176
  79. metadata +21 -5
  80. data/lib/puppet/provider/package/darwinport.rb +0 -86
@@ -47,10 +47,9 @@ describe Puppet::Indirector::Exec do
47
47
  @searcher.find(@request).should be_nil
48
48
  end
49
49
 
50
- it "should return nil and log an error if there's an execution failure" do
50
+ it "should raise an exception if there's an execution failure" do
51
51
  @searcher.expects(:execute).with(%w{/echo foo}).raises(Puppet::ExecutionFailure.new("message"))
52
52
 
53
- Puppet.expects(:err)
54
- @searcher.find(@request).should be_nil
53
+ lambda {@searcher.find(@request)}.should raise_exception(Puppet::Error, 'Failed to find foo via exec: message')
55
54
  end
56
55
  end
@@ -1,7 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require File.dirname(__FILE__) + '/../../../spec_helper'
4
- require 'sqlite3' rescue nil
4
+ begin
5
+ require 'sqlite3'
6
+ rescue LoadError
7
+ end
5
8
  require 'tempfile'
6
9
  require 'puppet/rails'
7
10
 
@@ -29,6 +32,7 @@ describe "Puppet::Node::Facts::InventoryActiveRecord", :if => (Puppet.features.r
29
32
 
30
33
  after :each do
31
34
  Puppet::Rails.teardown
35
+ ActiveRecord::Base.remove_connection
32
36
  end
33
37
 
34
38
  describe "#save" do
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../../../spec_helper'
4
+
5
+ require 'puppet/transaction/report'
6
+ require 'puppet/indirector/report/yaml'
7
+
8
+ describe Puppet::Transaction::Report::Yaml do
9
+ it "should be a subclass of the Yaml terminus" do
10
+ Puppet::Transaction::Report::Yaml.superclass.should equal(Puppet::Indirector::Yaml)
11
+ end
12
+
13
+ it "should have documentation" do
14
+ Puppet::Transaction::Report::Yaml.doc.should_not be_nil
15
+ end
16
+
17
+ it "should be registered with the report indirection" do
18
+ indirection = Puppet::Indirector::Indirection.instance(:report)
19
+ Puppet::Transaction::Report::Yaml.indirection.should equal(indirection)
20
+ end
21
+
22
+ it "should have its name set to :yaml" do
23
+ Puppet::Transaction::Report::Yaml.name.should == :yaml
24
+ end
25
+
26
+ it "should inconditionnally save/load from the --lastrunreport setting" do
27
+ indirection = stub 'indirection', :name => :my_yaml, :register_terminus_type => nil
28
+ Puppet::Indirector::Indirection.stubs(:instance).with(:my_yaml).returns(indirection)
29
+ store_class = Class.new(Puppet::Transaction::Report::Yaml) do
30
+ def self.to_s
31
+ "MyYaml::MyType"
32
+ end
33
+ end
34
+ store = store_class.new
35
+
36
+ store.path(:me).should == Puppet[:lastrunreport]
37
+ end
38
+ end
@@ -85,28 +85,29 @@ describe Puppet::Node::Environment do
85
85
  @env.known_resource_types.should equal(@collection)
86
86
  end
87
87
 
88
- it "should give to all threads the same collection if it didn't change" do
89
- Puppet::Resource::TypeCollection.expects(:new).with(@env).returns @collection
90
- @env.known_resource_types
88
+ it "should give to all threads using the same environment the same collection if the collection isn't stale" do
89
+ original_thread_type_collection = Puppet::Resource::TypeCollection.new(@env)
90
+ Puppet::Resource::TypeCollection.expects(:new).with(@env).returns original_thread_type_collection
91
+ @env.known_resource_types.should equal(original_thread_type_collection)
92
+
93
+ original_thread_type_collection.expects(:require_reparse?).returns(false)
94
+ Puppet::Resource::TypeCollection.stubs(:new).with(@env).returns @collection
91
95
 
92
96
  t = Thread.new {
93
- @env.known_resource_types.should equal(@collection)
97
+ @env.known_resource_types.should equal(original_thread_type_collection)
94
98
  }
95
99
  t.join
96
100
  end
97
101
 
98
- it "should give to new threads a new collection if it isn't stale" do
99
- Puppet::Resource::TypeCollection.expects(:new).with(@env).returns @collection
100
- @env.known_resource_types.expects(:stale?).returns(true)
101
-
102
- Puppet::Resource::TypeCollection.expects(:new).returns @collection
102
+ it "should generate a new TypeCollection if the current one requires reparsing" do
103
+ old_type_collection = @env.known_resource_types
104
+ old_type_collection.stubs(:require_reparse?).returns true
105
+ Thread.current[:known_resource_types] = nil
106
+ new_type_collection = @env.known_resource_types
103
107
 
104
- t = Thread.new {
105
- @env.known_resource_types.should equal(@collection)
106
- }
107
- t.join
108
+ new_type_collection.should be_a Puppet::Resource::TypeCollection
109
+ new_type_collection.should_not equal(old_type_collection)
108
110
  end
109
-
110
111
  end
111
112
 
112
113
  [:modulepath, :manifestdir].each do |setting|
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../spec_helper'))
3
+
4
+ require 'puppet/parameter/path'
5
+
6
+ [false, true].each do |arrays|
7
+ describe "Puppet::Parameter::Path with arrays #{arrays}" do
8
+ it_should_behave_like "all path parameters", :path, :array => arrays do
9
+ # The new type allows us a test that is guaranteed to go direct to our
10
+ # validation code, without passing through any "real type" overrides or
11
+ # whatever on the way.
12
+ Puppet::newtype(:test_puppet_parameter_path) do
13
+ newparam(:path, :parent => Puppet::Parameter::Path, :arrays => arrays) do
14
+ isnamevar
15
+ accept_arrays arrays
16
+ end
17
+ end
18
+
19
+ def instance(path)
20
+ Puppet::Type.type(:test_puppet_parameter_path).new(:path => path)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -581,12 +581,11 @@ describe Puppet::Parser::Compiler do
581
581
  @scope.expects(:find_hostclass).with("notfound").returns(nil)
582
582
  @compiler.evaluate_classes(%w{notfound}, @scope)
583
583
  end
584
- # I wish it would fail
585
584
  it "should log when it can't find class" do
586
585
  klasses = {'foo'=>nil}
587
586
  @node.classes = klasses
588
587
  @compiler.topscope.stubs(:find_hostclass).with('foo').returns(nil)
589
- Puppet.expects(:info).with('Could not find class foo for testnode')
588
+ Puppet.expects(:warning).with('Could not find class foo for testnode')
590
589
  @compiler.compile
591
590
  end
592
591
  end
@@ -679,3 +679,15 @@ describe "Puppet::Parser::Lexer in the old tests when lexing example files" do
679
679
  end
680
680
  end
681
681
  end
682
+
683
+ describe "when trying to lex an non-existent file" do
684
+ include PuppetSpec::Files
685
+
686
+ it "should return an empty list of tokens" do
687
+ lexer = Puppet::Parser::Lexer.new
688
+ lexer.file = nofile = tmpfile('lexer')
689
+ File.exists?(nofile).should == false
690
+
691
+ lexer.fullscan.should == [[false,false]]
692
+ end
693
+ end
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../../spec_helper'
3
+
4
+ provider_class = Puppet::Type.type(:exec).provider(:posix)
5
+
6
+ describe provider_class do
7
+ before :each do
8
+ @resource = Puppet::Resource.new(:exec, 'foo')
9
+ @provider = provider_class.new(@resource)
10
+ end
11
+
12
+ ["posix", "microsoft_windows"].each do |feature|
13
+ describe "when in #{feature} environment" do
14
+ before :each do
15
+ if feature == "microsoft_windows"
16
+ Puppet.features.stubs(:microsoft_windows?).returns(true)
17
+ Puppet.features.stubs(:posix?).returns(false)
18
+ else
19
+ Puppet.features.stubs(:posix?).returns(true)
20
+ Puppet.features.stubs(:microsoft_windows?).returns(false)
21
+ end
22
+ end
23
+
24
+ describe "#validatecmd" do
25
+ it "should fail if no path is specified and the command is not fully qualified" do
26
+ lambda { @provider.validatecmd("foo") }.should raise_error(
27
+ Puppet::Error,
28
+ "'foo' is not qualified and no path was specified. Please qualify the command or specify a path."
29
+ )
30
+ end
31
+
32
+ it "should pass if a path is given" do
33
+ @provider.resource[:path] = ['/bogus/bin']
34
+ @provider.validatecmd("../foo")
35
+ end
36
+
37
+ it "should pass if command is fully qualifed" do
38
+ @provider.resource[:path] = ['/bogus/bin']
39
+ @provider.validatecmd("/bin/blah/foo")
40
+ end
41
+ end
42
+
43
+ describe "#run" do
44
+ it "should fail if no path is specified and command does not exist" do
45
+ lambda { @provider.run("foo") }.should raise_error(ArgumentError, "Could not find command 'foo'")
46
+ end
47
+
48
+ it "should fail if the command isn't in the path" do
49
+ @provider.resource[:path] = ['/bogus/bin']
50
+ lambda { @provider.run("foo") }.should raise_error(ArgumentError, "Could not find command 'foo'")
51
+ end
52
+
53
+ it "should fail if the command isn't executable" do
54
+ @provider.resource[:path] = ['/bogus/bin']
55
+ File.stubs(:exists?).with("foo").returns(true)
56
+
57
+ lambda { @provider.run("foo") }.should raise_error(ArgumentError, "'foo' is not executable")
58
+ end
59
+
60
+ it "should not be able to execute shell builtins" do
61
+ @provider.resource[:path] = ['/bin']
62
+ lambda { @provider.run("cd ..") }.should raise_error(ArgumentError, "Could not find command 'cd'")
63
+ end
64
+
65
+ it "should execute the command if the command given includes arguments or subcommands" do
66
+ @provider.resource[:path] = ['/bogus/bin']
67
+ File.stubs(:exists?).returns(false)
68
+ File.stubs(:exists?).with("foo").returns(true)
69
+ File.stubs(:executable?).with("foo").returns(true)
70
+
71
+ Puppet::Util.expects(:execute).with() { |command, arguments| (command == ['foo bar --sillyarg=true --blah']) && (arguments.is_a? Hash) }
72
+ @provider.run("foo bar --sillyarg=true --blah")
73
+ end
74
+
75
+ it "should fail if quoted command doesn't exist" do
76
+ @provider.resource[:path] = ['/bogus/bin']
77
+ File.stubs(:exists?).returns(false)
78
+ File.stubs(:exists?).with("foo").returns(true)
79
+ File.stubs(:executable?).with("foo").returns(true)
80
+
81
+ lambda { @provider.run('"foo bar --sillyarg=true --blah"') }.should raise_error(ArgumentError, "Could not find command 'foo bar --sillyarg=true --blah'")
82
+ end
83
+
84
+ it "should execute the command if it finds it in the path and is executable" do
85
+ @provider.resource[:path] = ['/bogus/bin']
86
+ File.stubs(:exists?).with("foo").returns(true)
87
+ File.stubs(:executable?).with("foo").returns(true)
88
+ Puppet::Util.expects(:execute).with() { |command, arguments| (command == ['foo']) && (arguments.is_a? Hash) }
89
+
90
+ @provider.run("foo")
91
+ end
92
+
93
+ if feature == "microsoft_windows"
94
+ [".exe", ".ps1", ".bat", ".com", ""].each do |extension|
95
+ it "should check file extension #{extension} when it can't find the executable" do
96
+ @provider.resource[:path] = ['/bogus/bin']
97
+ File.stubs(:exists?).returns(false)
98
+ File.stubs(:exists?).with("/bogus/bin/foo#{extension}").returns(true)
99
+ File.stubs(:executable?).with("foo").returns(true)
100
+ Puppet::Util.expects(:execute).with() { |command, arguments| (command == ['foo']) && (arguments.is_a? Hash) }
101
+
102
+ @provider.run("foo")
103
+ end
104
+ end
105
+ end
106
+
107
+ it "should warn if you're overriding something in environment" do
108
+ @provider.resource[:environment] = ['WHATEVER=/something/else', 'WHATEVER=/foo']
109
+ File.stubs(:exists?).returns(false)
110
+ File.stubs(:exists?).with("foo").returns(true)
111
+ File.stubs(:executable?).with("foo").returns(true)
112
+
113
+ Puppet::Util.expects(:execute).with() { |command, arguments| (command == ['foo']) && (arguments.is_a? Hash) }
114
+ @provider.run("foo")
115
+ @logs.map {|l| "#{l.level}: #{l.message}" }.should == ["warning: Overriding environment setting 'WHATEVER' with '/foo'"]
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../../spec_helper'
3
+
4
+ provider_class = Puppet::Type.type(:exec).provider(:shell)
5
+
6
+ describe provider_class do
7
+ before :each do
8
+ @resource = Puppet::Resource.new(:exec, 'foo')
9
+ @provider = provider_class.new(@resource)
10
+ end
11
+
12
+ describe "#run" do
13
+ it "should be able to run builtin shell commands" do
14
+ output, status = @provider.run("if [ 1 = 1 ]; then echo 'blah'; fi")
15
+ status.exitstatus.should == 0
16
+ output.should == "blah\n"
17
+ end
18
+
19
+ it "should be able to run commands with single quotes in them" do
20
+ output, status = @provider.run("echo 'foo bar'")
21
+ status.exitstatus.should == 0
22
+ output.should == "foo bar\n"
23
+ end
24
+
25
+ it "should be able to run commands with double quotes in them" do
26
+ output, status = @provider.run('echo "foo bar"')
27
+ status.exitstatus.should == 0
28
+ output.should == "foo bar\n"
29
+ end
30
+
31
+ it "should be able to run multiple commands separated by a semicolon" do
32
+ output, status = @provider.run("echo 'foo' ; echo 'bar'")
33
+ status.exitstatus.should == 0
34
+ output.should == "foo\nbar\n"
35
+ end
36
+
37
+ it "should be able to read values from the environment parameter" do
38
+ @resource[:environment] = "FOO=bar"
39
+ output, status = @provider.run("echo $FOO")
40
+ status.exitstatus.should == 0
41
+ output.should == "bar\n"
42
+ end
43
+ end
44
+
45
+ describe "#validatecmd" do
46
+ it "should always return true because builtins don't need path or to be fully qualified" do
47
+ @provider.validatecmd('whateverdoesntmatter').should == true
48
+ end
49
+ end
50
+ end
@@ -10,10 +10,10 @@ describe provider_class do
10
10
  @provider = provider_class.new(@resource)
11
11
  end
12
12
 
13
- # #1360
14
13
  it "should add -o when allowdupe is enabled and the group is being created" do
15
14
  @resource.stubs(:should).returns "fakeval"
16
15
  @resource.stubs(:[]).returns "fakeval"
16
+ @resource.stubs(:system?).returns true
17
17
  @resource.expects(:allowdupe?).returns true
18
18
  @provider.expects(:execute).with { |args| args.include?("-o") }
19
19
 
@@ -28,4 +28,14 @@ describe provider_class do
28
28
 
29
29
  @provider.gid = 150
30
30
  end
31
+
32
+ it "should add -r when system is enabled and the group is being created" do
33
+ @resource.stubs(:should).returns "fakeval"
34
+ @resource.stubs(:[]).returns "fakeval"
35
+ @resource.expects(:system?).returns true
36
+ @resource.stubs(:allowdupe?).returns true
37
+ @provider.expects(:execute).with { |args| args.include?("-r") }
38
+
39
+ @provider.create
40
+ end
31
41
  end
@@ -42,8 +42,18 @@ describe provider_class do
42
42
  @provider.install
43
43
  end
44
44
 
45
+ it "should specify that documentation should not be included" do
46
+ @provider.expects(:execute).with { |args| args[3] == "--no-rdoc" }.returns ""
47
+ @provider.install
48
+ end
49
+
50
+ it "should specify that RI should not be included" do
51
+ @provider.expects(:execute).with { |args| args[4] == "--no-ri" }.returns ""
52
+ @provider.install
53
+ end
54
+
45
55
  it "should specify the package name" do
46
- @provider.expects(:execute).with { |args| args[3] == "myresource" }.returns ""
56
+ @provider.expects(:execute).with { |args| args[5] == "myresource" }.returns ""
47
57
  @provider.install
48
58
  end
49
59
 
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ provider_class = Puppet::Type.type(:package).provider(:macports)
4
+
5
+ describe provider_class do
6
+ let :resource_name do
7
+ "foo"
8
+ end
9
+
10
+ let :resource do
11
+ Puppet::Type.type(:package).new(:name => resource_name, :provider => :macports)
12
+ end
13
+
14
+ let :provider do
15
+ prov = resource.provider
16
+ prov.expects(:execute).never
17
+ prov
18
+ end
19
+
20
+ let :current_hash do
21
+ {:name => resource_name, :ensure => "1.2.3", :revision => "1", :provider => :macports}
22
+ end
23
+
24
+ describe "provider features" do
25
+ subject { provider }
26
+
27
+ it { should be_installable }
28
+ it { should be_uninstallable }
29
+ it { should be_upgradeable }
30
+ it { should be_versionable }
31
+ end
32
+
33
+ describe "when listing all instances" do
34
+ it "should call port -q installed" do
35
+ provider_class.expects(:port).with("-q", :installed).returns("")
36
+ provider_class.instances
37
+ end
38
+
39
+ it "should create instances from active ports" do
40
+ provider_class.expects(:port).returns("foo @1.234.5_2 (active)")
41
+ provider_class.instances.size.should == 1
42
+ end
43
+
44
+ it "should ignore ports that aren't activated" do
45
+ provider_class.expects(:port).returns("foo @1.234.5_2")
46
+ provider_class.instances.size.should == 0
47
+ end
48
+ end
49
+
50
+ describe "when installing" do
51
+ it "should not specify a version when ensure is set to latest" do
52
+ resource[:ensure] = :latest
53
+ provider.expects(:port).with { |flag, method, name, version|
54
+ version.should be_nil
55
+ }
56
+ provider.install
57
+ end
58
+
59
+ it "should not specify a version when ensure is set to present" do
60
+ resource[:ensure] = :present
61
+ provider.expects(:port).with { |flag, method, name, version|
62
+ version.should be_nil
63
+ }
64
+ provider.install
65
+ end
66
+
67
+ it "should specify a version when ensure is set to a version" do
68
+ resource[:ensure] = "1.2.3"
69
+ provider.expects(:port).with { |flag, method, name, version|
70
+ version.should be
71
+ }
72
+ provider.install
73
+ end
74
+ end
75
+
76
+ describe "when querying for the latest version" do
77
+ let :new_info_line do
78
+ "1.2.3 2"
79
+ end
80
+ let :infoargs do
81
+ ["-q", :info, "--line", "--version", "--revision", resource_name]
82
+ end
83
+
84
+ it "should return nil when the package cannot be found" do
85
+ resource[:name] = resource_name
86
+ provider.expects(:port).returns("")
87
+ provider.latest.should == nil
88
+ end
89
+
90
+ it "should return the current version if the installed port has the same revision" do
91
+ current_hash[:revision] = "2"
92
+ provider.expects(:port).with(*infoargs).returns(new_info_line)
93
+ provider.expects(:query).returns(current_hash)
94
+ provider.latest.should == current_hash[:ensure]
95
+ end
96
+
97
+ it "should return the new version_revision if the installed port has a lower revision" do
98
+ current_hash[:revision] = "1"
99
+ provider.expects(:port).with(*infoargs).returns(new_info_line)
100
+ provider.expects(:query).returns(current_hash)
101
+ provider.latest.should == "1.2.3_2"
102
+ end
103
+ end
104
+
105
+ describe "when updating a port" do
106
+ it "should execute port upgrade if the port is installed" do
107
+ resource[:name] = resource_name
108
+ resource[:ensure] = :present
109
+ provider.expects(:query).returns(current_hash)
110
+ provider.expects(:port).with("-q", :upgrade, resource_name)
111
+ provider.update
112
+ end
113
+
114
+ it "should execute port install if the port is not installed" do
115
+ resource[:name] = resource_name
116
+ resource[:ensure] = :present
117
+ provider.expects(:query).returns("")
118
+ provider.expects(:port).with("-q", :install, resource_name)
119
+ provider.update
120
+ end
121
+ end
122
+ end