Skip to content

Commit

Permalink
#428 Better error message when roles have circular dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrudin committed May 28, 2021
1 parent 26bc350 commit 5e05d6a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ else if (index > -1) {
}
}

String[] sortedRoleNames = sorter.sort();
String[] sortedRoleNames;
try {
sortedRoleNames = sorter.sort();
} catch (IllegalStateException ex) {
throw new IllegalArgumentException("Unable to deploy roles due to circular dependencies " +
"between two or more roles; please remove these circular dependencies in order to deploy" +
" your roles");
}

roles = new ArrayList<>();
for (String name : sortedRoleNames) {
roles.add(map.get(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.io.File;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

/**
* Each of these tests verifies that the roles in the given config dir can be deployed successfully based on their
Expand Down Expand Up @@ -73,6 +73,22 @@ public void anotherSortingTest() {
}
}

@Test
void circularDependencies() {
appConfig.getFirstConfigDir().setBaseDir(new File("src/test/resources/sample-app/roles-with-circular-dependencies"));
initializeAppDeployer(new DeployRolesCommand());
try {
deploySampleApp();
fail("Expected an error due to a circular dependency between the two roles");
} catch (IllegalArgumentException ex) {
assertEquals("Unable to deploy roles due to circular dependencies between two or more roles; " +
"please remove these circular dependencies in order to deploy your roles",
ex.getMessage());
} finally {
undeploySampleApp();
}
}

@Test
public void test() {
appConfig.getFirstConfigDir().setBaseDir(new File("src/test/resources/sample-app/roles-with-dependencies"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"role-name": "sample-app-role0",
"role": [
"sample-app-role1"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"role-name": "sample-app-role1",
"role": [
"sample-app-role0"
]
}

0 comments on commit 5e05d6a

Please sign in to comment.