|
| 1 | +package org.rundeck.plugins.nodes.attributes |
| 2 | + |
| 3 | +import com.dtolabs.rundeck.core.common.NodeEntryImpl |
| 4 | +import com.dtolabs.rundeck.plugins.nodes.IModifiableNodeEntry |
| 5 | +import spock.lang.Specification |
| 6 | + |
| 7 | +class AttributeNodeEnhancerSpec extends Specification{ |
| 8 | + |
| 9 | + def "test bad regex match"(){ |
| 10 | + |
| 11 | + given: |
| 12 | + def plugin = new AttributeNodeEnhancer() |
| 13 | + plugin.match = "attb1=value1" |
| 14 | + plugin.add = "attb2=value2" |
| 15 | + |
| 16 | + |
| 17 | + def node = new ModifiableNodeEntry("test1") |
| 18 | + node.attributes = [attb1:"value1"] |
| 19 | + |
| 20 | + def project = "TestProject" |
| 21 | + when: |
| 22 | + |
| 23 | + plugin.updateNode(project, node) |
| 24 | + |
| 25 | + then: |
| 26 | + node.attributes.attb2 == null |
| 27 | + |
| 28 | + } |
| 29 | + |
| 30 | + def "test regex match"(){ |
| 31 | + |
| 32 | + given: |
| 33 | + def plugin = new AttributeNodeEnhancer() |
| 34 | + plugin.match = "attb1==value1" |
| 35 | + plugin.add = "attb2=value2" |
| 36 | + |
| 37 | + |
| 38 | + def node = new ModifiableNodeEntry("test1") |
| 39 | + node.attributes = [attb1:"value1"] |
| 40 | + |
| 41 | + def project = "TestProject" |
| 42 | + when: |
| 43 | + |
| 44 | + plugin.updateNode(project, node) |
| 45 | + |
| 46 | + then: |
| 47 | + node.attributes.attb2 == "value2" |
| 48 | + |
| 49 | + } |
| 50 | + |
| 51 | + def "test multiples regex match"(){ |
| 52 | + |
| 53 | + given: |
| 54 | + def plugin = new AttributeNodeEnhancer() |
| 55 | + plugin.match = match |
| 56 | + plugin.add = "result=valueResult" |
| 57 | + |
| 58 | + |
| 59 | + def node = new ModifiableNodeEntry("test1") |
| 60 | + node.attributes = [attb1:"value1",attb2:"value2"] |
| 61 | + |
| 62 | + def project = "TestProject" |
| 63 | + when: |
| 64 | + |
| 65 | + plugin.updateNode(project, node) |
| 66 | + |
| 67 | + then: |
| 68 | + node.attributes.result == result |
| 69 | + |
| 70 | + where: |
| 71 | + match | result |
| 72 | + "attb1==value1\nattb2==value2" | "valueResult" |
| 73 | + "attb1==value1\r\nattb2==value2" | "valueResult" |
| 74 | + "attb1=value1\r\nattb2==value2" | null |
| 75 | + "attb1==value1\nattb2=value2" | null |
| 76 | + } |
| 77 | + |
| 78 | + |
| 79 | + class ModifiableNodeEntry extends NodeEntryImpl implements IModifiableNodeEntry{ |
| 80 | + |
| 81 | + ModifiableNodeEntry(final String nodename) { |
| 82 | + super(nodename) |
| 83 | + } |
| 84 | + |
| 85 | + |
| 86 | + @Override |
| 87 | + void addAttribute(final String name, final String value) { |
| 88 | + attributes.put(name, value) |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + void removeAttribute(final String name) { |
| 93 | + attributes.remove(name) |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + void addTag(final String tag) { |
| 98 | + tags.add(tag) |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + void removeTag(String tag) { |
| 103 | + tags.remove(tag) |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | +} |
0 commit comments