summaryrefslogtreecommitdiffstats
path: root/spec/unit/type/zpool_spec.rb
blob: 21a5ba0c6821062d139ed6c14f824a6cdf40a4ca (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
#!/usr/bin/env ruby

require 'spec_helper'

zpool = Puppet::Type.type(:zpool)

describe zpool do
  before do
    @provider = stub 'provider'
    @resource = stub 'resource', :resource => nil, :provider => @provider, :line => nil, :file => nil
  end

  properties = [:ensure, :disk, :mirror, :raidz, :spare, :log]

  properties.each do |property|
    it "should have a #{property} property" do
      zpool.attrclass(property).ancestors.should be_include(Puppet::Property)
    end
  end

  parameters = [:pool, :raid_parity]

  parameters.each do |parameter|
    it "should have a #{parameter} parameter" do
      zpool.attrclass(parameter).ancestors.should be_include(Puppet::Parameter)
    end
  end
end

vdev_property = Puppet::Property::VDev

describe vdev_property do
  before do
    vdev_property.initvars
    @resource = stub 'resource', :[]= => nil, :property => nil
    @property = vdev_property.new(:resource => @resource)
  end

  it "should be insync if the devices are the same" do
    @property.should = ["dev1 dev2"]
    @property.safe_insync?(["dev2 dev1"]).must be_true
  end

  it "should be out of sync if the devices are not the same" do
    @property.should = ["dev1 dev3"]
    @property.safe_insync?(["dev2 dev1"]).must be_false
  end

  it "should be insync if the devices are the same and the should values are comma seperated" do
    @property.should = ["dev1", "dev2"]
    @property.safe_insync?(["dev2 dev1"]).must be_true
  end

  it "should be out of sync if the device is absent and should has a value" do
    @property.should = ["dev1", "dev2"]
    @property.safe_insync?(:absent).must be_false
  end

  it "should be insync if the device is absent and should is absent" do
    @property.should = [:absent]
    @property.safe_insync?(:absent).must be_true
  end
end

multi_vdev_property = Puppet::Property::MultiVDev

describe multi_vdev_property do
  before do
    multi_vdev_property.initvars
    @resource = stub 'resource', :[]= => nil, :property => nil
    @property = multi_vdev_property.new(:resource => @resource)
  end

  it "should be insync if the devices are the same" do
    @property.should = ["dev1 dev2"]
    @property.safe_insync?(["dev2 dev1"]).must be_true
  end

  it "should be out of sync if the devices are not the same" do
    @property.should = ["dev1 dev3"]
    @property.safe_insync?(["dev2 dev1"]).must be_false
  end

  it "should be out of sync if the device is absent and should has a value" do
    @property.should = ["dev1", "dev2"]
    @property.safe_insync?(:absent).must be_false
  end

  it "should be insync if the device is absent and should is absent" do
    @property.should = [:absent]
    @property.safe_insync?(:absent).must be_true
  end

  describe "when there are multiple lists of devices" do
    it "should be in sync if each group has the same devices" do
      @property.should = ["dev1 dev2", "dev3 dev4"]
      @property.safe_insync?(["dev2 dev1", "dev3 dev4"]).must be_true
    end

    it "should be out of sync if any group has the different devices" do
      @property.should = ["dev1 devX", "dev3 dev4"]
      @property.safe_insync?(["dev2 dev1", "dev3 dev4"]).must be_false
    end

    it "should be out of sync if devices are in the wrong group" do
      @property.should = ["dev1 dev2", "dev3 dev4"]
      @property.safe_insync?(["dev2 dev3", "dev1 dev4"]).must be_false
    end
  end
end