Add support for Ubuntu20 on kokoro (#2279)

This commit is contained in:
Pavlo Tkach 2024-01-10 14:32:34 -05:00 committed by GitHub
parent 265d69051b
commit d7edd27cdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 25 deletions

View file

@ -16,11 +16,9 @@ package google.registry.tools;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import org.flywaydb.core.Flyway;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.Container;
/**
@ -36,9 +34,6 @@ public class DumpGoldenSchemaCommand extends PostgresqlCommand {
// The mount point in the container.
private static final String CONTAINER_MOUNT_POINT = "/tmp/pg_dump.out";
// Temporary workaround to fix permission issues on certain Linux distro (e. g. Arch Linux).
private static final String CONTAINER_MOUNT_POINT_TMP = "/tmp/pg_dump.tmp";
@Parameter(
names = {"--output", "-o"},
description = "Output file",
@ -64,19 +59,7 @@ public class DumpGoldenSchemaCommand extends PostgresqlCommand {
if (result.getExitCode() != 0) {
throw new RuntimeException(result.toString());
}
result =
postgresContainer.execInContainer("cp", CONTAINER_MOUNT_POINT_TMP, CONTAINER_MOUNT_POINT);
if (result.getExitCode() != 0) {
throw new RuntimeException(result.toString());
}
}
@Override
protected void onContainerCreate() throws IOException {
// open the output file for write so we can mount it.
new FileOutputStream(output.toFile()).close();
postgresContainer.withFileSystemBind(
output.toString(), CONTAINER_MOUNT_POINT, BindMode.READ_WRITE);
postgresContainer.copyFileFromContainer(CONTAINER_MOUNT_POINT, output.toString());
}
private static String[] getSchemaDumpCommand(String username, String dbName) {
@ -87,7 +70,7 @@ public class DumpGoldenSchemaCommand extends PostgresqlCommand {
"-U",
username,
"-f",
CONTAINER_MOUNT_POINT_TMP,
CONTAINER_MOUNT_POINT,
"--schema-only",
"--no-owner",
"--no-privileges",

View file

@ -38,6 +38,8 @@ class PathParameterTest {
private final PathParameter vanilla = new PathParameter();
private static final Boolean isRoot = "root".equals(System.getProperty("user.name"));
@Test
void testConvert_etcPasswd_returnsPath() {
assertThat((Object) vanilla.convert("/etc/passwd")).isEqualTo(Paths.get("/etc/passwd"));
@ -105,9 +107,15 @@ class PathParameterTest {
void testInputFileValidate_unreadableFile_throws() throws Exception {
Path file = Files.createFile(tmpDir.resolve("tmpfile.txt"));
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("-w-------"));
ParameterException thrown =
assertThrows(ParameterException.class, () -> inputFile.validate("input", file.toString()));
assertThat(thrown).hasMessageThat().contains("not readable");
// This test doesn't take into account the fact that root user has access to read/write the
// file even if posix permissions disallow it.
// For the environmnent that run strictly under root, we will ignore the test results.
if (!isRoot) {
ParameterException thrown =
assertThrows(
ParameterException.class, () -> inputFile.validate("input", file.toString()));
assertThat(thrown).hasMessageThat().contains("not readable");
}
}
// =========================== Test OutputFile Validate ========================================
@ -142,9 +150,15 @@ class PathParameterTest {
void testOutputFileValidate_notWritable_throws() throws Exception {
Path file = Files.createFile(tmpDir.resolve("newFile.dat"));
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("r--------"));
ParameterException thrown =
assertThrows(ParameterException.class, () -> outputFile.validate("input", file.toString()));
assertThat(thrown).hasMessageThat().contains("not writable");
// This test doesn't take into account the fact that root user has access to read/write the
// file even if posix permissions disallow it.
// For the environmnent that run strictly under root, we will ignore the test results.
if (!isRoot) {
ParameterException thrown =
assertThrows(
ParameterException.class, () -> outputFile.validate("input", file.toString()));
assertThat(thrown).hasMessageThat().contains("not writable");
}
}
@Test