Skip to content

Commit

Permalink
Fix #127 - Fix filters applying actions despite criteria not matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry Lacour committed Mar 28, 2019
1 parent a8ee216 commit 3e22a51
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build/
gradle-app.setting
!gradle-wrapper.jar
/.nb-gradle/
output/

bin/
.project
Expand Down
9 changes: 4 additions & 5 deletions src/main/groovy/togit/ScriptBase.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,12 @@ abstract class ScriptBase extends Script implements Context {
* Closure containing DSL methods used for the migration
* @param closure The DSL code
*/
static void migrate(boolean dryRun = false, @DslContext(MigrationContext) Closure closure) {
static void migrate(boolean skipExecution = false, boolean skipReset = false, @DslContext(MigrationContext) Closure closure) {
executeInContext(closure, new MigrationContext())
MigrationManager.instance.migrate(dryRun)
MigrationManager.instance.migrate(skipExecution)
LOG.info(migrationComplete())
if (!dryRun) {
MigrationManager.instance.resetMigrationPlan()
}
if (skipReset) { return }
MigrationManager.instance.resetMigrationPlan()
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/groovy/togit/migration/MigrationManager.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ class MigrationManager {
plan = new MigrationPlan()
}

void migrate(boolean dryRun = false) {
if (dryRun) {
void migrate(boolean skipExecution = false) {
if (skipExecution) {
LOG.info('Skipping execution')
plan.plan()
return
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/groovy/togit/migration/plan/Snapshot.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ abstract class Snapshot {
* @return true if the Snapshot matches all Criteria, otherwise false
*/
boolean matches(List<Criteria> criteria, List<Snapshot> allSnapshots) {
for (def crit : criteria) {
for (Criteria crit : criteria) {
if (!crit.appliesTo(this, allSnapshots)) {
false
return false
}
}
true
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ActionsContextTest {
$/
source('dummy')
target('dummy')
migrate(true) {
migrate(true, true) {
filters {
filter {
actions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CriteriaContextTest {
$/
source('dummy')
target('dummy')
migrate(true) {
migrate(true, true) {
filters {
filter {
criteria {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ExtractionsContextTest {
$/
source('dummy')
target('dummy')
migrate(true) {
migrate(true, true) {
filters {
filter {
extractions {
Expand Down
42 changes: 42 additions & 0 deletions src/test/groovy/toGit/context/dummy/GHI127.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package togit.context.dummy

import org.junit.Test
import togit.Executor
import togit.TestHelper
import togit.migration.MigrationManager
import togit.migration.sources.dummy.DummySource
import togit.migration.targets.dummy.DummyTarget

/* Filters would apply actions to Snapshots that didnt meet criteria. */
class GHI127 {

private static void runTest() {
new Executor().execute(TestHelper.tempCommandFile(testScript()).absolutePath)
}

static String testScript() {
"""\
source('dummy')
target('dummy')
migrate(false, true) {
filters {
filter {
criteria {
custom { current, all -> current.identifier == "foo" }
}
actions {
custom { println "blip" }
}
}
}
}""".stripIndent()
}

@Test
void onlyAppliesToMatchingActions() {
runTest()
MigrationManager manager = MigrationManager.instance
assert manager.plan.steps.size() == 1
assert manager.plan.steps.foo.actions.size() == 1
}
}

0 comments on commit 3e22a51

Please sign in to comment.