-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
LiquibaseCommandLineTest.groovy
95 lines (78 loc) · 6.28 KB
/
LiquibaseCommandLineTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package liquibase.integration.commandline
import liquibase.command.CommandBuilder
import liquibase.configuration.ConfigurationDefinition
import liquibase.logging.LogMessageFilter
import spock.lang.Specification
import spock.lang.Unroll
import java.util.logging.LogRecord
class LiquibaseCommandLineTest extends Specification {
@Unroll
def "toArgNames for command arguments"() {
expect:
LiquibaseCommandLine.toArgNames(new CommandBuilder(["argTest"] as String[][]).argument(argName, String).build()).join(", ") == expected
where:
argName | expected
"test" | "--test"
"twoWords" | "--two-words, --twoWords"
"threeWordsHere" | "--three-words-here, --threeWordsHere"
}
@Unroll
def "toArgNames for configuration arguments"() {
expect:
LiquibaseCommandLine.toArgNames(new ConfigurationDefinition.Builder(prefix).define(argName, String).buildTemporary()).join(", ") == expected
where:
prefix | argName | expected
"liquibase" | "test" | "--test, --liquibase-test, --liquibasetest"
"liquibase" | "twoWords" | "--two-words, --liquibase-two-words, --twoWords, --liquibasetwoWords"
"liquibase" | "threeWordsHere" | "--three-words-here, --liquibase-three-words-here, --threeWordsHere, --liquibasethreeWordsHere"
"liquibase.pro" | "test" | "--pro-test, --liquibase-pro-test, --protest, --liquibaseprotest"
"other" | "twoWords" | "--other-two-words, --othertwoWords"
}
@Unroll
def "toArgNames for configuration arguments and aliases"() {
expect:
LiquibaseCommandLine.toArgNames(new ConfigurationDefinition.Builder(prefix).define(argName, String).addAliasKey(alias).buildTemporary()).join(", ") == expected
where:
prefix | argName | alias | expected
"liquibase" | "test" | "testAlias" | "--test, --liquibase-test, --liquibasetest, --test-alias, --testAlias"
}
@Unroll
def "adjustLegacyArgs"() {
expect:
new LiquibaseCommandLine().adjustLegacyArgs(input as String[]).toArrayString() == (expected as String[]).toArrayString()
where:
input | expected
["--arg", "update", "--help"] | ["--arg", "update", "--help"]
["tag", "--help"] | ["tag", "--help"]
["tag", "my-tag"] | ["tag", "--tag", "my-tag"]
["rollback", "my-tag"] | ["rollback", "--tag", "my-tag"]
["rollbackToDate", "1/2/3"] | ["rollbackToDate", "--date", "1/2/3"]
["rollback-to-date", "1/2/3"] | ["rollback-to-date", "--date", "1/2/3"]
["rollback-to-date", "1/2/3", "3:15:21"] | ["rollback-to-date", "--date", "1/2/3 3:15:21"]
["rollback-count", "5"] | ["rollback-count", "--count", "5"]
["future-rollback-count-sql", "5"] | ["future-rollback-count-sql", "--count", "5"]
["future-rollback-from-tag-sql", "my-tag"] | ["future-rollback-from-tag-sql", "--tag", "my-tag"]
["--log-level", "DEBUG", "--log-file", "06V21.txt", "--defaultsFile=liquibase.h2-mem.properties", "update", "--changelog-file", "postgres_lbpro_master_changelog.xml", "--labels", "setup"] | ["--log-level", "DEBUG", "--log-file", "06V21.txt", "--defaultsFile=liquibase.h2-mem.properties", "update", "--changelog-file", "postgres_lbpro_master_changelog.xml", "--labels", "setup"]
}
def "accepts -D subcommand arguments for changelog parameters"() {
when:
def subcommands = new LiquibaseCommandLine().commandLine.getSubcommands()
then:
subcommands["update"].commandSpec.findOption("-D") != null
subcommands["snapshot"].commandSpec.findOption("-D") == null
}
@Unroll
def "cleanExceptionMessage"() {
expect:
new LiquibaseCommandLine().cleanExceptionMessage(input) == expected
where:
input | expected
null | null
"" | ""
"random string" | "random string"
"Unexpected error running Liquibase: message here" | "message here"
"java.lang.RuntimeException: message here" | "message here"
"java.lang.ParseError: message here" | "message here"
"java.io.RuntimeException: java.lang.RuntimeException: message here" | "message here"
}
}