Repository: GoogleContainerTools/jib
File: jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/ManifestPullerIntegrationTest.java (Java)

Code before:
    Assert.assertEquals(2, manifestTemplate.getSchemaVersion());
    Assert.assertTrue(manifestTemplate.getLayers().size() > 0);
  }

  @Test
  public void testPull_ociManifest() throws IOException, RegistryException {
    RegistryClient registryClient =
        RegistryClient.factory(EventHandlers.NONE, "gcr.io", "distroless/base", httpClient)
            .newRegistryClient();

    OciManifestTemplate manifestTemplate =
        registryClient
            .pullManifest(KNOWN_OCI_MANIFEST_SHA, OciManifestTemplate.class)
            .getManifest();

    Assert.assertEquals(2, manifestTemplate.getSchemaVersion());
    Assert.assertTrue(manifestTemplate.getLayers().size() > 0);
  }

  @Test
  public void testPull_v22ManifestList() throws IOException, RegistryException {
    RegistryClient registryClient =
        RegistryClient.factory(EventHandlers.NONE, "gcr.io", "distroless/base", httpClient)
            .newRegistryClient();

    // Ensures call to image at KNOWN_MANIFEST_LIST_SHA returns a manifest list
    V22ManifestListTemplate manifestListTargeted =
        registryClient
            .pullManifest(KNOWN_MANIFEST_LIST_SHA, V22ManifestListTemplate.class)
            .getManifest();
    Assert.assertEquals(2, manifestListTargeted.getSchemaVersion());
    Assert.assertTrue(manifestListTargeted.getManifests().size() > 0);

    // Generic call to image at KNOWN_MANIFEST_LIST_SHA, should also return a manifest list
    ManifestTemplate manifestListGeneric =
        registryClient.pullManifest(KNOWN_MANIFEST_LIST_SHA).getManifest();
    Assert.assertEquals(2, manifestListGeneric.getSchemaVersion());
    MatcherAssert.assertThat(
        manifestListGeneric, CoreMatchers.instanceOf(V22ManifestListTemplate.class));
    Assert.assertTrue(((V22ManifestListTemplate) manifestListGeneric).getManifests().size() > 0);
  }

  @Test
  public void testPull_ociIndex() throws IOException, RegistryException {
    RegistryClient registryClient =
        RegistryClient.factory(EventHandlers.NONE, "gcr.io", "distroless/base", httpClient)
            .newRegistryClient();

    // Ensures call to image at KNOWN_OCI_INDEX_SHA returns an OCI index
    OciIndexTemplate manifestListTargeted =
        registryClient.pullManifest(KNOWN_OCI_INDEX_SHA, OciIndexTemplate.class).getManifest();

Review comment (suggestion):
minor: how about we say something like "at the specified sha`? This can prevent the comment from becoming stale if the variable name changes.

Code after:
    assertThat(manifestTemplate.getSchemaVersion()).isEqualTo(2);
    assertThat(manifestTemplate.getLayers()).isNotEmpty();
  }

  @Test
  public void testPull_ociManifest() throws IOException, RegistryException {
    RegistryClient registryClient =
        RegistryClient.factory(EventHandlers.NONE, "gcr.io", "distroless/base", httpClient)
            .newRegistryClient();

    OciManifestTemplate manifestTemplate =
        registryClient
            .pullManifest(KNOWN_OCI_MANIFEST_SHA, OciManifestTemplate.class)
            .getManifest();

    assertThat(manifestTemplate.getSchemaVersion()).isEqualTo(2);
    assertThat(manifestTemplate.getLayers()).isNotEmpty();
  }

  @Test
  public void testPull_v22ManifestList() throws IOException, RegistryException {
    RegistryClient registryClient =
        RegistryClient.factory(EventHandlers.NONE, "gcr.io", "distroless/base", httpClient)
            .newRegistryClient();

    // Ensures call to image at the specified SHA returns a manifest list
    V22ManifestListTemplate manifestListTargeted =
        registryClient
            .pullManifest(KNOWN_MANIFEST_LIST_SHA, V22ManifestListTemplate.class)
            .getManifest();
    assertThat(manifestListTargeted.getSchemaVersion()).isEqualTo(2);
    assertThat(manifestListTargeted.getManifests()).isNotEmpty();

    // Generic call to image at the specified SHA, should also return a manifest list
    ManifestTemplate manifestListGeneric =
        registryClient.pullManifest(KNOWN_MANIFEST_LIST_SHA).getManifest();
    assertThat(manifestListGeneric.getSchemaVersion()).isEqualTo(2);
    assertThat(manifestListGeneric).isInstanceOf(V22ManifestListTemplate.class);
    assertThat(((V22ManifestListTemplate) manifestListGeneric).getManifests()).isNotEmpty();
  }

  @Test
  public void testPull_ociIndex() throws IOException, RegistryException {
    RegistryClient registryClient =
        RegistryClient.factory(EventHandlers.NONE, "gcr.io", "distroless/base", httpClient)
            .newRegistryClient();

    // Ensures call to image at the specified SHA returns an OCI index
    OciIndexTemplate manifestListTargeted =
        registryClient.pullManifest(KNOWN_OCI_INDEX_SHA, OciIndexTemplate.class).getManifest();
    assertThat(manifestListTargeted.getSchemaVersion()).isEqualTo(2);