OfficialAgentImageResolver implements DockerImageNameResolver { @Nonnull @Override public String resolve() { return lock.call(() -> { String imageTag = this.imageTag; if (imageTag == null) { imageTag = this.imageTag = performResolution(); } return imageTag; }); } OfficialAgentImageResolver(String version, DockerRegistryClientFactory registryClientFty); @Nonnull @Override String resolve(); @Nonnull static OfficialAgentImageResolver forCurrentServer(DockerRegistryClientFactory registryFty);  }
@Test public void normalResolution() { clientFty.configureClient((clt) -> clt.knownImage(OfficialAgentImageResolver.REPO, "4.0", "5.2", "5.2.1", "5.2.1.1", "6.0", version)); OfficialAgentImageResolver resolver = createResolver(); assertThat(resolver.resolve()).isEqualTo(OfficialAgentImageResolver.REPO + ":" + version); assertThat(clientFty.getClient().isClosed()).isTrue(); }
@Test public void usingLatestWhenNoMatchingVersion() { clientFty.configureClient((clt) -> clt.knownImage(OfficialAgentImageResolver.REPO, "4.0", "6.0")); OfficialAgentImageResolver resolver = createResolver(); assertThat(resolver.resolve()).isEqualTo(OfficialAgentImageResolver.LATEST); }
@Test public void usingDefaultWhenRepoLookupFail() { clientFty.configureClient(clt -> clt.failOnAccess(new DockerClientProcessingException("Test failure."))); OfficialAgentImageResolver resolver = createResolver(); assertThat(resolver.resolve()).isEqualTo(OfficialAgentImageResolver.REPO + ":" + version); }
@Test public void mustCacheResult() { clientFty.configureClient((clt) -> clt.knownImage(OfficialAgentImageResolver.REPO, "4.0", "6.0")); OfficialAgentImageResolver resolver = createResolver(); String resolved = resolver.resolve(); clientFty.getClient().failOnAccess(new DockerClientProcessingException("Test failure.")); assertThat(resolver.resolve()).isEqualTo(resolved); }