File: ovs_spec.rb

package info (click to toggle)
puppet-module-vswitch 21.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 596 kB
  • sloc: ruby: 2,189; python: 38; sh: 10; makefile: 10
file content (111 lines) | stat: -rw-r--r-- 4,416 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
109
110
111
require 'puppet'
require 'spec_helper'
require 'puppet/provider/ovs'

describe Puppet::Provider::Ovs do
  describe '#get_property' do
    it 'returns the property' do
      expect(described_class).to receive(:vsctl)
        .with('get', 'Port', 'testport', 'key')
        .and_return('value')
      expect(described_class.get_property('Port', 'testport', 'key')).to eq('value')
    end
    it 'returns the property without surrounding spaces' do
      expect(described_class).to receive(:vsctl)
        .with('get', 'Port', 'testport', 'key')
        .and_return('  value  ')
      expect(described_class.get_property('Port', 'testport', 'key')).to eq('value')
    end
  end

  describe '#set_property' do
    it 'sets the property' do
      expect(described_class).to receive(:vsctl)
        .with('set', 'Port', 'testport', 'key=value')
      described_class.set_property('Port', 'testport', 'key', 'value')
    end
    it 'sets the property (integer)' do
      expect(described_class).to receive(:vsctl)
        .with('set', 'Port', 'testport', 'key=1')
      described_class.set_property('Port', 'testport', 'key', 1)
    end
    it 'sets the property (boolean)' do
      expect(described_class).to receive(:vsctl)
        .with('set', 'Port', 'testport', 'key=true')
      described_class.set_property('Port', 'testport', 'key', true)
    end
    it 'clears the property when nil' do
      expect(described_class).to receive(:vsctl)
        .with('clear', 'Port', 'testport', 'key')
      described_class.set_property('Port', 'testport', 'key')
    end
    it 'clears the property when empty (string)' do
      expect(described_class).to receive(:vsctl)
        .with('clear', 'Port', 'testport', 'key')
      described_class.set_property('Port', 'testport', 'key', '')
    end
    it 'clears the property when empty (array)' do
      expect(described_class).to receive(:vsctl)
        .with('clear', 'Port', 'testport', 'key')
      described_class.set_property('Port', 'testport', 'key', [])
    end
  end

  describe '#get_other_config' do
    it 'returns the configs' do
      expect(described_class).to receive(:vsctl)
        .with('get', 'Port', 'testport', 'other_config')
        .and_return('{key1=value1,key2=value2}')
      expect(described_class.get_other_config('Port', 'testport', 'key1')).to eq('value1')
    end
    it 'returns the configs when not exist' do
      expect(described_class).to receive(:vsctl)
        .with('get', 'Port', 'testport', 'other_config')
        .and_return('{key1=value1,key2=value2}')
      expect(described_class.get_other_config('Port', 'testport', 'key3')).to eq(nil)
    end
  end

  describe '#set_other_config' do
    it 'sets the configs' do
      expect(described_class).to receive(:vsctl)
        .with('set', 'Port', 'testport', 'other_config:key=value')
      described_class.set_other_config('Port', 'testport', 'key', 'value')
    end
    it 'sets the configs (integer)' do
      expect(described_class).to receive(:vsctl)
        .with('set', 'Port', 'testport', 'other_config:key=1')
      described_class.set_other_config('Port', 'testport', 'key', 1)
    end
    it 'sets the configs (boolean)' do
      expect(described_class).to receive(:vsctl)
        .with('set', 'Port', 'testport', 'other_config:key=true')
      described_class.set_other_config('Port', 'testport', 'key', true)
    end
    it 'clears the configs when nil' do
      expect(described_class).to receive(:vsctl)
        .with('remove', 'Port', 'testport', 'other_config', 'key')
      described_class.set_other_config('Port', 'testport', 'key')
    end
    it 'clears the configs when empty (string)' do
      expect(described_class).to receive(:vsctl)
        .with('remove', 'Port', 'testport', 'other_config', 'key')
      described_class.set_other_config('Port', 'testport', 'key', '')
    end
    it 'clears the configs when empty (array)' do
      expect(described_class).to receive(:vsctl)
        .with('remove', 'Port', 'testport', 'other_config', 'key')
      described_class.set_other_config('Port', 'testport', 'key', [])
    end
  end

  describe '#parse_hash' do
    it 'parse hash value with default splitter' do
      expect(described_class.parse_hash('a=b,c=d')).to eq({'a' => 'b', 'c' => 'd'})
    end
    it 'parse hash value with custom splitter' do
      expect(described_class.parse_hash('a=b
c=d', "\n")).to eq({'a' => 'b', 'c' => 'd'})
    end
  end
end