Skip to content
Permalink
Browse files
Merge pull request #10 from vjuranek/JENKINS-9773
Jenkins 9773
  • Loading branch information
vjuranek committed Jun 27, 2011
2 parents 3e5ed16 + 1792273 commit df313719c482e2620fb0baa808478f659640ea16
Showing 3 changed files with 48 additions and 1 deletion.
@@ -124,7 +124,7 @@ public SlaveTemplate getTemplate(String ami) {
*/
public SlaveTemplate getTemplate(Label label) {
for (SlaveTemplate t : templates)
if(t.containsLabel(label))
if(label.matches(t.getLabelSet()))
return t;
return null;
}
@@ -102,6 +102,10 @@ public String getRootCommandPrefix() {
return rootCommandPrefix;
}

public Set getLabelSet(){
return labelSet;
}

/**
* Does this contain the given label?
*
@@ -0,0 +1,43 @@
package hudson.plugins.ec2;

import hudson.model.Label;
import hudson.model.labels.LabelAtom;

import java.util.ArrayList;
import java.util.List;

import org.jvnet.hudson.test.HudsonTestCase;

import com.xerox.amazonws.ec2.InstanceType;

public class TemplateLabelsTest extends HudsonTestCase{

private AmazonEC2Cloud ac;
private final String LABEL1 = "label1";
private final String LABEL2 = "label2";

@Override
public void setUp() throws Exception{
super.setUp();
SlaveTemplate template = new SlaveTemplate("ami", "foo", "22", InstanceType.LARGE, LABEL1 + " " + LABEL2, "foo ami", "bar", "aaa", "10", "rrr", "fff", "-Xmx1g");
List<SlaveTemplate> templates = new ArrayList<SlaveTemplate>();
templates.add(template);
ac = new AmazonEC2Cloud(AwsRegion.US_EAST_1, "abc", "def", "ghi", "3", templates);
}

public void testLabelAtom(){
assertEquals(true, ac.canProvision(new LabelAtom(LABEL1)));
assertEquals(true, ac.canProvision(new LabelAtom(LABEL2)));
assertEquals(false, ac.canProvision(new LabelAtom("aaa")));
}

public void testLabelExpression() throws Exception{
assertEquals(true, ac.canProvision(Label.parseExpression(LABEL1 + " || " + LABEL2)));
assertEquals(true, ac.canProvision(Label.parseExpression(LABEL1 + " && " + LABEL2)));
assertEquals(true, ac.canProvision(Label.parseExpression(LABEL1 + " || aaa")));
assertEquals(false, ac.canProvision(Label.parseExpression(LABEL1 + " && aaa")));
assertEquals(false, ac.canProvision(Label.parseExpression("aaa || bbb")));
assertEquals(false, ac.canProvision(Label.parseExpression("aaa || bbb")));
}

}

0 comments on commit df31371

Please sign in to comment.