Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2fe4e059102bdf01cb2a6274a4ff520c44565669 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*******************************************************************************
 * Copyright (c) 2015 Red Hat.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat - Initial Contribution
 *******************************************************************************/
package org.eclipse.linuxtools.internal.docker.ui.wizards;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.linuxtools.internal.docker.ui.validators.ImageNameValidator;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class ImagePullPatternTest { 
	
	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[][] {
			match("", IStatus.CANCEL),
			match("£", IStatus.WARNING),
			match("wildfly", IStatus.WARNING),
			match("jboss/", IStatus.WARNING),
			match("jboss/wildfly", IStatus.WARNING),
			match("jboss/wildfly:", IStatus.WARNING),
			match("jboss/wildfly:latest", IStatus.OK),
			match("localhost/wildfly/", IStatus.WARNING),
			match("localhost/jboss/wildfly", IStatus.WARNING),
			match("localhost/jboss/wildfly:", IStatus.WARNING),
			match("localhost/jboss/wildfly:latest", IStatus.WARNING),
			match("localhost/jboss/wildfly:9", IStatus.WARNING),
			match("localhost/jboss/wildfly:9.", IStatus.WARNING),
			match("localhost/jboss/wildfly:9.0.1.", IStatus.WARNING),
			match("localhost/jboss/wildfly:9.0.1.Final", IStatus.WARNING),
			match("localhost:", IStatus.WARNING),
			match("localhost:5000", IStatus.OK), // bc it matches the REPO:TAG pattern.
			match("localhost:5000/", IStatus.WARNING),
			match("localhost:5000/jboss/wildfly", IStatus.WARNING),
			match("localhost:5000/jboss/wildfly/", IStatus.WARNING),
			match("localhost:5000/jboss/wildfly", IStatus.WARNING),
			match("localhost:5000/jboss/wildfly:", IStatus.WARNING),
			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);
		// then
		Assert.assertEquals(expectedSeverity, status.getSeverity());
	}

}

Back to the top