|
119 | 119 | 'classes::class3' => { 'param1' => 'existing', |
120 | 120 | 'param2' => 'existing' } } |
121 | 121 | end |
| 122 | + let(:group_with_rule) do |
| 123 | + { |
| 124 | + name: 'test_group', |
| 125 | + environment: 'test_env', |
| 126 | + classes: { |
| 127 | + 'classes::class1' => { 'param1' => 'resource', |
| 128 | + 'param2' => 'resource', |
| 129 | + 'param3' => 'existing' }, |
| 130 | + 'classes::class3' => { 'param1' => 'existing', |
| 131 | + 'param2' => 'existing' } |
| 132 | + }, |
| 133 | + rule: |
| 134 | + ['or', |
| 135 | + ['~', ['fact', 'fact1'], 'value1'], |
| 136 | + ['~', ['fact', 'fact2'], 'value2']] |
| 137 | + } |
| 138 | + end |
| 139 | + let(:and_rule) do |
| 140 | + ['and', |
| 141 | + ['~', ['fact', 'fact1'], 'value1'], |
| 142 | + ['~', ['fact', 'fact2'], 'value2']] |
| 143 | + end |
| 144 | + let(:or_rule) do |
| 145 | + ['or', |
| 146 | + ['~', ['fact', 'fact1'], 'value1'], |
| 147 | + ['~', ['fact', 'fact2'], 'value2']] |
| 148 | + end |
| 149 | + |
| 150 | + it 'matches rule exactly by default' do |
| 151 | + rsrc = described_class.new(group_with_rule) |
| 152 | + allow(rsrc.property(:rule)).to receive(:retrieve).and_return(and_rule) |
| 153 | + expect(rsrc.property(:rule).should).to eq group_with_rule[:rule] |
| 154 | + end |
| 155 | + |
| 156 | + it 'does not update rule when purge behaviour set to :none' do |
| 157 | + rsrc = described_class.new(group_with_rule.merge(purge_behavior: 'none')) |
| 158 | + allow(rsrc.property(:rule)).to receive(:retrieve).and_return(and_rule) |
| 159 | + expect(rsrc.property(:rule).should).to eq and_rule |
| 160 | + end |
| 161 | + |
| 162 | + it 'updates rule when purge behaviour set to :rule' do |
| 163 | + rsrc = described_class.new(group_with_rule.merge(purge_behavior: 'rule')) |
| 164 | + allow(rsrc.property(:rule)).to receive(:retrieve).and_return(and_rule) |
| 165 | + expect(rsrc.property(:rule).should).to eq group_with_rule[:rule] |
| 166 | + end |
122 | 167 |
|
123 | 168 | it 'matches classes and data exactly by default' do |
124 | 169 | rsrc = described_class.new(resource_hash) |
|
0 commit comments