### Question:
PlatformChecker { static void checkManifestPlatform( BuildContext buildContext, ContainerConfigurationTemplate containerConfig) { EventHandlers eventHandlers = buildContext.getEventHandlers(); String baseImageName = buildContext.getBaseImageConfiguration().getTarPath().isPresent() ? buildContext.getBaseImageConfiguration().getTarPath().get().toString() : buildContext.getBaseImageConfiguration().getImage().toString(); Set<Platform> platforms = buildContext.getContainerConfiguration().getPlatforms(); Verify.verify(!platforms.isEmpty()); if (platforms.size() != 1) { eventHandlers.dispatch( LogEvent.warn( "platforms configured, but '" + baseImageName + "' is not a manifest list")); } else { Platform platform = platforms.iterator().next(); if (!platform.getArchitecture().equals(containerConfig.getArchitecture()) || !platform.getOs().equals(containerConfig.getOs())) { if (!(platform.getArchitecture().equals("amd64") && platform.getOs().equals("linux"))) { String warning = "the configured platform (%s/%s) doesn't match the platform (%s/%s) of the base " + "image (%s)"; eventHandlers.dispatch( LogEvent.warn( String.format( warning, platform.getArchitecture(), platform.getOs(), containerConfig.getArchitecture(), containerConfig.getOs(), baseImageName))); } } } }    }### Answer:
@Test public void testCheckManifestPlatform_mismatch() { Mockito.when(containerConfig.getPlatforms()) .thenReturn(ImmutableSet.of(new Platform("configured arch", "configured OS"))); ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate(); containerConfigJson.setArchitecture("actual arch"); containerConfigJson.setOs("actual OS"); PlatformChecker.checkManifestPlatform(buildContext, containerConfigJson); Mockito.verify(eventHandlers) .dispatch( LogEvent.warn( "the configured platform (configured arch/configured OS) doesn't match the " + "platform (actual arch/actual OS) of the base image (scratch)")); }
@Test public void testCheckManifestPlatform_noWarningIfDefaultAmd64Linux() { Mockito.when(containerConfig.getPlatforms()) .thenReturn(ImmutableSet.of(new Platform("amd64", "linux"))); ContainerConfigurationTemplate containerConfigJson = new ContainerConfigurationTemplate(); containerConfigJson.setArchitecture("actual arch"); containerConfigJson.setOs("actual OS"); PlatformChecker.checkManifestPlatform(buildContext, containerConfigJson); Mockito.verifyNoInteractions(eventHandlers); }
@Test public void testCheckManifestPlatform_multiplePlatformsConfigured() { Mockito.when(containerConfig.getPlatforms()) .thenReturn(ImmutableSet.of(new Platform("amd64", "linux"), new Platform("arch", "os"))); PlatformChecker.checkManifestPlatform(buildContext, new ContainerConfigurationTemplate()); Mockito.verify(eventHandlers) .dispatch(LogEvent.warn("platforms configured, but 'scratch' is not a manifest list")); }
@Test public void testCheckManifestPlatform_tarBaseImage() { Path tar = Paths.get("/foo/bar.tar"); Mockito.when(buildContext.getBaseImageConfiguration()) .thenReturn(ImageConfiguration.builder(ImageReference.scratch()).setTarPath(tar).build()); Mockito.when(containerConfig.getPlatforms()) .thenReturn(ImmutableSet.of(new Platform("amd64", "linux"), new Platform("arch", "os"))); PlatformChecker.checkManifestPlatform(buildContext, new ContainerConfigurationTemplate()); Mockito.verify(eventHandlers) .dispatch( LogEvent.warn( "platforms configured, but '" + tar.toString() + "' is not a manifest list")); }