File: zpool_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (108 lines) | stat: -rw-r--r-- 3,469 bytes parent folder | download
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
require 'spec_helper'

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

describe zpool do
  before do
    @provider = double('provider')
    @resource = double('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
      expect(zpool.attrclass(property).ancestors).to be_include(Puppet::Property)
    end
  end

  parameters = [:pool, :raid_parity]

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

vdev_property = Puppet::Property::VDev

describe vdev_property do
  before do
    vdev_property.initvars
    @resource = double('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"]
    expect(@property.safe_insync?(["dev2 dev1"])).to be_truthy
  end

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

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

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

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

multi_vdev_property = Puppet::Property::MultiVDev

describe multi_vdev_property do
  before do
    multi_vdev_property.initvars
    @resource = double('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"]
    expect(@property.safe_insync?(["dev2 dev1"])).to be_truthy
  end

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

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

  it "should be insync if the device is absent and should is absent" do
    @property.should = [:absent]
    expect(@property.safe_insync?(:absent)).to be_truthy
  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"]
      expect(@property.safe_insync?(["dev2 dev1", "dev3 dev4"])).to be_truthy
    end

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

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