diff options
Diffstat (limited to 'spec/unit/type')
-rwxr-xr-x | spec/unit/type/cron_spec.rb | 2 | ||||
-rwxr-xr-x | spec/unit/type/exec_spec.rb | 62 | ||||
-rwxr-xr-x | spec/unit/type/file/checksum_spec.rb | 17 | ||||
-rwxr-xr-x | spec/unit/type/file/content_spec.rb | 3 | ||||
-rwxr-xr-x | spec/unit/type/file/selinux_spec.rb | 18 | ||||
-rwxr-xr-x | spec/unit/type/file/source_spec.rb | 54 | ||||
-rwxr-xr-x | spec/unit/type/file_spec.rb | 381 | ||||
-rwxr-xr-x | spec/unit/type/group_spec.rb | 2 | ||||
-rwxr-xr-x | spec/unit/type/mount_spec.rb | 10 | ||||
-rwxr-xr-x | spec/unit/type/noop_metaparam_spec.rb | 4 | ||||
-rwxr-xr-x | spec/unit/type/resources_spec.rb | 4 | ||||
-rwxr-xr-x | spec/unit/type/service_spec.rb | 15 | ||||
-rwxr-xr-x | spec/unit/type/ssh_authorized_key_spec.rb | 6 | ||||
-rwxr-xr-x | spec/unit/type/tidy_spec.rb | 4 | ||||
-rwxr-xr-x | spec/unit/type/user_spec.rb | 2 |
15 files changed, 273 insertions, 311 deletions
diff --git a/spec/unit/type/cron_spec.rb b/spec/unit/type/cron_spec.rb index 7bf92eb02..f2c18896b 100755 --- a/spec/unit/type/cron_spec.rb +++ b/spec/unit/type/cron_spec.rb @@ -1,7 +1,7 @@ #!/usr/bin/env rspec require 'spec_helper' -describe Puppet::Type.type(:cron) do +describe Puppet::Type.type(:cron), :unless => Puppet.features.microsoft_windows? do before do @class = Puppet::Type.type(:cron) diff --git a/spec/unit/type/exec_spec.rb b/spec/unit/type/exec_spec.rb index 47d1b8523..8146dce92 100755 --- a/spec/unit/type/exec_spec.rb +++ b/spec/unit/type/exec_spec.rb @@ -2,6 +2,8 @@ require 'spec_helper' describe Puppet::Type.type(:exec) do + include PuppetSpec::Files + def exec_tester(command, exitstatus = 0, rest = {}) @user_name = 'some_user_name' @group_name = 'some_group_name' @@ -30,12 +32,13 @@ describe Puppet::Type.type(:exec) do end before do - @command = Puppet.features.posix? ? '/bin/true whatever' : '"C:/Program Files/something.exe" whatever' + @command = make_absolute('/bin/true whatever') + @executable = make_absolute('/bin/true') + @bogus_cmd = make_absolute('/bogus/cmd') end - describe "when not stubbing the provider" do + describe "when not stubbing the provider", :fails_on_windows => true do before do - @executable = Puppet.features.posix? ? '/bin/true' : 'C:/Program Files/something.exe' File.stubs(:exists?).returns false File.stubs(:exists?).with(@executable).returns true File.stubs(:exists?).with('/bin/false').returns true @@ -139,17 +142,18 @@ describe Puppet::Type.type(:exec) do end end - it "should be able to autorequire files mentioned in the command" do + it "should be able to autorequire files mentioned in the command", :fails_on_windows => true do + foo = make_absolute('/bin/foo') catalog = Puppet::Resource::Catalog.new - tmp = Puppet::Type.type(:file).new(:name => "/bin/foo") + tmp = Puppet::Type.type(:file).new(:name => foo) catalog.add_resource tmp - execer = Puppet::Type.type(:exec).new(:name => "/bin/foo") + execer = Puppet::Type.type(:exec).new(:name => foo) catalog.add_resource execer catalog.relationship_graph.dependencies(execer).should == [tmp] end - describe "when handling the path parameter" do + describe "when handling the path parameter", :fails_on_windows => true do expect = %w{one two three four} { "an array" => expect, "a colon separated list" => "one:two:three:four", @@ -165,7 +169,7 @@ describe Puppet::Type.type(:exec) do end end - describe "when setting user" do + describe "when setting user", :fails_on_windows => true do it "should fail if we are not root" do Puppet.features.stubs(:root?).returns(false) expect { Puppet::Type.type(:exec).new(:name => @command, :user => 'input') }. @@ -184,7 +188,7 @@ describe Puppet::Type.type(:exec) do describe "when setting group" do shared_examples_for "exec[:group]" do ['one', 2, 'wheel', 4294967295, 4294967296].each do |value| - it "should accept '#{value}' without error or judgement" do + it "should accept '#{value}' without error or judgement", :fails_on_windows => true do type = Puppet::Type.type(:exec).new(:name => @command, :group => value) type[:group].should == value end @@ -205,7 +209,7 @@ describe Puppet::Type.type(:exec) do describe "when setting cwd" do it_should_behave_like "all path parameters", :cwd, :array => false do def instance(path) - Puppet::Type.type(:exec).new(:name => '/bin/true', :cwd => path) + Puppet::Type.type(:exec).new(:name => @executable, :cwd => path) end end end @@ -221,7 +225,7 @@ describe Puppet::Type.type(:exec) do if @param == :name then instance = Puppet::Type.type(:exec).new() else - instance = Puppet::Type.type(:exec).new(:name => "/bin/true") + instance = Puppet::Type.type(:exec).new(:name => @executable) end if valid then instance.provider.expects(:validatecmd).returns(true) @@ -246,7 +250,7 @@ describe Puppet::Type.type(:exec) do shared_examples_for "all exec command parameters that take arrays" do |param| describe "when given an array of inputs" do before :each do - @test = Puppet::Type.type(:exec).new(:name => "/bin/true") + @test = Puppet::Type.type(:exec).new(:name => @executable) end it "should accept the array when all commands return valid" do @@ -281,7 +285,7 @@ describe Puppet::Type.type(:exec) do describe "for simple parameters" do before :each do - @exec = Puppet::Type.type(:exec).new(:name => '/bin/true') + @exec = Puppet::Type.type(:exec).new(:name => @executable) end describe "when setting environment" do @@ -330,7 +334,8 @@ describe Puppet::Type.type(:exec) do end end - it "should fail if timeout is exceeded" do + # REMIND: the exec provider is not supported on windows yet + it "should fail if timeout is exceeded", :fails_on_windows => true do File.stubs(:exists?).with('/bin/sleep').returns(true) File.stubs(:exists?).with('sleep').returns(false) sleep_exec = Puppet::Type.type(:exec).new(:name => 'sleep 1', :path => ['/bin'], :timeout => '0.2') @@ -338,13 +343,15 @@ describe Puppet::Type.type(:exec) do end it "should convert timeout to a float" do - resource = Puppet::Type.type(:exec).new :command => "/bin/false", :timeout => "12" + command = make_absolute('/bin/false') + resource = Puppet::Type.type(:exec).new :command => command, :timeout => "12" resource[:timeout].should be_a(Float) resource[:timeout].should == 12.0 end it "should munge negative timeouts to 0.0" do - resource = Puppet::Type.type(:exec).new :command => "/bin/false", :timeout => "-12.0" + command = make_absolute('/bin/false') + resource = Puppet::Type.type(:exec).new :command => command, :timeout => "-12.0" resource.parameter(:timeout).value.should be_a(Float) resource.parameter(:timeout).value.should == 0.0 end @@ -442,7 +449,7 @@ describe Puppet::Type.type(:exec) do describe "when setting creates" do it_should_behave_like "all path parameters", :creates, :array => true do def instance(path) - Puppet::Type.type(:exec).new(:name => '/bin/true', :creates => path) + Puppet::Type.type(:exec).new(:name => @executable, :creates => path) end end end @@ -460,7 +467,7 @@ describe Puppet::Type.type(:exec) do describe "#check" do before :each do - @test = Puppet::Type.type(:exec).new(:name => "/bin/true") + @test = Puppet::Type.type(:exec).new(:name => @executable) end describe ":refreshonly" do @@ -525,8 +532,8 @@ describe Puppet::Type.type(:exec) do }.each do |param, sense| describe ":#{param}" do before :each do - @pass = "/magic/pass" - @fail = "/magic/fail" + @pass = make_absolute("/magic/pass") + @fail = make_absolute("/magic/fail") @pass_status = stub('status', :exitstatus => sense[:pass] ? 0 : 1) @fail_status = stub('status', :exitstatus => sense[:fail] ? 0 : 1) @@ -584,9 +591,9 @@ describe Puppet::Type.type(:exec) do end end - describe "#retrieve" do + describe "#retrieve", :fails_on_windows => true do before :each do - @exec_resource = Puppet::Type.type(:exec).new(:name => "/bogus/cmd") + @exec_resource = Puppet::Type.type(:exec).new(:name => @bogus_cmd) end it "should return :notrun when check_all_attributes returns true" do @@ -608,7 +615,7 @@ describe Puppet::Type.type(:exec) do describe "#output" do before :each do - @exec_resource = Puppet::Type.type(:exec).new(:name => "/bogus/cmd") + @exec_resource = Puppet::Type.type(:exec).new(:name => @bogus_cmd) end it "should return the provider's run output" do @@ -625,14 +632,15 @@ describe Puppet::Type.type(:exec) do describe "#refresh" do before :each do - @exec_resource = Puppet::Type.type(:exec).new(:name => "/bogus/cmd") + @exec_resource = Puppet::Type.type(:exec).new(:name => @bogus_cmd) end it "should call provider run with the refresh parameter if it is set" do + myother_bogus_cmd = make_absolute('/myother/bogus/cmd') provider = stub 'provider' @exec_resource.stubs(:provider).returns(provider) - @exec_resource.stubs(:[]).with(:refresh).returns('/myother/bogus/cmd') - provider.expects(:run).with('/myother/bogus/cmd') + @exec_resource.stubs(:[]).with(:refresh).returns(myother_bogus_cmd) + provider.expects(:run).with(myother_bogus_cmd) @exec_resource.refresh end @@ -641,7 +649,7 @@ describe Puppet::Type.type(:exec) do provider = stub 'provider' status = stubs "process_status" status.stubs(:exitstatus).returns("0") - provider.expects(:run).with('/bogus/cmd').returns(["silly output", status]) + provider.expects(:run).with(@bogus_cmd).returns(["silly output", status]) @exec_resource.stubs(:provider).returns(provider) @exec_resource.refresh diff --git a/spec/unit/type/file/checksum_spec.rb b/spec/unit/type/file/checksum_spec.rb index b47f617cc..30c4aba6d 100755 --- a/spec/unit/type/file/checksum_spec.rb +++ b/spec/unit/type/file/checksum_spec.rb @@ -4,7 +4,8 @@ require 'spec_helper' checksum = Puppet::Type.type(:file).attrclass(:checksum) describe checksum do before do - @resource = Puppet::Type.type(:file).new :path => "/foo/bar" + @path = Puppet.features.microsoft_windows? ? "c:/foo/bar" : "/foo/bar" + @resource = Puppet::Type.type(:file).new :path => @path @checksum = @resource.parameter(:checksum) end @@ -35,25 +36,25 @@ describe checksum do it "should use its current value when asked to sum a file's content" do @checksum.value = :md5lite - @checksum.expects(:md5lite_file).with("/foo/bar").returns "yay" - @checksum.sum_file("/foo/bar") + @checksum.expects(:md5lite_file).with(@path).returns "yay" + @checksum.sum_file(@path) end it "should use :md5 to sum a file when no value is set" do - @checksum.expects(:md5_file).with("/foo/bar").returns "yay" - @checksum.sum_file("/foo/bar") + @checksum.expects(:md5_file).with(@path).returns "yay" + @checksum.sum_file(@path) end it "should convert all sums to strings when summing files" do @checksum.value = :mtime - @checksum.expects(:mtime_file).with("/foo/bar").returns Time.now - lambda { @checksum.sum_file("/foo/bar") }.should_not raise_error + @checksum.expects(:mtime_file).with(@path).returns Time.now + lambda { @checksum.sum_file(@path) }.should_not raise_error end it "should return the summed contents of a file with a checksum label" do @resource[:checksum] = :md5 @checksum.expects(:md5_file).returns "mysum" - @checksum.sum_file("/foo/bar").should == "{md5}mysum" + @checksum.sum_file(@path).should == "{md5}mysum" end it "should return the summed contents of a stream with a checksum label" do diff --git a/spec/unit/type/file/content_spec.rb b/spec/unit/type/file/content_spec.rb index 7af5f9d83..04ec48555 100755 --- a/spec/unit/type/file/content_spec.rb +++ b/spec/unit/type/file/content_spec.rb @@ -254,6 +254,7 @@ describe content do @content.should = "{md5}foo" @content.resource.bucket.class.any_instance.stubs(:getfile).returns "foo" @content.write(@fh) + @fh.close end describe "from actual content" do @@ -298,7 +299,7 @@ describe content do end end - describe "from local source" do + describe "from local source", :fails_on_windows => true do before(:each) do @resource = Puppet::Type.type(:file).new :path => @filename, :backup => false @sourcename = tmpfile('source') diff --git a/spec/unit/type/file/selinux_spec.rb b/spec/unit/type/file/selinux_spec.rb index 2622948d0..f6e7451c7 100755 --- a/spec/unit/type/file/selinux_spec.rb +++ b/spec/unit/type/file/selinux_spec.rb @@ -1,12 +1,14 @@ #!/usr/bin/env rspec require 'spec_helper' - [:seluser, :selrole, :seltype, :selrange].each do |param| property = Puppet::Type.type(:file).attrclass(param) describe property do + include PuppetSpec::Files + before do - @resource = Puppet::Type.type(:file).new :path => "/my/file" + @path = make_absolute("/my/file") + @resource = Puppet::Type.type(:file).new :path => @path @sel = property.new :resource => @resource end @@ -18,14 +20,14 @@ require 'spec_helper' it "should retrieve nil for #{param} if there is no SELinux support" do stat = stub 'stat', :ftype => "foo" @resource.expects(:stat).returns stat - @sel.expects(:get_selinux_current_context).with("/my/file").returns nil + @sel.expects(:get_selinux_current_context).with(@path).returns nil @sel.retrieve.should be_nil end it "should retrieve #{param} if a SELinux context is found with a range" do stat = stub 'stat', :ftype => "foo" @resource.expects(:stat).returns stat - @sel.expects(:get_selinux_current_context).with("/my/file").returns "user_u:role_r:type_t:s0" + @sel.expects(:get_selinux_current_context).with(@path).returns "user_u:role_r:type_t:s0" expectedresult = case param when :seluser; "user_u" when :selrole; "role_r" @@ -38,7 +40,7 @@ require 'spec_helper' it "should retrieve #{param} if a SELinux context is found without a range" do stat = stub 'stat', :ftype => "foo" @resource.expects(:stat).returns stat - @sel.expects(:get_selinux_current_context).with("/my/file").returns "user_u:role_r:type_t" + @sel.expects(:get_selinux_current_context).with(@path).returns "user_u:role_r:type_t" expectedresult = case param when :seluser; "user_u" when :selrole; "role_r" @@ -49,13 +51,13 @@ require 'spec_helper' end it "should handle no default gracefully" do - @sel.expects(:get_selinux_default_context).with("/my/file").returns nil + @sel.expects(:get_selinux_default_context).with(@path).returns nil @sel.default.must be_nil end it "should be able to detect matchpathcon defaults" do @sel.stubs(:debug) - @sel.expects(:get_selinux_default_context).with("/my/file").returns "user_u:role_r:type_t:s0" + @sel.expects(:get_selinux_default_context).with(@path).returns "user_u:role_r:type_t:s0" expectedresult = case param when :seluser; "user_u" when :selrole; "role_r" @@ -73,7 +75,7 @@ require 'spec_helper' it "should be able to set a new context" do stat = stub 'stat', :ftype => "foo" @sel.should = %w{newone} - @sel.expects(:set_selinux_context).with("/my/file", ["newone"], param) + @sel.expects(:set_selinux_context).with(@path, ["newone"], param) @sel.sync end diff --git a/spec/unit/type/file/source_spec.rb b/spec/unit/type/file/source_spec.rb index 5665d323d..c696feaf8 100755 --- a/spec/unit/type/file/source_spec.rb +++ b/spec/unit/type/file/source_spec.rb @@ -3,9 +3,13 @@ require 'spec_helper' source = Puppet::Type.type(:file).attrclass(:source) describe Puppet::Type.type(:file).attrclass(:source) do + include PuppetSpec::Files + before do # Wow that's a messy interface to the resource. @resource = stub 'resource', :[]= => nil, :property => nil, :catalog => stub("catalog", :dependent_data_expired? => false), :line => 0, :file => '' + @foobar = make_absolute("/foo/bar") + @feebooz = make_absolute("/fee/booz") end it "should be a subclass of Parameter" do @@ -27,15 +31,7 @@ describe Puppet::Type.type(:file).attrclass(:source) do end end - it "should have a method for retrieving its metadata" do - source.new(:resource => @resource).must respond_to(:metadata) - end - - it "should have a method for setting its metadata" do - source.new(:resource => @resource).must respond_to(:metadata=) - end - - describe "when returning the metadata" do + describe "when returning the metadata", :fails_on_windows => true do before do @metadata = stub 'metadata', :source= => nil end @@ -52,58 +48,44 @@ describe Puppet::Type.type(:file).attrclass(:source) do end it "should collect its metadata using the Metadata class if it is not already set" do - @source = source.new(:resource => @resource, :value => "/foo/bar") - Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns @metadata + @source = source.new(:resource => @resource, :value => @foobar) + Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).returns @metadata @source.metadata end it "should use the metadata from the first found source" do metadata = stub 'metadata', :source= => nil - @source = source.new(:resource => @resource, :value => ["/foo/bar", "/fee/booz"]) - Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns nil - Puppet::FileServing::Metadata.indirection.expects(:find).with("/fee/booz").returns metadata + @source = source.new(:resource => @resource, :value => [@foobar, @feebooz]) + Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).returns nil + Puppet::FileServing::Metadata.indirection.expects(:find).with(@feebooz).returns metadata @source.metadata.should equal(metadata) end it "should store the found source as the metadata's source" do metadata = mock 'metadata' - @source = source.new(:resource => @resource, :value => "/foo/bar") - Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns metadata + @source = source.new(:resource => @resource, :value => @foobar) + Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).returns metadata - metadata.expects(:source=).with("/foo/bar") + metadata.expects(:source=).with(@foobar) @source.metadata end it "should fail intelligently if an exception is encountered while querying for metadata" do - @source = source.new(:resource => @resource, :value => "/foo/bar") - Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").raises RuntimeError + @source = source.new(:resource => @resource, :value => @foobar) + Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).raises RuntimeError @source.expects(:fail).raises ArgumentError lambda { @source.metadata }.should raise_error(ArgumentError) end it "should fail if no specified sources can be found" do - @source = source.new(:resource => @resource, :value => "/foo/bar") - Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns nil + @source = source.new(:resource => @resource, :value => @foobar) + Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).returns nil @source.expects(:fail).raises RuntimeError lambda { @source.metadata }.should raise_error(RuntimeError) end - - it "should expire the metadata appropriately" do - expirer = stub 'expired', :dependent_data_expired? => true - - metadata = stub 'metadata', :source= => nil - Puppet::FileServing::Metadata.indirection.expects(:find).with("/fee/booz").returns metadata - - @source = source.new(:resource => @resource, :value => ["/fee/booz"]) - @source.metadata = "foo" - - @source.stubs(:expirer).returns expirer - - @source.metadata.should_not == "foo" - end end it "should have a method for setting the desired values on the resource" do @@ -113,7 +95,7 @@ describe Puppet::Type.type(:file).attrclass(:source) do describe "when copying the source values" do before do - @resource = Puppet::Type.type(:file).new :path => "/foo/bar" + @resource = Puppet::Type.type(:file).new :path => @foobar @source = source.new(:resource => @resource) @metadata = stub 'metadata', :owner => 100, :group => 200, :mode => 123, :checksum => "{md5}asdfasdf", :ftype => "file" diff --git a/spec/unit/type/file_spec.rb b/spec/unit/type/file_spec.rb index c71bdd62a..0041ce9f2 100755 --- a/spec/unit/type/file_spec.rb +++ b/spec/unit/type/file_spec.rb @@ -37,7 +37,6 @@ describe Puppet::Type.type(:file) do end describe "#write" do - it "should propagate failures encountered when renaming the temporary file" do File.stubs(:open) @@ -92,7 +91,6 @@ describe Puppet::Type.type(:file) do lambda { @file.write :NOTUSED }.should_not raise_error(Puppet::Error) end - end end @@ -152,255 +150,204 @@ describe Puppet::Type.type(:file) do end describe "when using POSIX filenames" do - describe "on POSIX systems" do - before do - Puppet.features.stubs(:posix?).returns(true) - Puppet.features.stubs(:microsoft_windows?).returns(false) - end - - it "should autorequire its parent directory" do - file = Puppet::Type::File.new(:path => "/foo/bar") - dir = Puppet::Type::File.new(:path => "/foo") - @catalog.add_resource file - @catalog.add_resource dir - reqs = file.autorequire - reqs[0].source.must == dir - reqs[0].target.must == file - end - - it "should autorequire its nearest ancestor directory" do - file = Puppet::Type::File.new(:path => "/foo/bar/baz") - dir = Puppet::Type::File.new(:path => "/foo") - root = Puppet::Type::File.new(:path => "/") - @catalog.add_resource file - @catalog.add_resource dir - @catalog.add_resource root - reqs = file.autorequire - reqs.length.must == 1 - reqs[0].source.must == dir - reqs[0].target.must == file - end - - it "should not autorequire anything when there is no nearest ancestor directory" do - file = Puppet::Type::File.new(:path => "/foo/bar/baz") - @catalog.add_resource file - file.autorequire.should be_empty - end - - it "should not autorequire its parent dir if its parent dir is itself" do - file = Puppet::Type::File.new(:path => "/") - @catalog.add_resource file - file.autorequire.should be_empty - end - - it "should remove trailing slashes" do - file = Puppet::Type::File.new(:path => "/foo/bar/baz/") - file[:path].should == "/foo/bar/baz" - end - - it "should remove double slashes" do - file = Puppet::Type::File.new(:path => "/foo/bar//baz") - file[:path].should == "/foo/bar/baz" - end + it "should autorequire its parent directory" do + file = Puppet::Type::File.new(:path => "/foo/bar") + dir = Puppet::Type::File.new(:path => "/foo") + @catalog.add_resource file + @catalog.add_resource dir + reqs = file.autorequire + reqs[0].source.must == dir + reqs[0].target.must == file + end - it "should remove trailing double slashes" do - file = Puppet::Type::File.new(:path => "/foo/bar/baz//") - file[:path].should == "/foo/bar/baz" - end + it "should autorequire its nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "/foo/bar/baz") + dir = Puppet::Type::File.new(:path => "/foo") + root = Puppet::Type::File.new(:path => "/") + @catalog.add_resource file + @catalog.add_resource dir + @catalog.add_resource root + reqs = file.autorequire + reqs.length.must == 1 + reqs[0].source.must == dir + reqs[0].target.must == file + end - it "should leave a single slash alone" do - file = Puppet::Type::File.new(:path => "/") - file[:path].should == "/" - end + it "should not autorequire anything when there is no nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "/foo/bar/baz") + @catalog.add_resource file + file.autorequire.should be_empty + end - it "should accept a double-slash at the start of the path" do - expect { - file = Puppet::Type::File.new(:path => "//tmp/xxx") - # REVISIT: This should be wrong, later. See the next test. - # --daniel 2011-01-31 - file[:path].should == '/tmp/xxx' - }.should_not raise_error - end + it "should not autorequire its parent dir if its parent dir is itself" do + file = Puppet::Type::File.new(:path => "/") + @catalog.add_resource file + file.autorequire.should be_empty + end - # REVISIT: This is pending, because I don't want to try and audit the - # entire codebase to make sure we get this right. POSIX treats two (and - # exactly two) '/' characters at the start of the path specially. - # - # See sections 3.2 and 4.11, which allow DomainOS to be all special like - # and still have the POSIX branding and all. --daniel 2011-01-31 - it "should preserve the double-slash at the start of the path" + it "should remove trailing slashes" do + file = Puppet::Type::File.new(:path => "/foo/bar/baz/") + file[:path].should == "/foo/bar/baz" end - describe "on Microsoft Windows systems" do - before do - Puppet.features.stubs(:posix?).returns(false) - Puppet.features.stubs(:microsoft_windows?).returns(true) - end + it "should remove double slashes" do + file = Puppet::Type::File.new(:path => "/foo/bar//baz") + file[:path].should == "/foo/bar/baz" + end - it "should refuse to work" do - lambda { Puppet::Type::File.new(:path => "/foo/bar") }.should raise_error(Puppet::Error) - end + it "should remove trailing double slashes" do + file = Puppet::Type::File.new(:path => "/foo/bar/baz//") + file[:path].should == "/foo/bar/baz" end - end - describe "when using Microsoft Windows filenames", :if => Puppet.features.microsoft_windows? do - describe "on Microsoft Windows systems" do - before do - Puppet.features.stubs(:posix?).returns(false) - Puppet.features.stubs(:microsoft_windows?).returns(true) - end + it "should leave a single slash alone" do + file = Puppet::Type::File.new(:path => "/") + file[:path].should == "/" + end - it "should autorequire its parent directory" do - file = Puppet::Type::File.new(:path => "X:/foo/bar") - dir = Puppet::Type::File.new(:path => "X:/foo") - @catalog.add_resource file - @catalog.add_resource dir - reqs = file.autorequire - reqs[0].source.must == dir - reqs[0].target.must == file - end + it "should accept a double-slash at the start of the path" do + expect { + file = Puppet::Type::File.new(:path => "//tmp/xxx") + # REVISIT: This should be wrong, later. See the next test. + # --daniel 2011-01-31 + file[:path].should == '/tmp/xxx' + }.should_not raise_error + end - it "should autorequire its nearest ancestor directory" do - file = Puppet::Type::File.new(:path => "X:/foo/bar/baz") - dir = Puppet::Type::File.new(:path => "X:/foo") - root = Puppet::Type::File.new(:path => "X:/") - @catalog.add_resource file - @catalog.add_resource dir - @catalog.add_resource root - reqs = file.autorequire - reqs.length.must == 1 - reqs[0].source.must == dir - reqs[0].target.must == file - end + # REVISIT: This is pending, because I don't want to try and audit the + # entire codebase to make sure we get this right. POSIX treats two (and + # exactly two) '/' characters at the start of the path specially. + # + # See sections 3.2 and 4.11, which allow DomainOS to be all special like + # and still have the POSIX branding and all. --daniel 2011-01-31 + it "should preserve the double-slash at the start of the path" + end - it "should not autorequire anything when there is no nearest ancestor directory" do - file = Puppet::Type::File.new(:path => "X:/foo/bar/baz") - @catalog.add_resource file - file.autorequire.should be_empty - end + describe "when using Microsoft Windows filenames" do + it "should autorequire its parent directory" do + file = Puppet::Type::File.new(:path => "X:/foo/bar") + dir = Puppet::Type::File.new(:path => "X:/foo") + @catalog.add_resource file + @catalog.add_resource dir + reqs = file.autorequire + reqs[0].source.must == dir + reqs[0].target.must == file + end - it "should not autorequire its parent dir if its parent dir is itself" do - file = Puppet::Type::File.new(:path => "X:/") - @catalog.add_resource file - file.autorequire.should be_empty - end + it "should autorequire its nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "X:/foo/bar/baz") + dir = Puppet::Type::File.new(:path => "X:/foo") + root = Puppet::Type::File.new(:path => "X:/") + @catalog.add_resource file + @catalog.add_resource dir + @catalog.add_resource root + reqs = file.autorequire + reqs.length.must == 1 + reqs[0].source.must == dir + reqs[0].target.must == file + end - it "should remove trailing slashes" do - file = Puppet::Type::File.new(:path => "X:/foo/bar/baz/") - file[:path].should == "X:/foo/bar/baz" - end + it "should not autorequire anything when there is no nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "X:/foo/bar/baz") + @catalog.add_resource file + file.autorequire.should be_empty + end - it "should remove double slashes" do - file = Puppet::Type::File.new(:path => "X:/foo/bar//baz") - file[:path].should == "X:/foo/bar/baz" - end + it "should not autorequire its parent dir if its parent dir is itself" do + file = Puppet::Type::File.new(:path => "X:/") + @catalog.add_resource file + file.autorequire.should be_empty + end - it "should remove trailing double slashes" do - file = Puppet::Type::File.new(:path => "X:/foo/bar/baz//") - file[:path].should == "X:/foo/bar/baz" - end + it "should remove trailing slashes" do + file = Puppet::Type::File.new(:path => "X:/foo/bar/baz/") + file[:path].should == "X:/foo/bar/baz" + end - it "should leave a drive letter with a slash alone", :'fails_on_ruby_1.9.2' => true do - file = Puppet::Type::File.new(:path => "X:/") - file[:path].should == "X:/" - end + it "should remove double slashes" do + file = Puppet::Type::File.new(:path => "X:/foo/bar//baz") + file[:path].should == "X:/foo/bar/baz" + end - it "should add a slash to a drive letter", :'fails_on_ruby_1.9.2' => true do - file = Puppet::Type::File.new(:path => "X:") - file[:path].should == "X:/" - end + it "should remove trailing double slashes" do + file = Puppet::Type::File.new(:path => "X:/foo/bar/baz//") + file[:path].should == "X:/foo/bar/baz" end - describe "on POSIX systems" do - before do - Puppet.features.stubs(:posix?).returns(true) - Puppet.features.stubs(:microsoft_windows?).returns(false) - end + it "should leave a drive letter with a slash alone", :'fails_on_ruby_1.9.2' => true do + file = Puppet::Type::File.new(:path => "X:/") + file[:path].should == "X:/" + end - it "should refuse to work" do - lambda { Puppet::Type::File.new(:path => "X:/foo/bar") }.should raise_error(Puppet::Error) - end + it "should not accept a drive letter without a slash", :'fails_on_ruby_1.9.2' => true do + lambda { Puppet::Type::File.new(:path => "X:") }.should raise_error(/File paths must be fully qualified/) end end - describe "when using UNC filenames" do - describe "on Microsoft Windows systems", :if => Puppet.features.microsoft_windows?, :'fails_on_ruby_1.9.2' => true do - before do - Puppet.features.stubs(:posix?).returns(false) - Puppet.features.stubs(:microsoft_windows?).returns(true) - end - - it "should autorequire its parent directory" do - file = Puppet::Type::File.new(:path => "//server/foo/bar") - dir = Puppet::Type::File.new(:path => "//server/foo") - @catalog.add_resource file - @catalog.add_resource dir - reqs = file.autorequire - reqs[0].source.must == dir - reqs[0].target.must == file - end - - it "should autorequire its nearest ancestor directory" do - file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux") - dir = Puppet::Type::File.new(:path => "//server/foo/bar") - root = Puppet::Type::File.new(:path => "//server/foo") - @catalog.add_resource file - @catalog.add_resource dir - @catalog.add_resource root - reqs = file.autorequire - reqs.length.must == 1 - reqs[0].source.must == dir - reqs[0].target.must == file - end + describe "when using UNC filenames", :'fails_on_ruby_1.9.2' => true do + before :each do + pending("UNC file paths not yet supported") + end - it "should not autorequire anything when there is no nearest ancestor directory" do - file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux") - @catalog.add_resource file - file.autorequire.should be_empty - end + it "should autorequire its parent directory" do + file = Puppet::Type::File.new(:path => "//server/foo/bar") + dir = Puppet::Type::File.new(:path => "//server/foo") + @catalog.add_resource file + @catalog.add_resource dir + reqs = file.autorequire + reqs[0].source.must == dir + reqs[0].target.must == file + end - it "should not autorequire its parent dir if its parent dir is itself" do - file = Puppet::Type::File.new(:path => "//server/foo") - @catalog.add_resource file - puts file.autorequire - file.autorequire.should be_empty - end + it "should autorequire its nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux") + dir = Puppet::Type::File.new(:path => "//server/foo/bar") + root = Puppet::Type::File.new(:path => "//server/foo") + @catalog.add_resource file + @catalog.add_resource dir + @catalog.add_resource root + reqs = file.autorequire + reqs.length.must == 1 + reqs[0].source.must == dir + reqs[0].target.must == file + end - it "should remove trailing slashes" do - file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/") - file[:path].should == "//server/foo/bar/baz" - end + it "should not autorequire anything when there is no nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux") + @catalog.add_resource file + file.autorequire.should be_empty + end - it "should remove double slashes" do - file = Puppet::Type::File.new(:path => "//server/foo/bar//baz") - file[:path].should == "//server/foo/bar/baz" - end + it "should not autorequire its parent dir if its parent dir is itself" do + file = Puppet::Type::File.new(:path => "//server/foo") + @catalog.add_resource file + puts file.autorequire + file.autorequire.should be_empty + end - it "should remove trailing double slashes" do - file = Puppet::Type::File.new(:path => "//server/foo/bar/baz//") - file[:path].should == "//server/foo/bar/baz" - end + it "should remove trailing slashes" do + file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/") + file[:path].should == "//server/foo/bar/baz" + end - it "should remove a trailing slash from a sharename" do - file = Puppet::Type::File.new(:path => "//server/foo/") - file[:path].should == "//server/foo" - end + it "should remove double slashes" do + file = Puppet::Type::File.new(:path => "//server/foo/bar//baz") + file[:path].should == "//server/foo/bar/baz" + end - it "should not modify a sharename" do - file = Puppet::Type::File.new(:path => "//server/foo") - file[:path].should == "//server/foo" - end + it "should remove trailing double slashes" do + file = Puppet::Type::File.new(:path => "//server/foo/bar/baz//") + file[:path].should == "//server/foo/bar/baz" end - describe "on POSIX systems" do - before do - Puppet.features.stubs(:posix?).returns(true) - Puppet.features.stubs(:microsoft_windows?).returns(false) - end + it "should remove a trailing slash from a sharename" do + file = Puppet::Type::File.new(:path => "//server/foo/") + file[:path].should == "//server/foo" + end - it "should refuse to work" do - lambda { Puppet::Type::File.new(:path => "X:/foo/bar") }.should raise_error(Puppet::Error) - end + it "should not modify a sharename" do + file = Puppet::Type::File.new(:path => "//server/foo") + file[:path].should == "//server/foo" end end diff --git a/spec/unit/type/group_spec.rb b/spec/unit/type/group_spec.rb index afe28247a..3b6cac8bc 100755 --- a/spec/unit/type/group_spec.rb +++ b/spec/unit/type/group_spec.rb @@ -1,7 +1,7 @@ #!/usr/bin/env rspec require 'spec_helper' -describe Puppet::Type.type(:group) do +describe Puppet::Type.type(:group), :fails_on_windows => true do before do ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin" unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin") @class = Puppet::Type.type(:group) diff --git a/spec/unit/type/mount_spec.rb b/spec/unit/type/mount_spec.rb index 9ef76992a..3309cd267 100755 --- a/spec/unit/type/mount_spec.rb +++ b/spec/unit/type/mount_spec.rb @@ -1,7 +1,7 @@ #!/usr/bin/env rspec require 'spec_helper' -describe Puppet::Type.type(:mount) do +describe Puppet::Type.type(:mount), :fails_on_windows => true do it "should have a :refreshable feature that requires the :remount method" do Puppet::Type.type(:mount).provider_feature(:refreshable).methods.should == [:remount] end @@ -16,7 +16,7 @@ describe Puppet::Type.type(:mount) do end end -describe Puppet::Type.type(:mount), "when validating attributes" do +describe Puppet::Type.type(:mount), "when validating attributes", :fails_on_windows => true do [:name, :remounts, :provider].each do |param| it "should have a #{param} parameter" do Puppet::Type.type(:mount).attrtype(param).should == :param @@ -30,7 +30,7 @@ describe Puppet::Type.type(:mount), "when validating attributes" do end end -describe Puppet::Type.type(:mount)::Ensure, "when validating values" do +describe Puppet::Type.type(:mount)::Ensure, "when validating values", :fails_on_windows => true do before do @provider = stub 'provider', :class => Puppet::Type.type(:mount).defaultprovider, :clear => nil Puppet::Type.type(:mount).defaultprovider.expects(:new).returns(@provider) @@ -62,7 +62,7 @@ describe Puppet::Type.type(:mount)::Ensure, "when validating values" do end end -describe Puppet::Type.type(:mount)::Ensure do +describe Puppet::Type.type(:mount)::Ensure, :fails_on_windows => true do before :each do provider_properties = {} @provider = stub 'provider', :class => Puppet::Type.type(:mount).defaultprovider, :clear => nil, :satisfies? => true, :name => :mock, :property_hash => provider_properties @@ -279,7 +279,7 @@ describe Puppet::Type.type(:mount)::Ensure do end end -describe Puppet::Type.type(:mount), "when modifying an existing mount entry" do +describe Puppet::Type.type(:mount), "when modifying an existing mount entry", :fails_on_windows => true do before do @provider = stub 'provider', :class => Puppet::Type.type(:mount).defaultprovider, :clear => nil, :satisfies? => true, :name => :mock, :remount => nil Puppet::Type.type(:mount).defaultprovider.stubs(:new).returns(@provider) diff --git a/spec/unit/type/noop_metaparam_spec.rb b/spec/unit/type/noop_metaparam_spec.rb index f4241d417..7083dd037 100755 --- a/spec/unit/type/noop_metaparam_spec.rb +++ b/spec/unit/type/noop_metaparam_spec.rb @@ -4,9 +4,11 @@ require 'spec_helper' require 'puppet/type' describe Puppet::Type.type(:file).attrclass(:noop) do + include PuppetSpec::Files + before do Puppet.settings.stubs(:use) - @file = Puppet::Type.newfile :path => "/what/ever" + @file = Puppet::Type.newfile :path => make_absolute("/what/ever") end it "should accept true as a value" do diff --git a/spec/unit/type/resources_spec.rb b/spec/unit/type/resources_spec.rb index 48c068cfa..f596968d3 100755 --- a/spec/unit/type/resources_spec.rb +++ b/spec/unit/type/resources_spec.rb @@ -51,7 +51,7 @@ describe resources do @resources.generate.collect { |r| r.ref }.should_not include(@host1.ref) end - it "should not include the skipped users", :'fails_on_ruby_1.9.2' => true do + it "should not include the skipped users", :'fails_on_ruby_1.9.2' => true, :fails_on_windows => true do res = Puppet::Type.type(:resources).new :name => :user, :purge => true res.catalog = Puppet::Resource::Catalog.new @@ -72,7 +72,7 @@ describe resources do end end - describe "when the instance's do not have an ensure property" do + describe "when the instance's do not have an ensure property", :fails_on_windows => true do it "should not be included in the generated resources" do @no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo') Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource] diff --git a/spec/unit/type/service_spec.rb b/spec/unit/type/service_spec.rb index 40270e7c8..ab006a4be 100755 --- a/spec/unit/type/service_spec.rb +++ b/spec/unit/type/service_spec.rb @@ -57,6 +57,21 @@ describe Puppet::Type.type(:service), "when validating attribute values" do Puppet::Type.type(:service).new(:name => "yay", :enable => :false) end + it "should support :manual as a value to :enable on Windows" do + Puppet.features.stubs(:microsoft_windows?).returns true + + Puppet::Type.type(:service).new(:name => "yay", :enable => :manual) + end + + it "should not support :manual as a value to :enable when not on Windows" do + Puppet.features.stubs(:microsoft_windows?).returns false + + expect { Puppet::Type.type(:service).new(:name => "yay", :enable => :manual) }.to raise_error( + Puppet::Error, + /Setting enable to manual is only supported on Microsoft Windows\./ + ) + end + it "should support :true as a value to :hasstatus" do Puppet::Type.type(:service).new(:name => "yay", :hasstatus => :true) end diff --git a/spec/unit/type/ssh_authorized_key_spec.rb b/spec/unit/type/ssh_authorized_key_spec.rb index 71b8a9ab0..db58dc9f3 100755 --- a/spec/unit/type/ssh_authorized_key_spec.rb +++ b/spec/unit/type/ssh_authorized_key_spec.rb @@ -3,7 +3,9 @@ require 'spec_helper' ssh_authorized_key = Puppet::Type.type(:ssh_authorized_key) -describe ssh_authorized_key do +describe ssh_authorized_key, :unless => Puppet.features.microsoft_windows? do + include PuppetSpec::Files + before do @class = Puppet::Type.type(:ssh_authorized_key) @@ -11,7 +13,7 @@ describe ssh_authorized_key do @class.stubs(:defaultprovider).returns(@provider_class) @class.stubs(:provider).returns(@provider_class) - @provider = stub 'provider', :class => @provider_class, :file_path => "/tmp/whatever", :clear => nil + @provider = stub 'provider', :class => @provider_class, :file_path => make_absolute("/tmp/whatever"), :clear => nil @provider_class.stubs(:new).returns(@provider) @catalog = Puppet::Resource::Catalog.new end diff --git a/spec/unit/type/tidy_spec.rb b/spec/unit/type/tidy_spec.rb index cb030634b..bf892e836 100755 --- a/spec/unit/type/tidy_spec.rb +++ b/spec/unit/type/tidy_spec.rb @@ -5,8 +5,10 @@ require 'puppet/file_bucket/dipper' tidy = Puppet::Type.type(:tidy) describe tidy do + include PuppetSpec::Files + before do - @basepath = Puppet.features.posix? ? "/what/ever" : "C:/tmp" + @basepath = make_absolute("/what/ever") Puppet.settings.stubs(:use) # for an unknown reason some of these specs fails when run individually diff --git a/spec/unit/type/user_spec.rb b/spec/unit/type/user_spec.rb index 823b12f27..f24fc8eef 100755 --- a/spec/unit/type/user_spec.rb +++ b/spec/unit/type/user_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' user = Puppet::Type.type(:user) -describe user do +describe user, :fails_on_windows => true do before do ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin" unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin") @provider = stub 'provider' |