1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/test/groovy/util/CommandLineMatcher.groovy
Daniel Kurzynski 6e26d78047
Improve neo deploy (#440)
The following features were added:
Lock resources for deployment
New parameters: environment, vmArguments
Assert password does not start with @
Link to cloud cockpit
Only execute rolling update if app is running
Show logs if deployment failed
Restart app after normal deployment
Use neo namespace for parameters
Align parameter names with neo sdk: size, application, source
Remove vmSize check as done by the tool itself
2019-01-28 11:32:24 +01:00

78 lines
1.8 KiB
Groovy

package util
import org.hamcrest.BaseMatcher
import org.hamcrest.Description
class CommandLineMatcher extends BaseMatcher {
String prolog
Set<String> args = (Set) []
Set<MapEntry> opts = (Set) []
String hint = ''
CommandLineMatcher hasProlog(prolog) {
this.prolog = prolog
return this
}
CommandLineMatcher hasDoubleQuotedOption(String key, String value) {
hasOption(key, "\"${value}\"")
return this
}
CommandLineMatcher hasSingleQuotedOption(String key, String value) {
hasOption(key, "\'${value}\'")
return this
}
CommandLineMatcher hasOption(String key, String value) {
this.opts.add(new MapEntry(key, value))
return this
}
CommandLineMatcher hasArgument(String arg) {
this.args.add(arg)
return this
}
@Override
boolean matches(Object o) {
for (String cmd : o) {
hint = ''
boolean matches = true
if (!cmd.matches(/${prolog}.*/)) {
hint = "A command line starting with \'${prolog}\'."
matches = false
}
for (MapEntry opt : opts) {
if (!cmd.matches(/.*[\s]*--${opt.key}[\s]*${opt.value}.*/)) {
hint = "A command line containing option \'${opt.key}\' with value \'${opt.value}\'"
matches = false
}
}
for (String arg : args) {
if (!cmd.matches(/.*[\s]*${arg}[\s]*.*/)) {
hint = "A command line having argument '${arg}'."
matches = false
}
}
if (matches)
return true
}
return false
}
@Override
public void describeTo(Description description) {
description.appendText(hint)
}
}