Start postgresql container in generate_sql_schema (#249)

* Start postgresql container in generate_sql_schema

Add a --start-postgresql option to the nomulus generate_sql_schema command so
that users don't have to start their own docker container to run it.

* Made default behavior be to give guidance
This commit is contained in:
Michael Muller 2019-08-30 16:04:34 -04:00 committed by GitHub
parent dc9d9158d8
commit d3ccad3aa7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 24 deletions

View file

@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
import java.io.File;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@ -35,7 +36,7 @@ public class GenerateSqlSchemaCommandTest extends CommandTestCase<GenerateSqlSch
@Rule public TemporaryFolder tmp = new TemporaryFolder();
@Rule public PostgreSQLContainer postgres =
@ClassRule public static PostgreSQLContainer postgres =
new PostgreSQLContainer()
.withDatabaseName("postgres")
.withUsername("postgres")
@ -61,4 +62,22 @@ public class GenerateSqlSchemaCommandTest extends CommandTestCase<GenerateSqlSch
// TODO: try running the schema against the test database.
assertThat(new File(tmp.getRoot(), "schema.sql").exists()).isTrue();
}
@Test
public void testIncompatibleFlags() throws Exception {
runCommand(
"--out-file=" + tmp.getRoot() + File.separatorChar + "schema.sql",
"--db-host=" + containerHostName,
"--db-port=" + containerPort,
"--start-postgresql");
assertInStderr(GenerateSqlSchemaCommand.DB_OPTIONS_CLASH);
}
@Test
public void testDockerPostgresql() throws Exception {
runCommand(
"--start-postgresql",
"--out-file=" + tmp.getRoot() + File.separatorChar + "schema.sql");
assertThat(new File(tmp.getRoot(), "schema.sql").exists()).isTrue();
}
}