summaryrefslogtreecommitdiffstats
path: root/lib/rss/rexmlparser.rb
Commit message (Expand)AuthorAgeFilesLines
* * {ext,lib,test}/**/*.rb: removed trailing spaces.nobu2009-03-061-5/+5
* * lib/rss/parser.rb: added entity handling type predicate.kou2005-11-231-5/+12
* * lib/rss/rss.rb (RSS::VERSION): 0.1.0 -> 0.1.1.kou2004-11-191-1/+1
* * lib/rss/: untabified.kou2004-10-161-37/+37
* should escape dot.nobu2004-02-171-1/+1
* * lib/rss/rexmlparser.rb: REXML version may be 4 digits.nobu2004-02-171-3/+3
* * lib/rss/parser.rb (RSS::Parser): added @@default_parser. Usedkou2004-01-311-3/+7
* * lib/rss: rss library imported. [ruby-dev:22726]matz2004-01-281-0/+43
ef='#n103'>103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
#!/usr/bin/env rspec
require 'spec_helper'

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

  it "should have no default value for :ensure" do
    mount = Puppet::Type.type(:mount).new(:name => "yay")
    mount.should(:ensure).should be_nil
  end

  it "should have :name as the only keyattribut" do
    Puppet::Type.type(:mount).key_attributes.should == [:name]
  end
end

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
    end
  end

  [:ensure, :device, :blockdevice, :fstype, :options, :pass, :dump, :atboot, :target].each do |param|
    it "should have a #{param} property" do
      Puppet::Type.type(:mount).attrtype(param).should == :property
    end
  end
end

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)
  end

  it "should alias :present to :defined as a value to :ensure" do
    mount = Puppet::Type.type(:mount).new(:name => "yay", :ensure => :present)
    mount.should(:ensure).should == :defined
  end

  it "should support :present as a value to :ensure" do
    Puppet::Type.type(:mount).new(:name => "yay", :ensure => :present)
  end

  it "should support :defined as a value to :ensure" do
    Puppet::Type.type(:mount).new(:name => "yay", :ensure => :defined)
  end

  it "should support :unmounted as a value to :ensure" do
    Puppet::Type.type(:mount).new(:name => "yay", :ensure => :unmounted)
  end

  it "should support :absent as a value to :ensure" do
    Puppet::Type.type(:mount).new(:name => "yay", :ensure => :absent)
  end

  it "should support :mounted as a value to :ensure" do
    Puppet::Type.type(:mount).new(:name => "yay", :ensure => :mounted)
  end
end

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
    Puppet::Type.type(:mount).defaultprovider.stubs(:new).returns(@provider)
    @mount = Puppet::Type.type(:mount).new(:name => "yay", :check => :ensure)

    @ensure = @mount.property(:ensure)
  end

  def mount_stub(params)
    Puppet::Type.type(:mount).validproperties.each do |prop|
      unless params[prop]
        params[prop] = :absent
        @mount[prop] = :absent
      end
    end

    params.each do |param, value|
      @provider.stubs(param).returns(value)
    end
  end

  describe Puppet::Type.type(:mount)::Ensure, "when changing the host" do

    def test_ensure_change(options)
      @provider.stubs(:get).with(:ensure).returns options[:from]
      @provider.stubs(:ensure).returns options[:from]
      @provider.stubs(:mounted?).returns([:mounted,:ghost].include? options[:from])
      @provider.expects(:create).times(options[:create] || 0)
      @provider.expects(:destroy).times(options[:destroy] || 0)
      @provider.expects(:mount).never
      @provider.expects(:unmount).times(options[:unmount] || 0)
      @ensure.stubs(:syncothers)
      @ensure.should = options[:to]
      @ensure.sync
      (!!@provider.property_hash[:needs_mount]).should == (!!options[:mount])
   end

   it "should create itself when changing from :ghost to :present" do
     test_ensure_change(:from => :ghost, :to => :present, :create => 1)
   end

   it "should create itself when changing from :absent to :present" do
     test_ensure_change(:from => :absent, :to => :present, :create => 1)
   end

   it "should create itself and unmount when changing from :ghost to :unmounted" do
     test_ensure_change(:from => :ghost, :to => :unmounted, :create => 1, :unmount => 1)
   end

   it "should unmount resource when changing from :mounted to :unmounted" do
     test_ensure_change(:from => :mounted, :to => :unmounted, :unmount => 1)
   end

   it "should create itself when changing from :absent to :unmounted" do
     test_ensure_change(:from => :absent, :to => :unmounted, :create => 1)
   end

   it "should unmount resource when changing from :ghost to :absent" do
     test_ensure_change(:from => :ghost, :to => :absent, :unmount => 1)
   end

   it "should unmount and destroy itself when changing from :mounted to :absent" do
     test_ensure_change(:from => :mounted, :to => :absent, :destroy => 1, :unmount => 1)
   end

   it "should destroy itself when changing from :unmounted to :absent" do
     test_ensure_change(:from => :unmounted, :to => :absent, :destroy => 1)
   end

   it "should create itself when changing from :ghost to :mounted" do
     test_ensure_change(:from => :ghost, :to => :mounted, :create => 1)
   end

   it "should create itself and mount when changing from :absent to :mounted" do
     test_ensure_change(:from => :absent, :to => :mounted, :create => 1, :mount => 1)
   end

   it "should mount resource when changing from :unmounted to :mounted" do
     test_ensure_change(:from => :unmounted, :to => :mounted, :mount => 1)
   end


   it "should be in sync if it is :absent and should be :absent" do
     @ensure.should = :absent
     @ensure.safe_insync?(:absent).should == true
   end

   it "should be out of sync if it is :absent and should be :defined" do
     @ensure.should = :defined
     @ensure.safe_insync?(:absent).should == false
   end

   it "should be out of sync if it is :absent and should be :mounted" do
     @ensure.should = :mounted
     @ensure.safe_insync?(:absent).should == false
   end

   it "should be out of sync if it is :absent and should be :unmounted" do
     @ensure.should = :unmounted
     @ensure.safe_insync?(:absent).should == false
   end

   it "should be out of sync if it is :mounted and should be :absent" do
     @ensure.should = :absent
     @ensure.safe_insync?(:mounted).should == false
   end

   it "should be in sync if it is :mounted and should be :defined" do
     @ensure.should = :defined
     @ensure.safe_insync?(:mounted).should == true
   end

   it "should be in sync if it is :mounted and should be :mounted" do
     @ensure.should = :mounted
     @ensure.safe_insync?(:mounted).should == true
   end

   it "should be out in sync if it is :mounted and should be :unmounted" do
     @ensure.should = :unmounted
     @ensure.safe_insync?(:mounted).should == false
   end


   it "should be out of sync if it is :unmounted and should be :absent" do
     @ensure.should = :absent
     @ensure.safe_insync?(:unmounted).should == false
   end

   it "should be in sync if it is :unmounted and should be :defined" do
     @ensure.should = :defined
     @ensure.safe_insync?(:unmounted).should == true
   end

   it "should be out of sync if it is :unmounted and should be :mounted" do
     @ensure.should = :mounted
     @ensure.safe_insync?(:unmounted).should == false
   end

   it "should be in sync if it is :unmounted and should be :unmounted" do
     @ensure.should = :unmounted
     @ensure.safe_insync?(:unmounted).should == true
   end


   it "should be out of sync if it is :ghost and should be :absent" do
     @ensure.should = :absent
     @ensure.safe_insync?(:ghost).should == false
   end

   it "should be out of sync if it is :ghost and should be :defined" do
     @ensure.should = :defined
     @ensure.safe_insync?(:ghost).should == false
   end

   it "should be out of sync if it is :ghost and should be :mounted" do
     @ensure.should = :mounted
     @ensure.safe_insync?(:ghost).should == false
   end

   it "should be out of sync if it is :ghost and should be :unmounted" do
     @ensure.should = :unmounted
     @ensure.safe_insync?(:ghost).should == false
   end

 end

  describe Puppet::Type.type(:mount), "when responding to refresh" do
    pending "2.6.x specifies slightly different behavior and the desired behavior needs to be clarified and revisited.  See ticket #4904" do

      it "should remount if it is supposed to be mounted" do
        @mount[:ensure] = "mounted"
        @provider.expects(:remount)

        @mount.refresh
      end

      it "should not remount if it is supposed to be present" do
        @mount[:ensure] = "present"
        @provider.expects(:remount).never

        @mount.refresh
      end

      it "should not remount if it is supposed to be absent" do
        @mount[:ensure] = "absent"
        @provider.expects(:remount).never

        @mount.refresh
      end

      it "should not remount if it is supposed to be defined" do
        @mount[:ensure] = "defined"
        @provider.expects(:remount).never

        @mount.refresh
      end

      it "should not remount if it is supposed to be unmounted" do
        @mount[:ensure] = "unmounted"
        @provider.expects(:remount).never

        @mount.refresh
      end

      it "should not remount swap filesystems" do
        @mount[:ensure] = "mounted"
        @mount[:fstype] = "swap"
        @provider.expects(:remount).never

        @mount.refresh
      end
    end
  end
end

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)
    @mount = Puppet::Type.type(:mount).new(:name => "yay", :ensure => :mounted)

    {:device => "/foo/bar", :blockdevice => "/other/bar", :target => "/what/ever", :fstype => 'eh', :options => "", :pass => 0, :dump => 0, :atboot => 0,
      :ensure => :mounted}.each do
      |param, value|
      @mount.provider.stubs(param).returns value
      @mount[param] = value
    end

    @mount.provider.stubs(:mounted?).returns true

    # stub this to not try to create state.yaml
    Puppet::Util::Storage.stubs(:store)

    @catalog = Puppet::Resource::Catalog.new
    @catalog.add_resource @mount
  end

  it "should use the provider to change the dump value" do
    @mount.provider.expects(:dump).returns 0
    @mount.provider.expects(:dump=).with(1)

    @mount[:dump] = 1

    @catalog.apply
  end

  it "should umount before flushing changes to disk" do
    syncorder = sequence('syncorder')
    @mount.provider.expects(:options).returns 'soft'
    @mount.provider.expects(:ensure).returns :mounted

    @mount.provider.expects(:unmount).in_sequence(syncorder)
    @mount.provider.expects(:options=).in_sequence(syncorder).with 'hard'
    @mount.expects(:flush).in_sequence(syncorder) # Call inside syncothers
    @mount.expects(:flush).in_sequence(syncorder) # I guess transaction or anything calls flush again

    @mount[:ensure] = :unmounted
    @mount[:options] = 'hard'

    @catalog.apply
  end

end