Skip to content

Commit

Permalink
Have a persistent path root for each test case (airbytehq#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
sherifnada authored Oct 28, 2020
1 parent 3ef2baa commit 7ba6830
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ secrets
# Python
*.egg-info
__pycache__
.eggs
.venv
.mypy_cache
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,44 @@


class Type(Enum):
RECORD = "RECORD"
STATE = "STATE"
LOG = "LOG"
SPEC = "SPEC"
CONNECTION_STATUS = "CONNECTION_STATUS"
CATALOG = "CATALOG"
RECORD = 'RECORD'
STATE = 'STATE'
LOG = 'LOG'
SPEC = 'SPEC'
CONNECTION_STATUS = 'CONNECTION_STATUS'
CATALOG = 'CATALOG'


class AirbyteRecordMessage(BaseModel):
stream: str = Field(..., description="the name of the stream for this record")
data: Dict[str, Any] = Field(..., description="the record data")
stream: str = Field(..., description='the name of the stream for this record')
data: Dict[str, Any] = Field(..., description='the record data')
emitted_at: int = Field(
...,
description="when the data was emitted from the source. epoch in millisecond.",
description='when the data was emitted from the source. epoch in millisecond.',
)


class AirbyteStateMessage(BaseModel):
data: Dict[str, Any] = Field(..., description="the state data")
data: Dict[str, Any] = Field(..., description='the state data')


class Level(Enum):
FATAL = "FATAL"
ERROR = "ERROR"
WARN = "WARN"
INFO = "INFO"
DEBUG = "DEBUG"
TRACE = "TRACE"
FATAL = 'FATAL'
ERROR = 'ERROR'
WARN = 'WARN'
INFO = 'INFO'
DEBUG = 'DEBUG'
TRACE = 'TRACE'


class AirbyteLogMessage(BaseModel):
level: Level = Field(..., description="the type of logging")
message: str = Field(..., description="the log message")
level: Level = Field(..., description='the type of logging')
message: str = Field(..., description='the log message')


class Status(Enum):
SUCCEEDED = "SUCCEEDED"
FAILED = "FAILED"
SUCCEEDED = 'SUCCEEDED'
FAILED = 'FAILED'


class AirbyteConnectionStatus(BaseModel):
Expand All @@ -81,15 +81,17 @@ class AirbyteConnectionStatus(BaseModel):

class AirbyteStream(BaseModel):
name: str = Field(..., description="Stream's name.")
json_schema: Dict[str, Any] = Field(..., description="Stream schema using Json Schema specs.")
json_schema: Dict[str, Any] = Field(
..., description='Stream schema using Json Schema specs.'
)


class ConnectorSpecification(BaseModel):
documentationUrl: Optional[AnyUrl] = None
changelogUrl: Optional[AnyUrl] = None
connectionSpecification: Dict[str, Any] = Field(
...,
description="ConnectorDefinition specific blob. Must be a valid JSON string.",
description='ConnectorDefinition specific blob. Must be a valid JSON string.',
)


Expand All @@ -98,19 +100,21 @@ class AirbyteCatalog(BaseModel):


class AirbyteMessage(BaseModel):
type: Type = Field(..., description="Message type")
type: Type = Field(..., description='Message type')
log: Optional[AirbyteLogMessage] = Field(
None,
description="log message: any kind of logging you want the platform to know about.",
description='log message: any kind of logging you want the platform to know about.',
)
spec: Optional[ConnectorSpecification] = None
connectionStatus: Optional[AirbyteConnectionStatus] = None
catalog: Optional[AirbyteCatalog] = Field(
None,
description="log message: any kind of logging you want the platform to know about.",
description='log message: any kind of logging you want the platform to know about.',
)
record: Optional[AirbyteRecordMessage] = Field(
None, description='record message: the record'
)
record: Optional[AirbyteRecordMessage] = Field(None, description="record message: the record")
state: Optional[AirbyteStateMessage] = Field(
None,
description="schema message: the state. Must be the last message produced. The platform uses this information",
description='schema message: the state. Must be the last message produced. The platform uses this information',
)
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class PythonTestSource extends TestSource {
public static String IMAGE_NAME;
public static String PYTHON_CONTAINER_NAME;

private Path testRoot;

@Override
protected String getImageName() {
return IMAGE_NAME;
Expand All @@ -74,6 +76,7 @@ protected AirbyteCatalog getCatalog() throws IOException {

@Override
protected void setup(TestDestinationEnv testEnv) throws Exception {
testRoot = Files.createTempDirectory(Files.createDirectories(Path.of("/tmp/standard_test")), "pytest");
runExecutableVoid(Command.SETUP);
}

Expand All @@ -90,20 +93,19 @@ private enum Command {
TEARDOWN
}

private static <T> T runExecutable(Command cmd, Class<T> klass) throws IOException {
private <T> T runExecutable(Command cmd, Class<T> klass) throws IOException {
return Jsons.object(runExecutable(cmd), klass);
}

private static JsonNode runExecutable(Command cmd) throws IOException {
private JsonNode runExecutable(Command cmd) throws IOException {
return Jsons.deserialize(IOs.readFile(runExecutableInternal(cmd), OUTPUT_FILENAME));
}

private static void runExecutableVoid(Command cmd) throws IOException {
private void runExecutableVoid(Command cmd) throws IOException {
runExecutableInternal(cmd);
}

private static Path runExecutableInternal(Command cmd) throws IOException {
final Path testRoot = Files.createTempDirectory(Files.createDirectories(Path.of("/tmp/standard_test")), cmd.toString().toLowerCase());
private Path runExecutableInternal(Command cmd) throws IOException {
LOGGER.info("testRoot = " + testRoot);
final List<String> dockerCmd =
Lists.newArrayList(
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ spotless {
}
python {
target '**/*.py'
targetExclude "**/build/**/*", "**/.gradle/**/*", "**/.venv/**/*"
targetExclude "**/build/**/*", "**/.gradle/**/*", "**/.venv/**/*", "**/.eggs/**/*"
licenseHeaderFile createPythonLicenseWith(rootProject.file('LICENSE')), '(from|import|# generated)'
}
format 'styling', {
Expand Down

0 comments on commit 7ba6830

Please sign in to comment.