Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
rh-che #1418: Adding 'dockerImage' caching during CDN pre-fetching
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
  • Loading branch information
ibuziuk committed May 31, 2019
1 parent f2c91e9 commit d4a8c3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ public String getPaths() throws Exception {
throw new NotFoundException("No editor is configured for CDN resource pre-fetching");
}

PluginMeta editorMeta = getEditorMeta();
dockerImage = getDockerImage(editorMeta);
if (dockerImage == null) {
PluginMeta editorMeta = getEditorMeta();
dockerImage = getDockerImage(editorMeta);
}

JsonNode json = inspectDockerImage();
return json.path("Labels").path(LABEL_NAME).asText("[]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -100,12 +99,6 @@ protected URLConnection openConnection(URL u) throws IOException {
});
}

@BeforeMethod
public void setUp() throws Exception {
service = null;
when(pluginFQNParser.parsePluginFQN(any())).thenReturn(PLUGIN_FQN);
}

@Test(
expectedExceptions = {RuntimeException.class},
expectedExceptionsMessageRegExp =
Expand All @@ -131,6 +124,7 @@ public void throwWhenNoPreferredEditor() throws Exception {
expectedExceptions = {InfrastructureException.class},
expectedExceptionsMessageRegExp = DOWNLOAD_EXCEPTION_MESSAGE)
public void throwWhenEditorNotFound() throws Exception {
when(pluginFQNParser.parsePluginFQN(any())).thenReturn(PLUGIN_FQN);
doThrow(new IOException(DOWNLOAD_ERROR)).when(yamlDownloader).getYamlResponseAndParse(any());
service =
new CdnSupportService(
Expand All @@ -142,6 +136,7 @@ public void throwWhenEditorNotFound() throws Exception {
expectedExceptions = {ServerException.class},
expectedExceptionsMessageRegExp = SERVER_EXCEPTION_MESSAGE_WHEN_SPEC_IS_NULL)
public void throwWhenEditorSpecIsNull() throws Exception {
when(pluginFQNParser.parsePluginFQN(any())).thenReturn(PLUGIN_FQN);
doReturn(pluginMeta).when(yamlDownloader).getYamlResponseAndParse(any());
doReturn(null).when(pluginMeta).getSpec();
service =
Expand All @@ -155,7 +150,7 @@ public void throwWhenEditorSpecIsNull() throws Exception {
expectedExceptions = {ServerException.class},
expectedExceptionsMessageRegExp = SERVER_EXCEPTION_MESSAGE_WHEN_NO_CONTAINERS_IN_SPEC)
public void throwWhenEditorContainersIsNull() throws Exception {

when(pluginFQNParser.parsePluginFQN(any())).thenReturn(PLUGIN_FQN);
doReturn(pluginMeta).when(yamlDownloader).getYamlResponseAndParse(any());
doReturn(pluginSpec).when(pluginMeta).getSpec();
doReturn(null).when(pluginSpec).getContainers();
Expand All @@ -170,6 +165,7 @@ public void throwWhenEditorContainersIsNull() throws Exception {
expectedExceptions = {ServerException.class},
expectedExceptionsMessageRegExp = SERVER_EXCEPTION_MESSAGE_WHEN_NO_CONTAINERS_IN_SPEC)
public void throwWhenEditorContainersIsEmpty() throws Exception {
when(pluginFQNParser.parsePluginFQN(any())).thenReturn(PLUGIN_FQN);
doReturn(pluginMeta).when(yamlDownloader).getYamlResponseAndParse(any());
doReturn(pluginSpec).when(pluginMeta).getSpec();
doReturn(Collections.EMPTY_LIST).when(pluginSpec).getContainers();
Expand All @@ -184,6 +180,7 @@ public void throwWhenEditorContainersIsEmpty() throws Exception {
expectedExceptions = {ServerException.class},
expectedExceptionsMessageRegExp = SERVER_EXCEPTION_MESSAGE_WHEN_MULTIPLE_CONTAINERS_IN_SPEC)
public void throwWhenMultipleEditorContainers() throws Exception {
when(pluginFQNParser.parsePluginFQN(any())).thenReturn(PLUGIN_FQN);
doReturn(pluginMeta).when(yamlDownloader).getYamlResponseAndParse(any());
doReturn(pluginSpec).when(pluginMeta).getSpec();
doReturn(containers).when(pluginSpec).getContainers();
Expand All @@ -199,6 +196,7 @@ public void throwWhenMultipleEditorContainers() throws Exception {
expectedExceptions = {ServerException.class},
expectedExceptionsMessageRegExp = SERVER_EXCEPTION_MESSAGE_WHEN_CONTAINER_IMAGE_IS_NULL)
public void throwWhenContainerImageIsNull() throws Exception {
when(pluginFQNParser.parsePluginFQN(any())).thenReturn(PLUGIN_FQN);
doReturn(pluginMeta).when(yamlDownloader).getYamlResponseAndParse(any());
doReturn(pluginSpec).when(pluginMeta).getSpec();
doReturn(containers).when(pluginSpec).getContainers();
Expand Down Expand Up @@ -244,14 +242,6 @@ public void throwWhenSkopeoFailsWithNonZeroCode() throws Exception {

@Test
public void reuseExistingImageRefAndReturnLabelWhenSkopeoSucceeds() throws Exception {
doReturn(pluginMeta).when(yamlDownloader).getYamlResponseAndParse(any());
doReturn(pluginSpec).when(pluginMeta).getSpec();
doReturn(containers).when(pluginSpec).getContainers();
doReturn(false).when(containers).isEmpty();
doReturn(1).when(containers).size();
doReturn(container).when(containers).get(0);
doReturn(IMAGE_REF).when(container).getImage();

lenient()
.when(commandRunner.runCommand(eq("skopeo"), any(), any(), anyLong(), any(), any(), any()))
.thenReturn(skopeoHelpProcess, skopeoInspectProcess);
Expand All @@ -268,11 +258,12 @@ public void reuseExistingImageRefAndReturnLabelWhenSkopeoSucceeds() throws Excep

assertEquals(service.getPaths(), "cdnJsonContent");

verify(yamlDownloader, times(1)).getYamlResponseAndParse(PLUGIN_URL);
verify(yamlDownloader, times(0)).getYamlResponseAndParse(PLUGIN_URL);
}

@Test
public void searchForImageRefAndReturnLabelWhenSkopeoSucceeds() throws Exception {
when(pluginFQNParser.parsePluginFQN(any())).thenReturn(PLUGIN_FQN);
doReturn(pluginMeta).when(yamlDownloader).getYamlResponseAndParse(any());
doReturn(pluginSpec).when(pluginMeta).getSpec();
doReturn(containers).when(pluginSpec).getContainers();
Expand Down

0 comments on commit d4a8c3b

Please sign in to comment.