mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(lambda): propagate image inspection failures (#2268)
Co-authored-by: Moroshani <208086089+moroshani@users.noreply.github.com>
This commit is contained in:
1 parent
b911ccd013
commit
9ebf9feb54
2 files changed
+54
-3
No files matched your search
-3
@@ -124,9 +124,6 @@ public class ImageCacheService {
|
||||
return true;
|
||||
} catch (com.github.dockerjava.api.exception.NotFoundException e) {
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
LOG.debugv("Could not check local image presence for {0}: {1}", imageUri, e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+54
@@ -1,22 +1,68 @@
|
||||
package io.github.hectorvent.floci.services.lambda.launcher;
|
||||
|
||||
import com.github.dockerjava.api.DockerClient;
|
||||
import com.github.dockerjava.api.command.InspectImageCmd;
|
||||
import com.github.dockerjava.api.command.PullImageCmd;
|
||||
import com.github.dockerjava.api.command.PullImageResultCallback;
|
||||
import com.github.dockerjava.api.exception.DockerClientException;
|
||||
import com.github.dockerjava.api.exception.DockerException;
|
||||
import com.github.dockerjava.api.exception.InternalServerErrorException;
|
||||
import com.github.dockerjava.api.exception.NotFoundException;
|
||||
import com.github.dockerjava.api.exception.UnauthorizedException;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class ImageCacheServiceTest {
|
||||
|
||||
private static final String IMAGE = "public.ecr.aws/docker/library/alpine:latest";
|
||||
|
||||
@Test
|
||||
void pullsImageWhenInspectionReportsNotFound() throws Exception {
|
||||
DockerClient dockerClient = mock(DockerClient.class);
|
||||
InspectImageCmd inspectImage = mock(InspectImageCmd.class);
|
||||
PullImageCmd pullImage = mock(PullImageCmd.class);
|
||||
PullImageResultCallback callback = mock(PullImageResultCallback.class);
|
||||
when(dockerClient.inspectImageCmd(IMAGE)).thenReturn(inspectImage);
|
||||
when(inspectImage.exec()).thenThrow(new NotFoundException("image not found"));
|
||||
when(dockerClient.pullImageCmd(IMAGE)).thenReturn(pullImage);
|
||||
when(pullImage.withAuthConfig(any())).thenReturn(pullImage);
|
||||
when(pullImage.exec(any(PullImageResultCallback.class))).thenReturn(callback);
|
||||
|
||||
newService(dockerClient).ensureImageExists(IMAGE);
|
||||
|
||||
verify(pullImage).exec(any(PullImageResultCallback.class));
|
||||
verify(callback).awaitCompletion(5, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
void propagatesImageInspectionFailureWithoutPulling() {
|
||||
DockerClient dockerClient = mock(DockerClient.class);
|
||||
InspectImageCmd inspectImage = mock(InspectImageCmd.class);
|
||||
DockerClientException failure = new DockerClientException("daemon unavailable");
|
||||
when(dockerClient.inspectImageCmd(IMAGE)).thenReturn(inspectImage);
|
||||
when(inspectImage.exec()).thenThrow(failure);
|
||||
|
||||
DockerClientException thrown = assertThrows(DockerClientException.class,
|
||||
() -> newService(dockerClient).ensureImageExists(IMAGE));
|
||||
|
||||
assertSame(failure, thrown);
|
||||
verify(dockerClient, never()).pullImageCmd(IMAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void succeedsOnFirstAttempt() throws Exception {
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
@@ -115,4 +161,12 @@ class ImageCacheServiceTest {
|
||||
}));
|
||||
assertEquals(1, calls.get());
|
||||
}
|
||||
|
||||
private static ImageCacheService newService(DockerClient dockerClient) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
EmulatorConfig.DockerConfig dockerConfig = mock(EmulatorConfig.DockerConfig.class);
|
||||
when(config.docker()).thenReturn(dockerConfig);
|
||||
when(dockerConfig.registryCredentials()).thenReturn(List.of());
|
||||
return new ImageCacheService(dockerClient, config);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user