forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNameParserTest.java
More file actions
126 lines (102 loc) · 4.99 KB
/
Copy pathNameParserTest.java
File metadata and controls
126 lines (102 loc) · 4.99 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Created on 17.08.2015
*/
package com.github.dockerjava.core;
import org.apache.commons.lang.StringUtils;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.core.NameParser.HostnameReposName;
import com.github.dockerjava.core.NameParser.ReposTag;
/**
*
*
* @author marcus
*
*/
public class NameParserTest {
@Test
public void testValidateRepoName() throws Exception {
NameParser.validateRepoName("repository");
NameParser.validateRepoName("namespace/repository");
NameParser.validateRepoName("namespace-with-dashes/repository");
NameParser.validateRepoName("namespace/repository-with-dashes");
NameParser.validateRepoName("namespace.with.dots/repository");
NameParser.validateRepoName("namespace/repository.with.dots");
NameParser.validateRepoName("namespace_with_underscores/repository");
NameParser.validateRepoName("namespace/repository_with_underscores");
}
@Test(expectedExceptions = InvalidRepositoryNameException.class)
public void testValidateRepoNameEmpty() throws Exception {
NameParser.validateRepoName("");
}
@Test(expectedExceptions = InvalidRepositoryNameException.class)
public void testValidateRepoNameExceedsMaxLength() throws Exception {
NameParser.validateRepoName(StringUtils.repeat("repository", 255));
}
@Test(expectedExceptions = InvalidRepositoryNameException.class)
public void testValidateRepoNameEndWithDash() throws Exception {
NameParser.validateRepoName("repository-");
}
@Test(expectedExceptions = InvalidRepositoryNameException.class)
public void testValidateRepoNameStartWithDash() throws Exception {
NameParser.validateRepoName("-repository");
}
@Test(expectedExceptions = InvalidRepositoryNameException.class)
public void testValidateRepoNameEndWithDot() throws Exception {
NameParser.validateRepoName("repository.");
}
@Test(expectedExceptions = InvalidRepositoryNameException.class)
public void testValidateRepoNameStartWithDot() throws Exception {
NameParser.validateRepoName(".repository");
}
@Test(expectedExceptions = InvalidRepositoryNameException.class)
public void testValidateRepoNameEndWithUnderscore() throws Exception {
NameParser.validateRepoName("repository_");
}
@Test(expectedExceptions = InvalidRepositoryNameException.class)
public void testValidateRepoNameStartWithUnderscore() throws Exception {
NameParser.validateRepoName("_repository");
}
@Test(expectedExceptions = InvalidRepositoryNameException.class)
public void testValidateRepoNameWithColon() throws Exception {
NameParser.validateRepoName("repository:with:colon");
}
@Test
public void testResolveSimpleRepositoryName() throws Exception {
HostnameReposName resolved = NameParser.resolveRepositoryName("repository");
assertEquals(resolved, new HostnameReposName(AuthConfig.DEFAULT_SERVER_ADDRESS, "repository"));
}
@Test
public void testResolveRepositoryNameWithNamespace() throws Exception {
HostnameReposName resolved = NameParser.resolveRepositoryName("namespace/repository");
assertEquals(resolved, new HostnameReposName(AuthConfig.DEFAULT_SERVER_ADDRESS, "namespace/repository"));
}
@Test
public void testResolveRepositoryNameWithNamespaceAndHostname() throws Exception {
HostnameReposName resolved = NameParser.resolveRepositoryName("localhost:5000/namespace/repository");
assertEquals(resolved, new HostnameReposName("localhost:5000", "namespace/repository"));
}
@Test(expectedExceptions = InvalidRepositoryNameException.class)
public void testResolveRepositoryNameWithIndex() throws Exception {
NameParser.resolveRepositoryName("index.docker.io/repository");
}
@Test
public void testResolveReposTagWithoutTagSimple() throws Exception {
ReposTag resolved = NameParser.parseRepositoryTag("repository");
assertEquals(resolved, new ReposTag("repository", ""));
resolved = NameParser.parseRepositoryTag("namespace/repository");
assertEquals(resolved, new ReposTag("namespace/repository", ""));
resolved = NameParser.parseRepositoryTag("localhost:5000/namespace/repository");
assertEquals(resolved, new ReposTag("localhost:5000/namespace/repository", ""));
}
@Test
public void testResolveReposTagWithTag() throws Exception {
ReposTag resolved = NameParser.parseRepositoryTag("repository:tag");
assertEquals(resolved, new ReposTag("repository", "tag"));
resolved = NameParser.parseRepositoryTag("namespace/repository:tag");
assertEquals(resolved, new ReposTag("namespace/repository", "tag"));
resolved = NameParser.parseRepositoryTag("localhost:5000/namespace/repository:tag");
assertEquals(resolved, new ReposTag("localhost:5000/namespace/repository", "tag"));
}
}