@Test
  public void testBuild_parentDirBehavior() throws IOException {
    Path testRoot = temporaryFolder.getRoot().toPath();

    // the path doesn't really matter on source files, but these are structured
    Path parent = Files.createDirectories(testRoot.resolve("dirA"));
    Path fileA = Files.createFile(parent.resolve("fileA"));
    Path ignoredParent = Files.createDirectories(testRoot.resolve("dirB-ignored"));
    Path fileB = Files.createFile(ignoredParent.resolve("fileB"));
    Path fileC =
        Files.createFile(Files.createDirectories(testRoot.resolve("dirC-absent")).resolve("fileC"));

    Blob layer =
        new ReproducibleLayerBuilder(
                ImmutableList.of(
                    new FileEntry(
                        parent,
                        AbsoluteUnixPath.get("/root/dirA"),
                        FilePermissions.fromOctalString("111"),
                        Instant.ofEpochSecond(10)),
                    new FileEntry(
                        fileA,
                        AbsoluteUnixPath.get("/root/dirA/fileA"),
                        FilePermissions.fromOctalString("222"),
                        Instant.ofEpochSecond(20)),
                    new FileEntry(
                        fileB,
                        AbsoluteUnixPath.get("/root/dirB-ignored/fileB"),
                        FilePermissions.fromOctalString("333"),
                        Instant.ofEpochSecond(30)),
                    new FileEntry(
                        ignoredParent,
                        AbsoluteUnixPath.get("/root/dirB-ignored"),
                        FilePermissions.fromOctalString("444"),
                        Instant.ofEpochSecond(40)),
                    new FileEntry(
                        fileC,
                        AbsoluteUnixPath.get("/root/dirC-absent/file3"),
                        FilePermissions.fromOctalString("555"),
                        Instant.ofEpochSecond(50))))
            .build();

    Path tarFile = temporaryFolder.newFile().toPath();
    try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(tarFile))) {
      layer.writeTo(out);
    }

    try (TarArchiveInputStream in = new TarArchiveInputStream(Files.newInputStream(tarFile))) {
      // root (default folder permissions)
      TarArchiveEntry root = in.getNextTarEntry();
      assertThat(root.getMode()).isEqualTo(040755);
      assertThat(root.getModTime().toInstant()).isEqualTo(Instant.ofEpochSecond(1));
      assertThat(root.getLongUserId()).isEqualTo(0);
      assertThat(root.getLongGroupId()).isEqualTo(0);
      assertThat(root.getUserName()).isEmpty();
      assertThat(root.getGroupName()).isEmpty();

      // parentAAA (custom permissions, custom timestamp)
      TarArchiveEntry rootParentA = in.getNextTarEntry();
      assertThat(rootParentA.getMode()).isEqualTo(040111);
      assertThat(rootParentA.getModTime().toInstant()).isEqualTo(Instant.ofEpochSecond(10));
      assertThat(rootParentA.getLongUserId()).isEqualTo(0);
      assertThat(rootParentA.getLongGroupId()).isEqualTo(0);
      assertThat(rootParentA.getUserName()).isEmpty();
      assertThat(rootParentA.getGroupName()).isEmpty();

      // skip over fileA
      in.getNextTarEntry();

      // parentBBB (default permissions - ignored custom permissions, since fileB added first)
      TarArchiveEntry rootParentB = in.getNextTarEntry();
      // TODO (#1650): we want 040444 here.
      assertThat(rootParentB.getMode()).isEqualTo(040755);
      // TODO (#1650): we want Instant.ofEpochSecond(40) here.
      assertThat(rootParentB.getModTime().toInstant()).isEqualTo(Instant.ofEpochSecond(1));
      assertThat(rootParentB.getLongUserId()).isEqualTo(0);
      assertThat(rootParentB.getLongGroupId()).isEqualTo(0);
      assertThat(rootParentB.getUserName()).isEmpty();
      assertThat(rootParentB.getGroupName()).isEmpty();

      // skip over fileB
      in.getNextTarEntry();

      // parentCCC (default permissions - no entry provided)
      TarArchiveEntry rootParentC = in.getNextTarEntry();
      assertThat(rootParentC.getMode()).isEqualTo(040755);
      assertThat(rootParentC.getModTime().toInstant()).isEqualTo(Instant.ofEpochSecond(1));
      assertThat(rootParentC.getLongUserId()).isEqualTo(0);
      assertThat(rootParentC.getLongGroupId()).isEqualTo(0);
      assertThat(rootParentC.getUserName()).isEmpty();
      assertThat(rootParentC.getGroupName()).isEmpty();

      // we don't care about fileC
    }
  }
Verifies that the next {@link TarArchiveEntry} in the {@link TarArchiveInputStream} is a
directory with correct permissions.

@param tarArchiveInputStream the {@link TarArchiveInputStream} to read from
@param expectedExtractionPath the expected extraction path of the next entry
@throws IOException if an I/O exception occurs
jib-core/src/test/java/com/google/cloud/tools/jib/image/ReproducibleLayerBuilderTest.java