Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/devshawn/kafka/gitops/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public DesiredStateFile getAndValidateStateFile() {

public DesiredPlan plan() {
DesiredPlan desiredPlan = generatePlan();
planManager.validatePlanHasChanges(desiredPlan, managerConfig.isDeleteDisabled());
planManager.writePlanToFile(desiredPlan);
planManager.validatePlanHasChanges(desiredPlan, managerConfig.isDeleteDisabled());
return desiredPlan;
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/devshawn/kafka/gitops/cli/ApplyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.devshawn.kafka.gitops.domain.plan.DesiredPlan;
import com.devshawn.kafka.gitops.exception.KafkaExecutionException;
import com.devshawn.kafka.gitops.exception.MissingConfigurationException;
import com.devshawn.kafka.gitops.exception.PlanIsUpToDateException;
import com.devshawn.kafka.gitops.exception.ReadPlanInputException;
import com.devshawn.kafka.gitops.exception.ValidationException;
import com.devshawn.kafka.gitops.service.ParserService;
Expand Down Expand Up @@ -35,6 +36,9 @@ public Integer call() {
DesiredPlan desiredPlan = stateManager.apply();
LogUtil.printApplyOverview(PlanUtil.getOverview(desiredPlan, parent.isDeleteDisabled()));
return 0;
} catch (PlanIsUpToDateException ex) {
LogUtil.printNoChangesMessage();
return 0;
} catch (MissingConfigurationException | ReadPlanInputException ex) {
LogUtil.printGenericError(ex, true);
} catch (ValidationException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class ApplyCommandIntegrationSpec extends Specification {
"seed-topic-modification-3" | true
"seed-topic-modification-3" | false
"seed-acl-exists" | false
"no-changes" | false
}

void 'test reading missing file throws ReadPlanInputException'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,25 @@ class PlanCommandIntegrationSpec extends Specification {
ByteArrayOutputStream out = new ByteArrayOutputStream()
PrintStream oldOut = System.out
System.setOut(new PrintStream(out))
String planOutputFile = "/tmp/plan.json"
String file = TestUtils.getResourceFilePath("plans/${planName}.yaml")
MainCommand mainCommand = new MainCommand()
CommandLine cmd = new CommandLine(mainCommand)

when:
int exitCode = cmd.execute("-f", file, "plan")
int exitCode = cmd.execute("-f", file, "plan", "-o", planOutputFile)

then:
exitCode == 0
out.toString() == TestUtils.getResourceFileContent("plans/no-changes-output.txt")

when:
String actualPlan = TestUtils.getFileContent(planOutputFile)
String expectedPlan = TestUtils.getResourceFileContent("plans/${planName}-plan.json")

then:
JSONAssert.assertEquals(expectedPlan, actualPlan, true)

cleanup:
System.setOut(oldOut)

Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/plans/no-changes-apply-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Executing apply...

[SUCCESS] There are no necessary changes; the actual state matches the desired state.
81 changes: 81 additions & 0 deletions src/test/resources/plans/no-changes-plan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"topicPlans": [
{
"name": "delete-topic",
"action": "NO_CHANGE",
"topicDetails": {
"partitions": 1,
"replication": 1,
"configs": {}
},
"topicConfigPlans": []
},
{
"name": "test-topic",
"action": "NO_CHANGE",
"topicDetails": {
"partitions": 1,
"replication": 1,
"configs": {}
},
"topicConfigPlans": []
},
{
"name": "topic-with-configs-1",
"action": "NO_CHANGE",
"topicDetails": {
"partitions": 3,
"replication": 1,
"configs": {
"cleanup.policy": "compact",
"segment.bytes": "100000"
}
},
"topicConfigPlans": [
{
"key": "cleanup.policy",
"value": "compact",
"action": "NO_CHANGE"
},
{
"key": "segment.bytes",
"value": "100000",
"action": "NO_CHANGE"
}
]
},
{
"name": "topic-with-configs-2",
"action": "NO_CHANGE",
"topicDetails": {
"partitions": 6,
"replication": 1,
"configs": {
"retention.ms": "60000"
}
},
"topicConfigPlans": [
{
"key": "retention.ms",
"value": "60000",
"action": "NO_CHANGE"
}
]
}
],
"aclPlans": [
{
"name": "test-service-0",
"aclDetails": {
"name": "test-topic",
"type": "TOPIC",
"pattern": "LITERAL",
"principal": "User:test",
"host": "*",
"operation": "READ",
"permission": "ALLOW"
},
"action": "NO_CHANGE"
}
]
}