Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2016-09-02 10:36:47 +0000
committerJeff Johnston2016-09-02 20:58:43 +0000
commit6b8123316fc864e4845ca97867468a5a1ed50938 (patch)
treee4fcebf3e6d027383420f3436c979943a5941af3
parentc5f8f6ecfd3594f5b33632c152bc7ae0e15d56cb (diff)
downloadorg.eclipse.linuxtools-6b8123316fc864e4845ca97867468a5a1ed50938.tar.gz
org.eclipse.linuxtools-6b8123316fc864e4845ca97867468a5a1ed50938.tar.xz
org.eclipse.linuxtools-6b8123316fc864e4845ca97867468a5a1ed50938.zip
Bug 499843 - Pull Image wizard pulls all images if tag is not specified
Adding the ":latest" tag to the image name if it was missing. Refactored the ImageNameValidator class to provide a utility method that can be called out of the validation context Renamed the ImagePullPatternTest to ImageNameValidatorTest since the class under test is ImageNameValidator Change-Id: I5edced116cf6d03bc6ab761f1d89e3552eef61b3 Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/80288 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> (cherry picked from commit f3bf52148d6dcc5acf70b6c2e16605e7d4e365bd) Reviewed-on: https://git.eclipse.org/r/80342
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageNameValidatorTest.java (renamed from containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPatternTest.java)15
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullSWTBotTest.java12
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageNameValidator.java37
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePull.java11
4 files changed, 61 insertions, 14 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPatternTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageNameValidatorTest.java
index 3340f2fa82..1e08addacd 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPatternTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageNameValidatorTest.java
@@ -18,13 +18,16 @@ import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
+/**
+ * Testing the {@link ImageNameValidator} class
+ */
@RunWith(Parameterized.class)
-public class ImagePullPatternTest {
-
+public class ImageNameValidatorTest {
+
private static Object[] match(final String imageName, final int expectedSeverity) {
return new Object[]{imageName, expectedSeverity};
}
-
+
@Parameters(name="{0} -> {1}")
public static Object[][] data() {
return new Object[][] {
@@ -53,13 +56,13 @@ public class ImagePullPatternTest {
match("localhost:5000/jboss/wildfly:latest", IStatus.OK),
};
}
-
+
@Parameter(value=0)
public String imageName;
@Parameter(value=1)
public int expectedSeverity;
-
-
+
+
@Test
public void verifyData() {
final IStatus status = new ImageNameValidator().validate(imageName);
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullSWTBotTest.java
index 591b9f9392..1d525542cf 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullSWTBotTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullSWTBotTest.java
@@ -125,6 +125,18 @@ public class ImagePullSWTBotTest {
}
@Test
+ public void shouldPullLatestImageFromDockerHub() throws DockerException, InterruptedException {
+ // given
+ openPullWizard();
+ // when
+ bot.text(0).setText("jboss/wildfly");
+ bot.button("Finish").click();
+ // then
+ Mockito.verify(client, Mockito.times(1)).pull(Matchers.eq("jboss/wildfly:latest"),
+ Matchers.any(DockerProgressHandler.class));
+ }
+
+ @Test
public void shouldPullImageFromOtherRegistry() throws DockerException, InterruptedException {
// given
MockRegistryAccountManagerFactory
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageNameValidator.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageNameValidator.java
index 54e7ba4051..83d9f26df8 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageNameValidator.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageNameValidator.java
@@ -14,24 +14,47 @@ import org.eclipse.linuxtools.internal.docker.core.DockerImage;
*/
public class ImageNameValidator implements IValidator {
+ public static enum ImageNameStatus {
+ // status when image name is valid and complete
+ VALID,
+ // status when the image name is empty
+ EMPTY,
+ // status when the image name does not match the expected pattern
+ INVALID_FORMAT,
+ // status when the image name does not contain a tag
+ TAG_MISSING;
+ }
+
@Override
public IStatus validate(final Object value) {
final String imageName = (String) value;
- if (imageName.isEmpty()) {
+ final ImageNameStatus imageNameStatus = getStatus(imageName);
+ switch (imageNameStatus) {
+ case EMPTY:
return ValidationStatus
.cancel(WizardMessages.getString("ImagePull.desc")); //$NON-NLS-1$
- }
- final Matcher matcher = DockerImage.imageNamePattern
- .matcher(imageName);
- if (!matcher.matches()) {
+ case INVALID_FORMAT:
return ValidationStatus.warning(WizardMessages
.getString("ImagePull.name.invalidformat.msg")); //$NON-NLS-1$
- } else if (matcher.group("tag") == null) { //$NON-NLS-1$
+ case TAG_MISSING:
return ValidationStatus.warning(
WizardMessages.getString("ImagePull.assumeLatest.msg")); //$NON-NLS-1$
+ default:
+ return Status.OK_STATUS;
+ }
+ }
+ public static ImageNameStatus getStatus(final String imageName) {
+ if (imageName == null || imageName.isEmpty()) {
+ return ImageNameStatus.EMPTY;
+ }
+ final Matcher matcher = DockerImage.imageNamePattern.matcher(imageName);
+ if (!matcher.matches()) {
+ return ImageNameStatus.INVALID_FORMAT;
+ } else if (matcher.group("tag") == null) { //$NON-NLS-1$
+ return ImageNameStatus.TAG_MISSING;
}
- return Status.OK_STATUS;
+ return ImageNameStatus.VALID;
}
} \ No newline at end of file
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePull.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePull.java
index 52f4c42f9d..399057df27 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePull.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePull.java
@@ -16,6 +16,8 @@ import org.eclipse.linuxtools.docker.core.DockerException;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IDockerImage;
import org.eclipse.linuxtools.docker.core.IRegistry;
+import org.eclipse.linuxtools.internal.docker.core.DockerImage;
+import org.eclipse.linuxtools.internal.docker.ui.wizards.ImageNameValidator.ImageNameStatus;
/**
*
@@ -55,7 +57,14 @@ public class ImagePull extends Wizard {
}
public String getSelectedImageName() {
- return this.imagePullPage.getSelectedImageName();
+ // append the ':latest' tag on the image name if no tag was specified
+ final String selectedImageName = this.imagePullPage
+ .getSelectedImageName();
+ if (ImageNameValidator
+ .getStatus(selectedImageName) == ImageNameStatus.TAG_MISSING) {
+ return selectedImageName + ':' + DockerImage.LATEST_TAG; // $NON-NLS-1$
+ }
+ return selectedImageName;
}
public IRegistry getSelectedRegistryAccount() {

Back to the top