Skip to content

Commit

Permalink
handling issues 347,364 (#385)
Browse files Browse the repository at this point in the history
* handling issues 347,364

* updating default for fleet items and adding specific error message when default is selected

* updating error message for checkFleet

* removing checkMethod info from fleet select entry

---------

Co-authored-by: Prathibha Datta Kumar <[email protected]>
  • Loading branch information
naraharip2017 and pdk27 authored Jul 13, 2023
1 parent 035a0c2 commit 550080c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetCloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import hudson.slaves.NodeProvisioner;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import hudson.util.ListBoxModel.Option;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -977,6 +978,7 @@ public ListBoxModel doFillFleetItems(@QueryParameter final boolean showAllFleets
@QueryParameter final String awsCredentialsId,
@QueryParameter final String fleet) {
final ListBoxModel model = new ListBoxModel();
model.add(0, new Option("- please select -", "", true));
try {
for (final EC2Fleet EC2Fleet : EC2Fleets.all()) {
EC2Fleet.describe(
Expand All @@ -990,6 +992,14 @@ public ListBoxModel doFillFleetItems(@QueryParameter final boolean showAllFleets
return model;
}

public FormValidation doCheckFleet(@QueryParameter final String fleet) {
if (StringUtils.isEmpty(fleet)) {
return FormValidation.error("Please select a valid EC2 Fleet");
} else {
return FormValidation.ok();
}
}

public FormValidation doTestConnection(
@QueryParameter final String awsCredentialsId,
@QueryParameter final String region,
Expand Down
23 changes: 20 additions & 3 deletions src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import hudson.slaves.ComputerConnector;
import hudson.slaves.NodeProvisioner;
import hudson.util.FormValidation;
import hudson.util.FormValidation.Kind;
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
import jenkins.model.Nodes;
Expand Down Expand Up @@ -1892,7 +1893,8 @@ public void descriptorImpl_doFillFleetItems_returnEmptyListIfNoEmptyEC2Fleet() {
ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillFleetItems(
false, "", "", "", "");

assertEquals(0, r.size());
assertEquals(1, r.size());
assertEquals("", r.get(0).value);
}

@Test
Expand All @@ -1904,7 +1906,8 @@ public void descriptorImpl_doFillFleetItems_returnFleetsProvidedByAllEC2Fleets()
ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillFleetItems(
false, "", "", "", "");

assertEquals(0, r.size());
assertEquals(1, r.size());
assertEquals("", r.get(0).value);
verify(ec2SpotFleet).describe("", "", "", r, "", false);
verify(autoScalingGroupFleet).describe("", "", "", r, "", false);
}
Expand All @@ -1921,7 +1924,21 @@ public void descriptorImpl_doFillFleetItems_returnEmptyListIfAnyException() {
ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillFleetItems(
false, "", "", "", "");

assertEquals(0, r.size());
assertEquals(1, r.size());
assertEquals("", r.get(0).value);
}

@Test
public void descriptorImpl_doCheckFleet_default() {
FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doCheckFleet("");
assertEquals(formValidation.kind, Kind.ERROR);
}

@Test
public void descriptorImpl_doCheckFleet_nonDefault() {
FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doCheckFleet("ASG1");
assertEquals(formValidation.kind, Kind.OK);

}

@Test
Expand Down

0 comments on commit 550080c

Please sign in to comment.