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
|
#! /usr/bin/env ruby
require 'spec_helper'
describe Puppet::Type.type(:zfs).provider(:zfs) do
let(:name) { 'myzfs' }
let(:zfs) { '/usr/sbin/zfs' }
let(:resource) do
Puppet::Type.type(:zfs).new(:name => name, :provider => :zfs)
end
let(:provider) { resource.provider }
before do
provider.class.stubs(:which).with('zfs').returns(zfs)
end
context ".instances" do
it "should have an instances method" do
provider.class.should respond_to(:instances)
end
it "should list instances" do
provider.class.expects(:zfs).with(:list,'-H').returns File.read(my_fixture('zfs-list.out'))
instances = provider.class.instances.map { |p| {:name => p.get(:name), :ensure => p.get(:ensure)} }
instances.size.should == 2
instances[0].should == {:name => 'rpool', :ensure => :present}
instances[1].should == {:name => 'rpool/ROOT', :ensure => :present}
end
end
context '#add_properties' do
it 'should return an array of properties' do
resource[:mountpoint] = '/foo'
provider.add_properties.should == ['-o', "mountpoint=/foo"]
end
it 'should return an empty array' do
provider.add_properties.should == []
end
end
context "#create" do
it "should execute zfs create" do
provider.expects(:zfs).with(:create, name)
provider.create
end
Puppet::Type.type(:zfs).validproperties.each do |prop|
next if prop == :ensure
it "should include property #{prop}" do
resource[prop] = prop
provider.expects(:zfs).with(:create, '-o', "#{prop}=#{prop}", name)
provider.create
end
end
end
context "#destroy" do
it "should execute zfs destroy" do
provider.expects(:zfs).with(:destroy, name)
provider.destroy
end
end
context "#exists?" do
it "should return true if the resource exists" do
#return stuff because we have to slice and dice it
provider.expects(:zfs).with(:list).returns("NAME USED AVAIL REFER MOUNTPOINT\nmyzfs 100K 27.4M /myzfs")
provider.should be_exists
end
it "should return false if returned values don't match the name" do
provider.expects(:zfs).with(:list).returns("no soup for you")
provider.should_not be_exists
end
end
describe "zfs properties" do
[:aclinherit, :aclmode, :atime, :canmount, :checksum,
:compression, :copies, :dedup, :devices, :exec, :logbias,
:mountpoint, :nbmand, :primarycache, :quota, :readonly,
:recordsize, :refquota, :refreservation, :reservation,
:secondarycache, :setuid, :shareiscsi, :sharenfs, :sharesmb,
:snapdir, :version, :volsize, :vscan, :xattr, :zoned].each do |prop|
it "should get #{prop}" do
provider.expects(:zfs).with(:get, '-H', '-o', 'value', prop, name).returns("value\n")
provider.send(prop).should == 'value'
end
it "should set #{prop}=value" do
provider.expects(:zfs).with(:set, "#{prop}=value", name)
provider.send("#{prop}=", "value")
end
end
end
end
|