-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
generateChangelog.test.groovy
151 lines (145 loc) · 5.57 KB
/
generateChangelog.test.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package liquibase.extension.testing.command
import liquibase.change.ColumnConfig
import liquibase.change.core.CreateTableChange
import liquibase.change.core.TagDatabaseChange
import liquibase.exception.CommandValidationException
import liquibase.extension.testing.setup.SetupCleanResources
CommandTests.define {
command = ["generateChangelog"]
signature = """
Short Description: Generate a changelog
Long Description: Writes Change Log XML to copy the current state of the database to standard out or a file
Required Args:
changelogFile (String) File to write changelog to
url (String) The JDBC database connection URL
OBFUSCATED
Optional Args:
dataOutputDirectory (String) Directory to write table data to
Default: null
diffTypes (String) Types of objects to compare
Default: null
driver (String) The JDBC driver class
Default: null
driverPropertiesFile (String) The JDBC driver properties file
Default: null
excludeObjects (String) Objects to exclude from diff
Default: null
includeCatalog (Boolean) If true, the catalog will be included in generated changeSets
Default: false
includeObjects (String) Objects to include in diff
Default: null
includeSchema (Boolean) If true, the schema will be included in generated changeSets
Default: false
includeTablespace (String) Include the tablespace attribute in the changelog
Default: null
overwriteOutputFile (String) Flag to allow overwriting of output changelog file
Default: null
password (String) Password to use to connect to the database
Default: null
OBFUSCATED
schemas (String) Schemas to include in diff
Default: null
username (String) Username to use to connect to the database
Default: null
"""
run "Happy path", {
arguments = [
url : { it.url },
username: { it.username },
password: { it.password },
changelogFile: "target/test-classes/changelog-test.xml"
]
setup {
cleanResources(SetupCleanResources.CleanupMode.CLEAN_ON_SETUP, "changelog-test.xml")
database = [
new CreateTableChange(
tableName: "FirstTable",
columns: [
ColumnConfig.fromName("FirstColumn")
.setType("VARCHAR(255)")
]
),
new CreateTableChange(
tableName: "SecondTable",
columns: [
ColumnConfig.fromName("SecondColumn")
.setType("VARCHAR(255)")
]
),
new TagDatabaseChange(
tag: "version_2.0"
),
new CreateTableChange(
tableName: "liquibaseRunInfo",
columns: [
ColumnConfig.fromName("timesRan")
.setType("INT")
]
),
]
}
expectedFileContent = [
"target/test-classes/changelog-test.xml" : [CommandTests.assertContains("<changeSet ", 3)]
]
expectedResults = [
statusCode : 0
]
}
run "Filtering with includeObjects", {
arguments = [
url : { it.url },
username: { it.username },
password: { it.password },
changelogFile: "target/test-classes/changelog-test.xml",
includeObjects: "table:FIRSTTABLE"
]
setup {
cleanResources(SetupCleanResources.CleanupMode.CLEAN_ON_SETUP, "changelog-test.xml")
database = [
new CreateTableChange(
tableName: "FirstTable",
columns: [
ColumnConfig.fromName("FirstColumn")
.setType("VARCHAR(255)")
]
),
new CreateTableChange(
tableName: "SecondTable",
columns: [
ColumnConfig.fromName("SecondColumn")
.setType("VARCHAR(255)")
]
),
new TagDatabaseChange(
tag: "version_2.0"
),
new CreateTableChange(
tableName: "liquibaseRunInfo",
columns: [
ColumnConfig.fromName("timesRan")
.setType("INT")
]
),
]
}
expectedFileContent = [
"target/test-classes/changelog-test.xml" : [CommandTests.assertContains("<changeSet ", 1)]
]
expectedResults = [
statusCode : 0
]
}
run "Run without changelogFile throws exception", {
arguments = [
changelogFile: ""
]
expectedException = CommandValidationException.class
}
run "Run without URL throws exception", {
arguments = [
url: "",
changelogFile: "target/test-classes/changeLog-test.xml"
]
expectedException = CommandValidationException.class
}
}