-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Add Singer infra #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Singer infra #58
Changes from 10 commits
892731c
6841917
b702850
abef59c
a43a2c0
b0414dc
315a352
558e8c9
95e0107
1facf7b
3217538
09c134c
0c57c92
6403b06
3077f6d
8f62231
b91aef4
45452cd
2dd3b33
09a1d82
6daa256
c49c950
03c2817
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
.git | ||
.gradle | ||
.idea | ||
**/build | ||
**/node_modules |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
VERSION=0.1.0 | ||
ENV=docker | ||
ENV=docker |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,11 @@ public abstract class BaseWorkerTestCase { | |
@BeforeAll | ||
public void init() { | ||
createTestWorkspace(); | ||
deleteWorkspaceUponJvmExit(); | ||
try { | ||
FileUtils.forceDeleteOnExit(workspaceDirectory.toFile()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
protected Path getWorkspacePath() { | ||
|
@@ -24,23 +28,11 @@ protected Path getWorkspacePath() { | |
|
||
private void createTestWorkspace() { | ||
try { | ||
workspaceDirectory = Paths.get("/tmp/tests/dataline-" + UUID.randomUUID().toString()); | ||
workspaceDirectory = | ||
Paths.get("/tmp/tests/dataline-" + UUID.randomUUID().toString().substring(0, 8)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah didn't know about that one -- will take a look. TY for the tip. |
||
FileUtils.forceMkdir(workspaceDirectory.toFile()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private void deleteWorkspaceUponJvmExit() { | ||
Runtime.getRuntime() | ||
.addShutdownHook( | ||
new Thread( | ||
() -> { | ||
try { | ||
FileUtils.deleteDirectory(workspaceDirectory.toFile()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
})); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,75 @@ | ||
package io.dataline.workers.singer; | ||
|
||
public class TestSingerDiscoveryWorker { | ||
// TODO pending installing singer binaries into the workspace | ||
import static io.dataline.workers.JobStatus.SUCCESSFUL; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.collect.Maps; | ||
import com.google.common.io.Resources; | ||
import io.dataline.workers.BaseWorkerTestCase; | ||
import io.dataline.workers.DiscoveryOutput; | ||
import io.dataline.workers.OutputAndStatus; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.nio.charset.Charset; | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am curious do these test past on github? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup! |
||
|
||
public class TestSingerDiscoveryWorker extends BaseWorkerTestCase { | ||
|
||
@Test | ||
public void testPostgresDiscovery() throws SQLException, IOException { | ||
PostgreSQLContainer db = new PostgreSQLContainer(); | ||
db.start(); | ||
Connection con = | ||
DriverManager.getConnection(db.getJdbcUrl(), db.getUsername(), db.getPassword()); | ||
con.createStatement().execute("CREATE TABLE id_and_name (id integer, name VARCHAR(200));"); | ||
|
||
String postgresCreds = getPostgresConfigJson(db); | ||
SingerDiscoveryWorker worker = | ||
new SingerDiscoveryWorker( | ||
"1", | ||
postgresCreds, | ||
SingerTap.POSTGRES, | ||
getWorkspacePath().toAbsolutePath().toString(), | ||
"/usr/local/lib/singer/"); // TODO inject as env variable | ||
|
||
System.out.println(getWorkspacePath().toAbsolutePath().toString()); | ||
System.out.println(postgresCreds); | ||
OutputAndStatus<DiscoveryOutput> run = worker.run(); | ||
assertEquals(SUCCESSFUL, run.status); | ||
|
||
String expectedCatalog = | ||
Resources.toString( | ||
Resources.getResource("simple_postgres_catalog.json"), Charset.defaultCharset()); | ||
assertTrue(run.output.isPresent()); | ||
assertEquals(expectedCatalog, run.output.get().catalog); | ||
} | ||
|
||
private String readResource(String name) { | ||
URL resource = Resources.getResource(name); | ||
try { | ||
return Resources.toString(resource, Charset.defaultCharset()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private String getPostgresConfigJson(PostgreSQLContainer psqlContainer) | ||
throws JsonProcessingException { | ||
Map<String, String> props = Maps.newHashMap(); | ||
props.put("dbname", psqlContainer.getDatabaseName()); | ||
props.put("user", psqlContainer.getUsername()); | ||
props.put("password", psqlContainer.getPassword()); | ||
props.put("host", psqlContainer.getHost()); | ||
props.put("port", String.valueOf(psqlContainer.getFirstMappedPort())); | ||
|
||
return new ObjectMapper().writeValueAsString(props); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if tests fail we want to see the reasons on the CLI