forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerConfigFileTest.java
More file actions
163 lines (128 loc) · 5.22 KB
/
Copy pathDockerConfigFileTest.java
File metadata and controls
163 lines (128 loc) · 5.22 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* Copyright (C) 2014 SignalFuse, Inc.
*/
package com.github.dockerjava.core;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.test.serdes.JSONTestHelper;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.io.File;
import java.io.IOException;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.MatcherAssert.assertThat;
public class DockerConfigFileTest {
@Rule
public ExpectedException expectedEx = ExpectedException.none();
private final File FILESROOT = new File(DockerConfigFileTest.class.getResource("/testAuthConfigFile").getFile());
@Test
public void emptyFile() throws IOException {
expectedEx.expect(IOException.class);
expectedEx.expectMessage("The Auth Config file is empty");
runTest("emptyFile");
}
@Test
public void tooSmallFile() throws IOException {
expectedEx.expect(IOException.class);
expectedEx.expectMessage("The Auth Config file is empty");
runTest("tooSmallFile");
}
@Test
public void invalidJsonInvalidAuth() throws IOException {
expectedEx.expect(IOException.class);
expectedEx.expectMessage("Invalid auth configuration file");
runTest("invalidJsonInvalidAuth");
}
@Test
public void invalidLegacyAuthLine() throws IOException {
expectedEx.expect(IOException.class);
expectedEx.expectMessage("Invalid Auth config file");
runTest("invalidLegacyAuthLine");
}
@Test
public void invalidLegacyInvalidAuth() throws IOException {
expectedEx.expect(IOException.class);
expectedEx.expectMessage("Invalid auth configuration file");
runTest("invalidLegacyInvalidAuth");
}
@Test
public void invalidLegacyEmailLine() throws IOException {
expectedEx.expect(IOException.class);
expectedEx.expectMessage("Invalid Auth config file");
runTest("invalidLegacyEmailLine");
}
@Test
public void validLegacyJson() throws IOException {
AuthConfig authConfig1 = new AuthConfig()
.withEmail("foo@example.com")
.withUsername("foo")
.withPassword("bar")
.withRegistryAddress("quay.io");
AuthConfig authConfig2 = new AuthConfig()
.withEmail("moo@example.com")
.withUsername("foo1")
.withPassword("bar1")
.withRegistryAddress(AuthConfig.DEFAULT_SERVER_ADDRESS);
DockerConfigFile expected = new DockerConfigFile();
expected.addAuthConfig(authConfig1);
expected.addAuthConfig(authConfig2);
assertThat(runTest("validLegacyJson"), is(expected));
}
@Test
public void validJsonWithUnknown() throws IOException {
AuthConfig authConfig1 = new AuthConfig()
.withRegistryAddress("192.168.99.100:32768");
AuthConfig authConfig2 = new AuthConfig()
.withEmail("foo@example.com")
.withUsername("foo")
.withPassword("bar")
.withRegistryAddress("https://index.docker.io/v1/");
DockerConfigFile expected = new DockerConfigFile();
expected.addAuthConfig(authConfig1);
expected.addAuthConfig(authConfig2);
DockerConfigFile actual = runTest("validJsonWithUnknown");
assertThat(actual, is(expected));
}
@Test
public void validJsonWithOnlyUnknown() throws IOException {
DockerConfigFile expected = new DockerConfigFile();
DockerConfigFile actual = runTest("validJsonWithOnlyUnknown");
assertThat(actual, is(expected));
}
@Test
public void validLegacy() throws IOException {
AuthConfig authConfig = new AuthConfig()
.withEmail("foo@example.com")
.withUsername("foo")
.withPassword("bar")
.withRegistryAddress(AuthConfig.DEFAULT_SERVER_ADDRESS);
DockerConfigFile expected = new DockerConfigFile();
expected.addAuthConfig(authConfig);
assertThat(runTest("validLegacy"), is(expected));
}
@Test
public void validDockerConfig() throws IOException {
AuthConfig authConfig1 = new AuthConfig()
.withEmail("foo@example.com")
.withUsername("foo")
.withPassword("bar")
.withRegistryAddress("quay.io");
AuthConfig authConfig2 = new AuthConfig()
.withEmail("moo@example.com")
.withUsername("foo1")
.withPassword("bar1")
.withRegistryAddress(AuthConfig.DEFAULT_SERVER_ADDRESS);
DockerConfigFile expected = new DockerConfigFile();
expected.addAuthConfig(authConfig1);
expected.addAuthConfig(authConfig2);
assertThat(runTest("validDockerConfig"), is(expected));
}
@Test
public void nonExistent() throws IOException {
DockerConfigFile expected = new DockerConfigFile();
assertThat(runTest("idontexist"), is(expected));
}
private DockerConfigFile runTest(String testFileName) throws IOException {
return DockerConfigFile.loadConfig(JSONTestHelper.getMapper(), new File(FILESROOT, testFileName).getAbsolutePath());
}
}