-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log Docker Build Context Directory while building image in Simple Dockerfile mode #1192
Merged
manusa
merged 1 commit into
eclipse-jkube:master
from
rohanKanojia:pr/log-contextdir-simpledockerfilemode
Jan 31, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,13 +13,13 @@ | |
*/ | ||
package org.eclipse.jkube.kit.build.service.docker.helper; | ||
|
||
import mockit.Expectations; | ||
import mockit.Mocked; | ||
import org.eclipse.jkube.kit.build.service.docker.config.handler.ImageConfigResolver; | ||
import org.eclipse.jkube.kit.common.JKubeConfiguration; | ||
import org.eclipse.jkube.kit.common.JavaProject; | ||
import org.eclipse.jkube.kit.common.KitLogger; | ||
import org.eclipse.jkube.kit.config.image.ImageConfiguration; | ||
import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
|
@@ -30,16 +30,24 @@ | |
import java.util.Properties; | ||
|
||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | ||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ConfigHelperTest { | ||
@Mocked | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not using Mockito annotations ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'd need to run the test with MockitoJUnitRunner.class These annotations were the ones provided by JMockit. |
||
private ImageConfigResolver imageConfigResolver; | ||
|
||
@Mocked | ||
private KitLogger logger; | ||
|
||
@Mocked | ||
private JavaProject javaProject; | ||
private JKubeConfiguration jKubeConfiguration; | ||
|
||
@Before | ||
public void setUp() { | ||
imageConfigResolver = mock(ImageConfigResolver.class, RETURNS_DEEP_STUBS); | ||
logger = new KitLogger.SilentLogger(); | ||
javaProject = mock(JavaProject.class, RETURNS_DEEP_STUBS); | ||
jKubeConfiguration = mock(JKubeConfiguration.class, RETURNS_DEEP_STUBS); | ||
when(jKubeConfiguration.getProject()).thenReturn(javaProject); | ||
} | ||
|
||
@Test | ||
public void initImageConfiguration_withSimpleImageConfiguration_shouldReturnImageConfiguration() { | ||
|
@@ -52,16 +60,11 @@ public void initImageConfiguration_withSimpleImageConfiguration_shouldReturnImag | |
.build(); | ||
List<ImageConfiguration> images = new ArrayList<>(); | ||
images.add(dummyImageConfiguration); | ||
new Expectations() {{ | ||
imageConfigResolver.resolve(dummyImageConfiguration, javaProject); | ||
result = dummyImageConfiguration; | ||
|
||
javaProject.getBaseDirectory(); | ||
result = new File("dummydir"); | ||
}}; | ||
when(jKubeConfiguration.getBasedir()).thenReturn(new File("dummydir")); | ||
when(imageConfigResolver.resolve(dummyImageConfiguration, javaProject)).thenReturn(images); | ||
|
||
// When | ||
List<ImageConfiguration> resolvedImages = ConfigHelper.initImageConfiguration("1.12", new Date(), javaProject, images, imageConfigResolver, logger, null, configs -> configs); | ||
List<ImageConfiguration> resolvedImages = ConfigHelper.initImageConfiguration("1.12", new Date(), images, imageConfigResolver, logger, null, configs -> configs, jKubeConfiguration); | ||
|
||
// Then | ||
assertThat(resolvedImages) | ||
|
@@ -74,25 +77,14 @@ public void initImageConfiguration_withSimpleImageConfiguration_shouldReturnImag | |
public void initImageConfiguration_withSimpleDockerFileInProjectBaseDir_shouldCreateImageConfiguration() { | ||
List<ImageConfiguration> images = new ArrayList<>(); | ||
File dockerFile = new File(getClass().getResource("/dummy-javaproject/Dockerfile").getFile()); | ||
new Expectations() {{ | ||
javaProject.getBaseDirectory(); | ||
result = dockerFile.getParentFile(); | ||
|
||
javaProject.getProperties(); | ||
result = new Properties(); | ||
|
||
javaProject.getGroupId(); | ||
result = "org.eclipse.jkube"; | ||
|
||
javaProject.getArtifactId(); | ||
result = "test-java-project"; | ||
|
||
javaProject.getVersion(); | ||
result = "0.0.1-SNAPSHOT"; | ||
}}; | ||
when(jKubeConfiguration.getBasedir()).thenReturn(dockerFile.getParentFile()); | ||
when(javaProject.getProperties()).thenReturn(new Properties()); | ||
when(javaProject.getGroupId()).thenReturn("org.eclipse.jkube"); | ||
when(javaProject.getArtifactId()).thenReturn("test-java-project"); | ||
when(javaProject.getVersion()).thenReturn("0.0.1-SNAPSHOT"); | ||
|
||
// When | ||
List<ImageConfiguration> resolvedImages = ConfigHelper.initImageConfiguration("1.12", new Date(), javaProject, images, imageConfigResolver, logger, null, configs -> configs); | ||
List<ImageConfiguration> resolvedImages = ConfigHelper.initImageConfiguration("1.12", new Date(), images, imageConfigResolver, logger, null, configs -> configs, jKubeConfiguration); | ||
|
||
// Then | ||
assertThat(resolvedImages) | ||
|
@@ -112,19 +104,12 @@ public void initImageConfiguration_withSimpleDockerFileModeEnabledAndImageConfig | |
List<ImageConfiguration> images = new ArrayList<>(); | ||
images.add(dummyImageConfiguration); | ||
File dockerFile = new File(getClass().getResource("/dummy-javaproject/Dockerfile").getFile()); | ||
new Expectations() {{ | ||
imageConfigResolver.resolve(dummyImageConfiguration, javaProject); | ||
result = dummyImageConfiguration; | ||
|
||
javaProject.getBaseDirectory(); | ||
result = dockerFile.getParentFile(); | ||
|
||
javaProject.getProperties(); | ||
result = new Properties(); | ||
}}; | ||
when(imageConfigResolver.resolve(dummyImageConfiguration, javaProject)).thenReturn(images); | ||
when(jKubeConfiguration.getBasedir()).thenReturn(dockerFile.getParentFile()); | ||
when(javaProject.getProperties()).thenReturn(new Properties()); | ||
|
||
// When | ||
List<ImageConfiguration> resolvedImages = ConfigHelper.initImageConfiguration("1.12", new Date(), javaProject, images, imageConfigResolver, logger, null, configs -> configs); | ||
List<ImageConfiguration> resolvedImages = ConfigHelper.initImageConfiguration("1.12", new Date(), images, imageConfigResolver, logger, null, configs -> configs, jKubeConfiguration); | ||
|
||
// Then | ||
assertThat(resolvedImages) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't these directories in JavaProject?
I remember in the early days these fields were scattered all around and we managed to reduce them to just the JKubeConfiguration and the JavaProject instances.
What's the issue in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the homonymous fields have the same purpose, one set should be deprecated. If not, the undocumented, should be. This way we would avoid situations like the current were there's confusion about what should be used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see
jKubeConfiguration.getBaseDir()
returns JavaProject's base directory. But I'm not able to find anysourceDirectory
equivalent in JavaProjectThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so this one is not duplicate, it just retrieves javaProject.baseDirectory
However,
outputDirectory
is still defined in both places. We'll need to investigate and deprecate, rename or proper document them.