Skip to content

Commit

Permalink
Fix DeployInstanceConfigurationIT
Browse files Browse the repository at this point in the history
  • Loading branch information
patchwork01 committed Nov 1, 2024
1 parent d88f8ff commit cebe608
Showing 1 changed file with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@

public class DeployInstanceConfigurationIT {
@TempDir
private Path tempDir;
private Path templatesDir;
@TempDir
private Path propertiesDir;

@Nested
@DisplayName("Load from template directory")
class LoadFromTemplateDirectory {
@Test
void shouldLoadInstancePropertiesWithNoTables() throws Exception {
// Given
createTemplatesInDirectory(tempDir);
writeTemplates();

// When
DeployInstanceConfiguration instanceConfiguration = DeployInstanceConfigurationFromTemplates.builder()
.templatesDir(tempDir).build().load();
DeployInstanceConfiguration instanceConfiguration = fromTemplatesDir();

// Then
InstanceProperties expectedInstanceProperties = new InstanceProperties();
Expand All @@ -70,15 +71,14 @@ class LoadFromInstanceProperties {
@Test
void shouldLoadTablePropertiesAndSchemaIfFoundNearInstanceProperties() throws Exception {
// Given
Path templateDir = createTemplatesInDirectory(tempDir.resolve("templates"));
Files.writeString(tempDir.resolve("instance.properties"), "sleeper.id=test-instance");
Files.writeString(tempDir.resolve("tags.properties"), "Project=TestProject");
Files.writeString(tempDir.resolve("table.properties"), "sleeper.table.name=test-table");
Files.writeString(tempDir.resolve("schema.json"), new SchemaSerDe().toJson(schemaWithKey("key")));
Files.writeString(propertiesDir.resolve("instance.properties"), "sleeper.id=test-instance");
Files.writeString(propertiesDir.resolve("tags.properties"), "Project=TestProject");
Files.writeString(propertiesDir.resolve("table.properties"), "sleeper.table.name=test-table");
Files.writeString(propertiesDir.resolve("schema.json"), new SchemaSerDe().toJson(schemaWithKey("key")));

// When
DeployInstanceConfiguration instanceConfiguration = fromInstancePropertiesOrTemplatesDir(
tempDir.resolve("instance.properties"), templateDir);
propertiesDir.resolve("instance.properties"));

// Then
InstanceProperties expectedInstanceProperties = new InstanceProperties();
Expand All @@ -97,19 +97,15 @@ void shouldLoadTablePropertiesAndSchemaIfFoundNearInstanceProperties() throws Ex
@Test
void shouldLoadNoTablesIfNotFoundNearInstanceProperties() throws Exception {
// Given
Path templateDir = createTemplatesInDirectory(tempDir.resolve("templates"));
Files.writeString(tempDir.resolve("instance.properties"), "sleeper.id=test-instance");
Files.writeString(propertiesDir.resolve("instance.properties"), "sleeper.id=test-instance");

// When
DeployInstanceConfiguration instanceConfiguration = DeployInstanceConfigurationFromTemplates.builder()
.instancePropertiesPath(tempDir.resolve("instance.properties"))
.templatesDir(templateDir)
.build().load();
DeployInstanceConfiguration instanceConfiguration = fromInstancePropertiesOrTemplatesDir(
propertiesDir.resolve("instance.properties"));

// Then
InstanceProperties expectedInstanceProperties = new InstanceProperties();
expectedInstanceProperties.set(ID, "test-instance");
expectedInstanceProperties.setTags(Map.of("Project", "TemplateProject"));
assertThat(instanceConfiguration)
.isEqualTo(DeployInstanceConfiguration.builder()
.instanceProperties(expectedInstanceProperties)
Expand All @@ -118,17 +114,22 @@ void shouldLoadNoTablesIfNotFoundNearInstanceProperties() throws Exception {
}
}

private static Path createTemplatesInDirectory(Path templatesDir) throws IOException {
private void writeTemplates() throws IOException {
Files.createDirectories(templatesDir);
Files.writeString(templatesDir.resolve("instanceproperties.template"), "sleeper.id=template-instance");
Files.writeString(templatesDir.resolve("tags.template"), "Project=TemplateProject");
return templatesDir;
}

private DeployInstanceConfiguration fromInstancePropertiesOrTemplatesDir(Path instancePropertiesFile, Path templateDir) {
private DeployInstanceConfiguration fromInstancePropertiesOrTemplatesDir(Path instancePropertiesFile) {
return DeployInstanceConfigurationFromTemplates.builder()
.instancePropertiesPath(instancePropertiesFile)
.templatesDir(templateDir)
.templatesDir(templatesDir)
.build().load();
}

private DeployInstanceConfiguration fromTemplatesDir() {
return DeployInstanceConfigurationFromTemplates.builder()
.templatesDir(templatesDir)
.build().load();
}
}

0 comments on commit cebe608

Please sign in to comment.