<commit_before>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright (c) 2008-2014 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'spec_helper'
require 'ostruct'

describe Chef::Provider::Mount::Solaris do
  let(:node) { Chef::Node.new }

  let(:events) { Chef::EventDispatch::Dispatcher.new }

  let(:run_context) { Chef::RunContext.new(node, {}, events) }

  let(:device_type) { :device }

  let(:fstype) { "ufs" }

  let(:device) { "/dev/dsk/c0t2d0s7" }

  let(:mountpoint) { "/mnt/foo" }

  let(:options) { nil }

  let(:new_resource) {
    new_resource = Chef::Resource::Mount.new(mountpoint)
    new_resource.device      device
    new_resource.device_type device_type
    new_resource.fstype      fstype
    new_resource.options     options

    new_resource.supports :remount => false
    new_resource
  }

  let(:provider) {
    Chef::Provider::Mount::Solaris.new(new_resource, run_context)
  }

  let(:vfstab_file_contents) {
    <<-EOF.gsub /^\s*/, ''
    #device         device          mount           FS      fsck    mount   mount
    #to mount       to fsck         point           type    pass    at boot options
    #
    fd      -       /dev/fd fd      -       no      -
    /proc   -       /proc   proc    -       no      -
    # swap
    /dev/dsk/c0t0d0s1       -       -       swap    -       no      -
    # root
    /dev/dsk/c0t0d0s0       /dev/rdsk/c0t0d0s0      /       ufs     1       no      -
    # tmpfs
    swap    -       /tmp    tmpfs   -       yes     -
    # nfs
    cartman:/share2         -                       /cartman        nfs     -       yes     rw,soft
    # ufs
    /dev/dsk/c0t2d0s7       /dev/rdsk/c0t2d0s7      /mnt/foo            ufs     2       yes     -
    EOF
  }

  let(:vfstab_file) {
    t = Tempfile.new("rspec-vfstab")
    t.write(vfstab_file_contents)
    t.close
    t
  }

  let(:mount_output) {
    <<-EOF.gsub /^\s*/, ''
    /dev/dsk/c0t0d0s0 on / type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012
    /dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012
    EOF
  }

  before do
    stub_const("Chef::Provider::Mount::Solaris::VFSTAB", vfstab_file.path )
    provider.stub(:shell_out!).with("mount -v").and_return(OpenStruct.new(:stdout => mount_output))
    File.stub(:symlink?).with(device).and_return(false)
    File.stub(:exist?).and_call_original # Tempfile.open on ruby 1.8.7 calls File.exist?
    File.stub(:exist?).with(device).and_return(true)
    File.stub(:exist?).with(mountpoint).and_return(true)
    expect(File).to_not receive(:exists?)
  end

  describe "#define_resource_requirements" do
    before do
      # we're not testing the actual actions so stub them all out
      [:mount_fs, :umount_fs, :remount_fs, :enable_fs, :disable_fs].each {|m| provider.stub(m) }
    end

    context "when the device_type is :label" do
      let(:device_type) { :label }

      it "should raise an error" do
        expect { provider.define_resource_requirements }.to raise_error(Chef::Exceptions::Mount)
      end
    end

    context "when the device_type is :uuid" do
      let(:device_type) { :uuid }

      it "should raise an error" do
        expect { provider.define_resource_requirements }.to raise_error(Chef::Exceptions::Mount)
      end
    end

    it "run_action(:mount) should raise an error if the device does not exist" do
      File.stub(:exist?).with(device).and_return(false)
      expect { provider.run_action(:mount) }.to raise_error(Chef::Exceptions::Mount)
    end

    it "run_action(:remount) should raise an error if the device does not exist" do
      File.stub(:exist?).with(device).and_return(false)
      expect { provider.run_action(:remount) }.to raise_error(Chef::Exceptions::Mount)
    end

    it "run_action(:mount) should raise an error if the mountpoint does not exist" do
      File.stub(:exist?).with(mountpoint).and_return false
      expect { provider.run_action(:mount) }.to raise_error(Chef::Exceptions::Mount)
    end

    it "run_action(:remount) should raise an error if the mountpoint does not exist" do
      File.stub(:exist?).with(mountpoint).and_return false
      expect { provider.run_action(:remount) }.to raise_error(Chef::Exceptions::Mount)
    end

    %w{tmpfs nfs ctfs proc mntfs objfs sharefs fd smbfs}.each do |ft|
      context "when the device has a fstype of #{ft}" do<commit_msg>moved this check into the resource<commit_after>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright (c) 2008-2014 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'spec_helper'
require 'ostruct'

describe Chef::Provider::Mount::Solaris do
  let(:node) { Chef::Node.new }

  let(:events) { Chef::EventDispatch::Dispatcher.new }

  let(:run_context) { Chef::RunContext.new(node, {}, events) }

  let(:device_type) { :device }

  let(:fstype) { "ufs" }

  let(:device) { "/dev/dsk/c0t2d0s7" }

  let(:mountpoint) { "/mnt/foo" }

  let(:options) { nil }

  let(:new_resource) {
    new_resource = Chef::Resource::Mount.new(mountpoint)
    new_resource.device      device
    new_resource.device_type device_type
    new_resource.fstype      fstype
    new_resource.options     options

    new_resource.supports :remount => false
    new_resource
  }

  let(:provider) {
    Chef::Provider::Mount::Solaris.new(new_resource, run_context)
  }

  let(:vfstab_file_contents) {
    <<-EOF.gsub /^\s*/, ''
    #device         device          mount           FS      fsck    mount   mount
    #to mount       to fsck         point           type    pass    at boot options
    #
    fd      -       /dev/fd fd      -       no      -
    /proc   -       /proc   proc    -       no      -
    # swap
    /dev/dsk/c0t0d0s1       -       -       swap    -       no      -
    # root
    /dev/dsk/c0t0d0s0       /dev/rdsk/c0t0d0s0      /       ufs     1       no      -
    # tmpfs
    swap    -       /tmp    tmpfs   -       yes     -
    # nfs
    cartman:/share2         -                       /cartman        nfs     -       yes     rw,soft
    # ufs
    /dev/dsk/c0t2d0s7       /dev/rdsk/c0t2d0s7      /mnt/foo            ufs     2       yes     -
    EOF
  }

  let(:vfstab_file) {
    t = Tempfile.new("rspec-vfstab")
    t.write(vfstab_file_contents)
    t.close
    t
  }

  let(:mount_output) {
    <<-EOF.gsub /^\s*/, ''
    /dev/dsk/c0t0d0s0 on / type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012
    /dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012
    EOF
  }

  before do
    stub_const("Chef::Provider::Mount::Solaris::VFSTAB", vfstab_file.path )
    provider.stub(:shell_out!).with("mount -v").and_return(OpenStruct.new(:stdout => mount_output))
    File.stub(:symlink?).with(device).and_return(false)
    File.stub(:exist?).and_call_original # Tempfile.open on ruby 1.8.7 calls File.exist?
    File.stub(:exist?).with(device).and_return(true)
    File.stub(:exist?).with(mountpoint).and_return(true)
    expect(File).to_not receive(:exists?)
  end

  describe "#define_resource_requirements" do
    before do
      # we're not testing the actual actions so stub them all out
      [:mount_fs, :umount_fs, :remount_fs, :enable_fs, :disable_fs].each {|m| provider.stub(m) }
    end

    it "run_action(:mount) should raise an error if the device does not exist" do
      File.stub(:exist?).with(device).and_return(false)
      expect { provider.run_action(:mount) }.to raise_error(Chef::Exceptions::Mount)
    end

    it "run_action(:remount) should raise an error if the device does not exist" do
      File.stub(:exist?).with(device).and_return(false)
      expect { provider.run_action(:remount) }.to raise_error(Chef::Exceptions::Mount)
    end

    it "run_action(:mount) should raise an error if the mountpoint does not exist" do
      File.stub(:exist?).with(mountpoint).and_return false
      expect { provider.run_action(:mount) }.to raise_error(Chef::Exceptions::Mount)
    end

    it "run_action(:remount) should raise an error if the mountpoint does not exist" do
      File.stub(:exist?).with(mountpoint).and_return false
      expect { provider.run_action(:remount) }.to raise_error(Chef::Exceptions::Mount)
    end

    %w{tmpfs nfs ctfs proc mntfs objfs sharefs fd smbfs}.each do |ft|
      context "when the device has a fstype of #{ft}" do
{'fraction_non_alphanumeric': 0.11828517784499844, 'fraction_numerical': 0.018775425054761655, 'mean_word_length': 2.6484018264840183, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6875256', 'n_tokens_mistral': 3345, 'n_tokens_neox': 3180, 'n_words': 784}