Skip to content

Commit

Permalink
support setting searchPath in CommandTests (DAT-11055) (#3129)
Browse files Browse the repository at this point in the history
Support setting searchPath in a command test definition.
  • Loading branch information
StevenMassaro committed Jul 29, 2022
1 parent 24102a9 commit abcd08f
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package liquibase.extension.testing.command

import liquibase.AbstractExtensibleObject
import liquibase.CatalogAndSchema
import liquibase.GlobalConfiguration
import liquibase.Scope
import liquibase.change.Change
import liquibase.changelog.ChangeLogHistoryService
Expand Down Expand Up @@ -31,6 +32,7 @@ import liquibase.logging.core.BufferedLogService
import liquibase.resource.ClassLoaderResourceAccessor
import liquibase.resource.InputStreamList
import liquibase.resource.ResourceAccessor
import liquibase.resource.SearchPathResourceAccessor
import liquibase.ui.ConsoleUIService
import liquibase.ui.InputHandler
import liquibase.ui.UIService
Expand Down Expand Up @@ -276,11 +278,37 @@ Long Description: ${commandDefinition.getLongDescription() ?: "NOT SET"}
}
}

def resourceAccessor = Scope.getCurrentScope().getResourceAccessor()

if (testDef.searchPath != null) {
def config = Scope.getCurrentScope().getSingleton(LiquibaseConfiguration.class)

ConfigurationValueProvider propertiesProvider = new AbstractMapConfigurationValueProvider() {
@Override
protected Map<?, ?> getMap() {
return Collections.singletonMap(GlobalConfiguration.SEARCH_PATH.getKey(), testDef.searchPath)
}

@Override
protected String getSourceDescription() {
return "command tests search path override"
}

@Override
int getPrecedence() {
return 1
}
}

config.registerProvider(propertiesProvider)
resourceAccessor = new SearchPathResourceAccessor(Scope.getCurrentScope().getResourceAccessor())
}

def scopeSettings = [
(LiquibaseCommandLineConfiguration.LOG_LEVEL.getKey()): Level.INFO,
("liquibase.plugin." + HubService.name) : MockHubService,
(Scope.Attr.resourceAccessor.name()) : testDef.resourceAccessor ?
testDef.resourceAccessor : Scope.getCurrentScope().getResourceAccessor(),
testDef.resourceAccessor : resourceAccessor,
(Scope.Attr.ui.name()) : testDef.testUI ? testDef.testUI.initialize(uiOutputWriter, uiErrorWriter) :
new TestUI(uiOutputWriter, uiErrorWriter),
(Scope.Attr.logService.name()) : logService
Expand Down Expand Up @@ -751,6 +779,8 @@ Long Description: ${commandDefinition.getLongDescription() ?: "NOT SET"}

private Map<String, ?> globalArguments = new HashMap<>()

private String searchPath

/**
* Arguments to command as key/value pairs
*/
Expand Down Expand Up @@ -820,6 +850,10 @@ Long Description: ${commandDefinition.getLongDescription() ?: "NOT SET"}
this.globalArguments = args
}

def setSearchPath(String searchPath) {
this.searchPath = searchPath
}

def setExpectedFileContent(Map<String, Object> content) {
this.expectedFileContent = content
}
Expand Down

0 comments on commit abcd08f

Please sign in to comment.