Skip to content

Commit

Permalink
feat #143 MongoDriver.listExecutedScripts() modification + test
Browse files Browse the repository at this point in the history
  • Loading branch information
asolovieff committed Sep 21, 2021
1 parent e619abe commit 775d6e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package datamaintain.db.driver.mongo

import datamaintain.core.db.driver.DatamaintainDriver
import datamaintain.core.exception.DatamaintainMongoQueryException
import datamaintain.core.script.ExecutedScript
import datamaintain.core.script.ExecutionStatus
import datamaintain.core.script.FileScript
import datamaintain.core.script.ScriptWithContent
import datamaintain.core.script.*
import datamaintain.core.step.executor.Execution
import datamaintain.core.util.runProcess
import datamaintain.db.driver.mongo.serialization.KJsonParser
Expand Down Expand Up @@ -80,9 +77,9 @@ class MongoDriver(mongoUri: String,
return null
}

override fun listExecutedScripts(): Sequence<ExecutedScript> {
val executionOutput: String = executeMongoQuery("db.$EXECUTED_SCRIPTS_COLLECTION.find().toArray()")
return if (executionOutput.isNotBlank()) jsonParser.parseArrayOfExecutedScripts(executionOutput) else emptySequence()
override fun listExecutedScripts(): Sequence<LightExecutedScript> {
val executionOutput: String = executeMongoQuery("db.$EXECUTED_SCRIPTS_COLLECTION.find({}, { \"name\": 1, \"checksum\": 1, \"identifier\": 1}).toArray()")
return if (executionOutput.isNotBlank()) jsonParser.parseArrayOfLightExecutedScripts(executionOutput) else emptySequence()
}

override fun markAsExecuted(executedScript: ExecutedScript): ExecutedScript {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package datamaintain.db.driver.mongo

import com.mongodb.client.model.Filters
import datamaintain.core.script.ExecutedScript
import datamaintain.core.script.ExecutionStatus
import datamaintain.core.script.FileScript
import datamaintain.core.script.ScriptAction
import datamaintain.core.script.*
import datamaintain.db.driver.mongo.serialization.ExecutedScriptDb
import datamaintain.db.driver.mongo.serialization.toExecutedScriptDb
import datamaintain.db.driver.mongo.test.AbstractMongoDbTest
Expand Down Expand Up @@ -36,7 +33,7 @@ internal class MongoDriverTest : AbstractMongoDbTest() {
// Then
expectThat(executedScripts.toList()) {
size.isEqualTo(2)
contains(script1, script2)
contains(lightExecutedScript1, lightExecutedScript2)
}
}

Expand Down Expand Up @@ -363,5 +360,17 @@ internal class MongoDriverTest : AbstractMongoDbTest() {
ExecutionStatus.OK,
ScriptAction.RUN
)

private val lightExecutedScript1 = LightExecutedScript(
script1.name,
script1.checksum,
script1.identifier
)

private val lightExecutedScript2 = LightExecutedScript(
script2.name,
script2.checksum,
script2.identifier
)
}

0 comments on commit 775d6e6

Please sign in to comment.