summaryrefslogtreecommitdiff
path: root/spec/unit/resource/mount_spec.rb
blob: ec6fb1232a3a4e73b28c932d93d18a95d8f364cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
#
# Author:: Joshua Timberman (<joshua@chef.io>)
# Author:: Tyler Cloke (<tyler@chef.io>)
# Copyright:: Copyright 2009-2017, 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"

describe Chef::Resource::Mount do
  let(:resource) { Chef::Resource::Mount.new("fakey_fakerton") }

  it "the mount_point property is the name_property" do
    expect(resource.mount_point).to eql("fakey_fakerton")
  end

  it "sets the default action as :mount" do
    expect(resource.action).to eql([:mount])
  end

  it "supports :disable, :enable, :mount, :remount, :umount, :unmount actions" do
    expect { resource.action :disable }.not_to raise_error
    expect { resource.action :enable }.not_to raise_error
    expect { resource.action :mount }.not_to raise_error
    expect { resource.action :remount }.not_to raise_error
    expect { resource.action :umount }.not_to raise_error
    expect { resource.action :unmount }.not_to raise_error
  end

  it "allows you to set the device property" do
    resource.device "/dev/sdb3"
    expect(resource.device).to eql("/dev/sdb3")
  end

  it "allows you to set mount_point property" do
    resource.mount_point "U:"
    expect(resource.mount_point).to eql("U:")
  end

  it "raises error when mount_point property is not set" do
    resource.mount_point nil
    expect { resource.mounted("poop") }.to raise_error(ArgumentError)
  end

  it "sets fsck_device to '-' by default" do
    expect(resource.fsck_device).to eql("-")
  end

  it "allows you to set the fsck_device property" do
    resource.fsck_device "/dev/rdsk/sdb3"
    expect(resource.fsck_device).to eql("/dev/rdsk/sdb3")
  end

  it "allows you to set the fstype property" do
    resource.fstype "nfs"
    expect(resource.fstype).to eql("nfs")
  end

  it "sets fstype to 'auto' by default" do
    expect(resource.fstype).to eql("auto")
  end

  it "allows you to set the dump property" do
    resource.dump 1
    expect(resource.dump).to eql(1)
  end

  it "allows you to set the pass property" do
    resource.pass 1
    expect(resource.pass).to eql(1)
  end

  it "sets the options property to defaults" do
    expect(resource.options).to eql(["defaults"])
  end

  it "allows options to be sent as a string, and convert to array" do
    resource.options "rw,noexec"
    expect(resource.options).to be_a_kind_of(Array)
  end

  it "allows options property as an array" do
    resource.options %w{ro nosuid}
    expect(resource.options).to be_a_kind_of(Array)
  end

  it "allows options to be sent as a delayed evaluator" do
    resource.options Chef::DelayedEvaluator.new { %w{rw noexec} }
    expect(resource.options).to eql(%w{rw noexec})
  end

  it "allows options to be sent as a delayed evaluator, and convert to array" do
    resource.options Chef::DelayedEvaluator.new { "rw,noexec" }
    expect(resource.options).to be_a_kind_of(Array)
    expect(resource.options).to eql(%w{rw noexec})
  end

  it "accepts true for mounted" do
    resource.mounted(true)
    expect(resource.mounted).to eql(true)
  end

  it "accepts false for mounted" do
    resource.mounted(false)
    expect(resource.mounted).to eql(false)
  end

  it "sets mounted to false by default" do
    expect(resource.mounted).to eql(false)
  end

  it "does not accept a string for mounted" do
    expect { resource.mounted("poop") }.to raise_error(ArgumentError)
  end

  it "accepts true for enabled" do
    resource.enabled(true)
    expect(resource.enabled).to eql(true)
  end

  it "accepts false for enabled" do
    resource.enabled(false)
    expect(resource.enabled).to eql(false)
  end

  it "sets enabled to false by default" do
    expect(resource.enabled).to eql(false)
  end

  it "does not accept a string for enabled" do
    expect { resource.enabled("poop") }.to raise_error(ArgumentError)
  end

  it "defaults all feature support to false" do
    support_hash = { remount: false }
    expect(resource.supports).to eq(support_hash)
  end

  it "allows you to set feature support as an array" do
    support_array = [ :remount ]
    support_hash = { remount: true }
    resource.supports(support_array)
    expect(resource.supports).to eq(support_hash)
  end

  it "allows you to set feature support as a hash" do
    support_hash = { remount: true }
    resource.supports(support_hash)
    expect(resource.supports).to eq(support_hash)
  end

  it "allows you to set username" do
    resource.username("Administrator")
    expect(resource.username).to eq("Administrator")
  end

  it "allows you to set password" do
    resource.password("Jetstream123!")
    expect(resource.password).to eq("Jetstream123!")
  end

  it "allows you to set domain" do
    resource.domain("TEST_DOMAIN")
    expect(resource.domain).to eq("TEST_DOMAIN")
  end
end