22
22
import org .junit .jupiter .api .AfterEach ;
23
23
import org .junit .jupiter .api .BeforeEach ;
24
24
import org .junit .jupiter .api .DisplayName ;
25
+ import org .junit .jupiter .api .Nested ;
25
26
import org .junit .jupiter .api .Test ;
26
27
import org .junit .jupiter .api .io .TempDir ;
27
28
@@ -62,7 +63,7 @@ void setUp() {
62
63
63
64
@ Test
64
65
@ DisplayName ("build args in image config and project properties" )
65
- void whenBuildArgsFromImageConfigAndFromProjectProperties_shouldMergeBuildArgs () {
66
+ void whenBuildArgsFromImageConfigAndFromProjectProperties_shouldMergeBuildArgsIncludingLocalDockerConfigProxySettings () {
66
67
// Given
67
68
projectProperties .setProperty ("docker.buildArg.VERSION" , "latest" );
68
69
projectProperties .setProperty ("docker.buildArg.FULL_IMAGE" , "busybox:latest" );
@@ -74,7 +75,7 @@ void whenBuildArgsFromImageConfigAndFromProjectProperties_shouldMergeBuildArgs()
74
75
.build ();
75
76
76
77
// When
77
- Map <String , String > mergedBuildArgs = BuildArgResolverUtil .mergeBuildArgs (imageConfiguration , jKubeConfiguration );
78
+ Map <String , String > mergedBuildArgs = BuildArgResolverUtil .mergeBuildArgsIncludingLocalDockerConfigProxySettings (imageConfiguration , jKubeConfiguration );
78
79
79
80
// Then
80
81
assertThat (mergedBuildArgs )
@@ -86,15 +87,15 @@ void whenBuildArgsFromImageConfigAndFromProjectProperties_shouldMergeBuildArgs()
86
87
87
88
@ Test
88
89
@ DisplayName ("build args in image config, project properties, system properties, plugin configuration" )
89
- void fromAllSourcesWithDifferentKeys_shouldMergeBuildArgs () {
90
+ void fromAllSourcesWithDifferentKeys_shouldMergeBuildArgsIncludingLocalDockerConfigProxySettings () {
90
91
// Given
91
92
givenBuildArgsFromImageConfiguration ("VERSION" , "latest" );
92
93
System .setProperty ("docker.buildArg.IMAGE-1" , "openjdk" );
93
94
projectProperties .setProperty ("docker.buildArg.REPO_1" , "docker.io/library" );
94
95
givenBuildArgsFromJKubeConfiguration ("FULL_IMAGE" , "busybox:latest" );
95
96
96
97
// When
97
- Map <String , String > mergedBuildArgs = BuildArgResolverUtil .mergeBuildArgs (imageConfiguration , jKubeConfiguration );
98
+ Map <String , String > mergedBuildArgs = BuildArgResolverUtil .mergeBuildArgsIncludingLocalDockerConfigProxySettings (imageConfiguration , jKubeConfiguration );
98
99
99
100
// Then
100
101
assertThat (mergedBuildArgs )
@@ -106,64 +107,88 @@ void fromAllSourcesWithDifferentKeys_shouldMergeBuildArgs() {
106
107
107
108
@ Test
108
109
@ DisplayName ("build args in image config and system properties with same key, should throw exception" )
109
- void fromBuildConfigurationAndSystemPropertiesWithSameKey_shouldNotMergeBuildArgs () {
110
+ void fromBuildConfigurationAndSystemPropertiesWithSameKey_shouldNotMergeBuildArgsIncludingLocalDockerConfigProxySettings () {
110
111
// Given
111
112
givenBuildArgsFromImageConfiguration ("VERSION" , "latest" );
112
113
System .setProperty ("docker.buildArg.VERSION" , "1.0.0" );
113
114
114
115
// When & Then
115
116
assertThatExceptionOfType (JKubeException .class )
116
- .isThrownBy (() -> BuildArgResolverUtil .mergeBuildArgs (imageConfiguration , jKubeConfiguration ))
117
+ .isThrownBy (() -> BuildArgResolverUtil .mergeBuildArgsIncludingLocalDockerConfigProxySettings (imageConfiguration , jKubeConfiguration ))
117
118
.withMessage ("Multiple Build Args with the same key: VERSION=latest and VERSION=1.0.0" );
118
119
}
119
120
120
121
@ Test
121
122
@ DisplayName ("build args in image config and project properties with same key, should throw exception" )
122
- void fromBuildConfigurationAndProjectPropertiesWithSameKey_shouldNotMergeBuildArgs () {
123
+ void fromBuildConfigurationAndProjectPropertiesWithSameKey_shouldNotMergeBuildArgsIncludingLocalDockerConfigProxySettings () {
123
124
// Given
124
125
givenBuildArgsFromImageConfiguration ("VERSION" , "latest" );
125
126
projectProperties .setProperty ("docker.buildArg.VERSION" , "1.0.0" );
126
127
127
128
// When & Then
128
129
assertThatExceptionOfType (JKubeException .class )
129
- .isThrownBy (() -> BuildArgResolverUtil .mergeBuildArgs (imageConfiguration , jKubeConfiguration ))
130
+ .isThrownBy (() -> BuildArgResolverUtil .mergeBuildArgsIncludingLocalDockerConfigProxySettings (imageConfiguration , jKubeConfiguration ))
130
131
.withMessage ("Multiple Build Args with the same key: VERSION=latest and VERSION=1.0.0" );
131
132
}
132
133
133
134
@ Test
134
135
@ DisplayName ("build args in image config and plugin config with same key, should throw exception" )
135
- void fromBuildConfigurationAndJKubeConfigurationWithSameKey_shouldNotMergeBuildArgs () {
136
+ void fromBuildConfigurationAndJKubeConfigurationWithSameKey_shouldNotMergeBuildArgsIncludingLocalDockerConfigProxySettings () {
136
137
// Given
137
138
givenBuildArgsFromImageConfiguration ("VERSION" , "latest" );
138
139
givenBuildArgsFromJKubeConfiguration ("VERSION" , "1.0.0" );
139
140
140
141
// When & Then
141
142
assertThatExceptionOfType (JKubeException .class )
142
- .isThrownBy (() -> BuildArgResolverUtil .mergeBuildArgs (imageConfiguration , jKubeConfiguration ))
143
+ .isThrownBy (() -> BuildArgResolverUtil .mergeBuildArgsIncludingLocalDockerConfigProxySettings (imageConfiguration , jKubeConfiguration ))
143
144
.withMessage ("Multiple Build Args with the same key: VERSION=latest and VERSION=1.0.0" );
144
145
}
145
146
146
- @ Test
147
- @ DisplayName ("should add proxy build args from ~/.docker/config.json" )
148
- void shouldAddBuildArgsFromDockerConfig (@ TempDir File temporaryFolder ) throws IOException {
149
- try {
150
- // Given
147
+ @ Nested
148
+ @ DisplayName ("local ~/.docker/config.json contains proxy settings" )
149
+ class LocalDockerConfigContainsProxySettings {
150
+ @ TempDir
151
+ private File temporaryFolder ;
152
+
153
+ @ BeforeEach
154
+ void setUp () throws IOException {
151
155
Path dockerConfig = temporaryFolder .toPath ();
152
156
final Map <String , String > env = Collections .singletonMap ("DOCKER_CONFIG" , dockerConfig .toFile ().getAbsolutePath ());
153
157
EnvUtil .overrideEnvGetter (env ::get );
154
158
Files .write (dockerConfig .resolve ("config.json" ), ("{\" proxies\" : {\" default\" : {\n " +
155
- " \" httpProxy\" : \" http://proxy.example.com:3128\" ,\n " +
156
- " \" httpsProxy\" : \" https://proxy.example.com:3129\" ,\n " +
157
- " \" noProxy\" : \" *.test.example.com,.example.org,127.0.0.0/8\" \n " +
158
- " }}}" ).getBytes ());
159
+ " \" httpProxy\" : \" http://proxy.example.com:3128\" ,\n " +
160
+ " \" httpsProxy\" : \" https://proxy.example.com:3129\" ,\n " +
161
+ " \" noProxy\" : \" *.test.example.com,.example.org,127.0.0.0/8\" \n " +
162
+ " }}}" ).getBytes ());
163
+
164
+ }
165
+
166
+ @ Test
167
+ @ DisplayName ("mergeBuildArgsIncludingLocalDockerConfigProxySettings, should add proxy build args for docker build strategy" )
168
+ void shouldAddBuildArgsFromDockerConfigInDockerBuild () {
159
169
// When
160
- final Map <String , String > mergedBuildArgs = BuildArgResolverUtil .mergeBuildArgs (imageConfiguration , jKubeConfiguration );
170
+ final Map <String , String > mergedBuildArgs = BuildArgResolverUtil .mergeBuildArgsIncludingLocalDockerConfigProxySettings (imageConfiguration , jKubeConfiguration );
161
171
// Then
162
172
assertThat (mergedBuildArgs )
163
173
.containsEntry ("docker.buildArg.http_proxy" , "http://proxy.example.com:3128" )
164
174
.containsEntry ("docker.buildArg.https_proxy" , "https://proxy.example.com:3129" )
165
175
.containsEntry ("docker.buildArg.no_proxy" , "*.test.example.com,.example.org,127.0.0.0/8" );
166
- } finally {
176
+ }
177
+
178
+ @ Test
179
+ @ DisplayName ("mergeBuildArgsWithoutIncludingLocalDockerConfigProxySettings, should not add proxy build args for OpenShift build strategy" )
180
+ void shouldNotAddBuildArgsFromDockerConfig () {
181
+ // When
182
+ final Map <String , String > mergedBuildArgs = BuildArgResolverUtil .mergeBuildArgsWithoutLocalDockerConfigProxySettings (imageConfiguration , jKubeConfiguration );
183
+ // Then
184
+ assertThat (mergedBuildArgs )
185
+ .doesNotContainEntry ("docker.buildArg.http_proxy" , "http://proxy.example.com:3128" )
186
+ .doesNotContainEntry ("docker.buildArg.https_proxy" , "https://proxy.example.com:3129" )
187
+ .doesNotContainEntry ("docker.buildArg.no_proxy" , "*.test.example.com,.example.org,127.0.0.0/8" );
188
+ }
189
+
190
+ @ AfterEach
191
+ void tearDown () {
167
192
EnvUtil .overrideEnvGetter (System ::getenv );
168
193
}
169
194
}
0 commit comments