@@ -62,7 +62,7 @@ function Test-Port([string]$ContainerName, [int]$Port) {
62
62
63
63
# Asserts that InputValue contains at least one occurence of Pattern.
64
64
# If -ReturnMatchPosition is informed, return the match value for that pattern position.
65
- function Contains ([Parameter (ValueFromPipeline )]$InputValue , [string []]$Pattern , [int ]$ReturnMatchPosition ) {
65
+ function Contains ([Parameter (ValueFromPipeline )]$InputValue , [string []]$Pattern , [int ]$ReturnMatchPosition , [ string ] $ErrorMessage ) {
66
66
process {
67
67
if ($hasMatch ) { return ; }
68
68
$_matches = $InputValue | Select-String - Pattern $Pattern
@@ -74,37 +74,49 @@ function Contains([Parameter(ValueFromPipeline)]$InputValue, [string[]]$Pattern,
74
74
}
75
75
76
76
end {
77
- assert $hasMatch
77
+ if ([string ]::IsNullOrEmpty($ErrorMessage )) {
78
+ $ErrorMessage = " InputValue does not contain the specified Pattern."
79
+ }
80
+ assert $hasMatch $ErrorMessage
78
81
return $result
79
82
}
80
83
}
81
84
82
85
# Asserts that InputValue contains exactly ExpectedCount occurences of Pattern.
83
- function ContainsExactly ([Parameter (ValueFromPipeline )]$InputValue , [string []]$Pattern , [int ]$ExpectedCount ) {
86
+ function ContainsExactly ([Parameter (ValueFromPipeline )]$InputValue , [string []]$Pattern , [int ]$ExpectedCount , [ string ] $ErrorMessage ) {
84
87
process {
85
88
$_matches = $InputValue | Select-String - Pattern $Pattern
86
89
$totalMatches += $_matches.Count
87
90
}
88
91
89
92
end {
90
- assert ($totalMatches -eq $ExpectedCount )
93
+ if ([string ]::IsNullOrEmpty($ErrorMessage )) {
94
+ $ErrorMessage = " InputValue does not contain exactly $ExpectedCount occurrences of Pattern."
95
+ }
96
+ assert ($totalMatches -eq $ExpectedCount ) $ErrorMessage
91
97
}
92
98
}
93
99
94
100
# Asserts that LastExitCode is equal to ExpectedValue.
95
- function ExitCodeIs ([Parameter (ValueFromPipeline )]$InputValue , [int ]$ExpectedValue ) {
101
+ function ExitCodeIs ([Parameter (ValueFromPipeline )]$InputValue , [int ]$ExpectedValue , [ string ] $ErrorMessage ) {
96
102
process { }
97
103
end {
98
- assert ($LastExitCode -eq $ExpectedValue )
104
+ if ([string ]::IsNullOrEmpty($ErrorMessage )) {
105
+ $ErrorMessage = " ExitCode = $InputValue , expected = $ExpectedValue ."
106
+ }
107
+ assert ($LastExitCode -eq $ExpectedValue ) $ErrorMessage
99
108
}
100
109
}
101
110
102
111
# Asserts that the difference between two DateTime values are under a given tolerance.
103
- function IsAdjacent ([Parameter (ValueFromPipeline )][datetime ]$InputValue , [datetime ]$ExpectedValue , [timespan ]$Tolerance = [timespan ]::FromSeconds(2 ) ) {
112
+ function IsAdjacent ([Parameter (ValueFromPipeline )][datetime ]$InputValue , [datetime ]$ExpectedValue , [timespan ]$Tolerance = [timespan ]::FromSeconds(1 ) , [ string ] $ErrorMessage ) {
104
113
process { }
105
114
end {
106
115
$difference = $InputValue - $ExpectedValue
107
- assert ($difference.Duration () -lt $Tolerance )
116
+ if ([string ]::IsNullOrEmpty($ErrorMessage )) {
117
+ $ErrorMessage = " The difference between $InputValue and $ExpectedValue is larger than the expected tolerance ($Tolerance )."
118
+ }
119
+ assert ($difference.Duration () -lt $Tolerance ) $ErrorMessage
108
120
}
109
121
}
110
122
@@ -122,7 +134,7 @@ function New-TemporaryDirectory {
122
134
123
135
task With_command_should_not_start_Firebird {
124
136
Invoke-Container - ImageParameters ' ps' , ' -A' |
125
- ContainsExactly - Pattern ' firebird|fbguard' - ExpectedCount 0
137
+ ContainsExactly - Pattern ' firebird|fbguard' - ExpectedCount 0 - ErrorMessage " Firebird processes should not be running when a command is specified. "
126
138
}
127
139
128
140
task Without_command_should_start_Firebird {
@@ -131,18 +143,18 @@ task Without_command_should_start_Firebird {
131
143
132
144
# Both firebird and fbguard must be running
133
145
docker exec $cId ps - A |
134
- ContainsExactly - Pattern ' firebird|fbguard' - ExpectedCount 2
146
+ ContainsExactly - Pattern ' firebird|fbguard' - ExpectedCount 2 - ErrorMessage " Expected 'firebird' and 'fbguard' processes to be running. "
135
147
136
148
# "Starting" but no "Stopping"
137
149
docker logs $cId |
138
- ContainsExactly - Pattern ' Starting Firebird|Stopping Firebird' - ExpectedCount 1
150
+ ContainsExactly - Pattern ' Starting Firebird|Stopping Firebird' - ExpectedCount 1 - ErrorMessage " Expected 'Starting Firebird' log entry. "
139
151
140
152
# Stop
141
153
docker stop $cId > $null
142
154
143
155
# "Starting" and "Stopping"
144
156
docker logs $cId |
145
- ContainsExactly - Pattern ' Starting Firebird|Stopping Firebird' - ExpectedCount 2
157
+ ContainsExactly - Pattern ' Starting Firebird|Stopping Firebird' - ExpectedCount 2 - ErrorMessage " Expected both 'Starting Firebird' and 'Stopping Firebird' log entries after container stop. "
146
158
}
147
159
}
148
160
@@ -151,10 +163,10 @@ task FIREBIRD_DATABASE_can_create_database {
151
163
param ($cId )
152
164
153
165
docker exec $cId test -f / var / lib/ firebird/ data / test.fdb |
154
- ExitCodeIs - ExpectedValue 0
166
+ ExitCodeIs - ExpectedValue 0 - ErrorMessage " Expected database file '/var/lib/firebird/data/test.fdb' to exist. "
155
167
156
168
docker logs $cId |
157
- Contains - Pattern " Creating database '/var/lib/firebird/data/test.fdb'"
169
+ Contains - Pattern " Creating database '/var/lib/firebird/data/test.fdb'" - ErrorMessage " Expected log message indicating creation of database '/var/lib/firebird/data/test.fdb'. "
158
170
}
159
171
}
160
172
@@ -163,10 +175,10 @@ task FIREBIRD_DATABASE_can_create_database_with_absolute_path {
163
175
param ($cId )
164
176
165
177
docker exec $cId test -f / tmp/ test.fdb |
166
- ExitCodeIs - ExpectedValue 0
178
+ ExitCodeIs - ExpectedValue 0 - ErrorMessage " Expected database file '/tmp/test.fdb' to exist when absolute path is used. "
167
179
168
180
docker logs $cId |
169
- Contains - Pattern " Creating database '/tmp/test.fdb'"
181
+ Contains - Pattern " Creating database '/tmp/test.fdb'" - ErrorMessage " Expected log message indicating creation of database '/tmp/test.fdb' with absolute path. "
170
182
}
171
183
}
172
184
@@ -176,15 +188,15 @@ task FIREBIRD_DATABASE_PAGE_SIZE_can_set_page_size_on_database_creation {
176
188
177
189
' SET LIST ON; SELECT mon$page_size FROM mon$database;' |
178
190
docker exec - i $cId isql - b - q / var / lib/ firebird/ data / test.fdb |
179
- Contains - Pattern ' MON\$PAGE_SIZE(\s+)4096'
191
+ Contains - Pattern ' MON\$PAGE_SIZE(\s+)4096' - ErrorMessage " Expected database page size to be 4096. "
180
192
}
181
193
182
194
Use-Container - Parameters ' -e' , ' FIREBIRD_DATABASE=test.fdb' , ' -e' , ' FIREBIRD_DATABASE_PAGE_SIZE=16384' {
183
195
param ($cId )
184
196
185
197
' SET LIST ON; SELECT mon$page_size FROM mon$database;' |
186
198
docker exec - i $cId isql - b - q / var / lib/ firebird/ data / test.fdb |
187
- Contains - Pattern ' MON\$PAGE_SIZE(\s+)16384'
199
+ Contains - Pattern ' MON\$PAGE_SIZE(\s+)16384' - ErrorMessage " Expected database page size to be 16384. "
188
200
}
189
201
}
190
202
@@ -194,24 +206,24 @@ task FIREBIRD_DATABASE_DEFAULT_CHARSET_can_set_default_charset_on_database_creat
194
206
195
207
' SET LIST ON; SELECT rdb$character_set_name FROM rdb$database;' |
196
208
docker exec - i $cId isql - b - q / var / lib/ firebird/ data / test.fdb |
197
- Contains - Pattern ' RDB\$CHARACTER_SET_NAME(\s+)NONE'
209
+ Contains - Pattern ' RDB\$CHARACTER_SET_NAME(\s+)NONE' - ErrorMessage " Expected default database charset to be NONE. "
198
210
}
199
211
200
212
Use-Container - Parameters ' -e' , ' FIREBIRD_DATABASE=test.fdb' , ' -e' , ' FIREBIRD_DATABASE_DEFAULT_CHARSET=UTF8' {
201
213
param ($cId )
202
214
203
215
' SET LIST ON; SELECT rdb$character_set_name FROM rdb$database;' |
204
216
docker exec - i $cId isql - b - q / var / lib/ firebird/ data / test.fdb |
205
- Contains - Pattern ' RDB\$CHARACTER_SET_NAME(\s+)UTF8'
217
+ Contains - Pattern ' RDB\$CHARACTER_SET_NAME(\s+)UTF8' - ErrorMessage " Expected default database charset to be UTF8. "
206
218
}
207
219
}
208
220
209
221
task FIREBIRD_USER_fails_without_password {
210
222
# Captures both stdout and stderr
211
223
$ ($stdout = Invoke-Container - DockerParameters ' -e' , ' FIREBIRD_USER=alice' ) 2>&1 |
212
- Contains - Pattern ' FIREBIRD_PASSWORD variable is not set.' # stderr
224
+ Contains - Pattern ' FIREBIRD_PASSWORD variable is not set.' - ErrorMessage " Expected error message 'FIREBIRD_PASSWORD variable is not set.' when FIREBIRD_USER is set without FIREBIRD_PASSWORD. " # stderr
213
225
214
- assert ($stdout -eq $null )
226
+ assert ($stdout -eq $null ) " Expected stdout to be null when FIREBIRD_USER is set without FIREBIRD_PASSWORD. "
215
227
}
216
228
217
229
task FIREBIRD_USER_can_create_user {
@@ -224,19 +236,19 @@ task FIREBIRD_USER_can_create_user {
224
236
# Correct password
225
237
' SELECT 1 FROM rdb$database;' |
226
238
docker exec - i $cId isql - b - q - u alice - p bird inet:/// var / lib/ firebird/ data / test.fdb |
227
- ExitCodeIs - ExpectedValue 0
239
+ ExitCodeIs - ExpectedValue 0 - ErrorMessage " Expected successful login with correct password for user 'alice'. "
228
240
229
241
# Incorrect password
230
242
' SELECT 1 FROM rdb$database;' |
231
243
docker exec - i $cId isql - b - q - u alice - p tiger inet:/// var / lib/ firebird/ data / test.fdb 2>&1 |
232
- ExitCodeIs - ExpectedValue 1
244
+ ExitCodeIs - ExpectedValue 1 - ErrorMessage " Expected failed login with incorrect password for user 'alice'. "
233
245
234
246
# File /opt/firebird/SYSDBA.password exists?
235
247
docker exec $cId test -f / opt/ firebird/ SYSDBA.password |
236
- ExitCodeIs - ExpectedValue 0
248
+ ExitCodeIs - ExpectedValue 0 - ErrorMessage " Expected SYSDBA.password file to exist when a new user is created. "
237
249
238
250
docker logs $cId |
239
- Contains - Pattern " Creating user 'alice'"
251
+ Contains - Pattern " Creating user 'alice'" - ErrorMessage " Expected log message indicating creation of user 'alice'. "
240
252
}
241
253
}
242
254
@@ -247,19 +259,19 @@ task FIREBIRD_ROOT_PASSWORD_can_change_sysdba_password {
247
259
# Correct password
248
260
' SELECT 1 FROM rdb$database;' |
249
261
docker exec - i $cId isql - b - q - u SYSDBA - p passw0rd inet:/// var / lib/ firebird/ data / test.fdb |
250
- ExitCodeIs - ExpectedValue 0
262
+ ExitCodeIs - ExpectedValue 0 - ErrorMessage " Expected successful login with new SYSDBA password. "
251
263
252
264
# Incorrect password
253
265
' SELECT 1 FROM rdb$database;' |
254
266
docker exec - i $cId isql - b - q - u SYSDBA - p tiger inet:/// var / lib/ firebird/ data / test.fdb 2>&1 |
255
- ExitCodeIs - ExpectedValue 1
267
+ ExitCodeIs - ExpectedValue 1 - ErrorMessage " Expected failed login with incorrect (old) SYSDBA password. "
256
268
257
269
# File /opt/firebird/SYSDBA.password removed?
258
270
docker exec $cId test -f / opt/ firebird/ SYSDBA.password |
259
- ExitCodeIs - ExpectedValue 1
271
+ ExitCodeIs - ExpectedValue 1 - ErrorMessage " Expected SYSDBA.password file to be removed after changing SYSDBA password. "
260
272
261
273
docker logs $cId |
262
- Contains - Pattern ' Changing SYSDBA password'
274
+ Contains - Pattern ' Changing SYSDBA password' - ErrorMessage " Expected log message indicating SYSDBA password change. "
263
275
}
264
276
}
265
277
@@ -268,10 +280,10 @@ task FIREBIRD_USE_LEGACY_AUTH_enables_legacy_auth {
268
280
param ($cId )
269
281
270
282
$logs = docker logs $cId
271
- $logs | Contains - Pattern " Using Legacy_Auth"
272
- $logs | Contains - Pattern " AuthServer = Legacy_Auth"
273
- $logs | Contains - Pattern " AuthClient = Legacy_Auth"
274
- $logs | Contains - Pattern " WireCrypt = Enabled"
283
+ $logs | Contains - Pattern " Using Legacy_Auth" - ErrorMessage " Expected log message 'Using Legacy_Auth'. "
284
+ $logs | Contains - Pattern " AuthServer = Legacy_Auth" - ErrorMessage " Expected log message 'AuthServer = Legacy_Auth'. "
285
+ $logs | Contains - Pattern " AuthClient = Legacy_Auth" - ErrorMessage " Expected log message 'AuthClient = Legacy_Auth'. "
286
+ $logs | Contains - Pattern " WireCrypt = Enabled" - ErrorMessage " Expected log message 'WireCrypt = Enabled' when Legacy_Auth is used. "
275
287
}
276
288
}
277
289
@@ -280,8 +292,8 @@ task FIREBIRD_CONF_can_change_any_setting {
280
292
param ($cId )
281
293
282
294
$logs = docker logs $cId
283
- $logs | Contains - Pattern " DefaultDbCachePages = 64K"
284
- $logs | Contains - Pattern " FileSystemCacheThreshold = 100M"
295
+ $logs | Contains - Pattern " DefaultDbCachePages = 64K" - ErrorMessage " Expected log message 'DefaultDbCachePages = 64K'. "
296
+ $logs | Contains - Pattern " FileSystemCacheThreshold = 100M" - ErrorMessage " Expected log message 'FileSystemCacheThreshold = 100M'. "
285
297
}
286
298
}
287
299
@@ -290,14 +302,14 @@ task FIREBIRD_CONF_key_is_case_sensitive {
290
302
param ($cId )
291
303
292
304
$logs = docker logs $cId
293
- $logs | Contains - Pattern " WireCrypt = Disabled"
305
+ $logs | Contains - Pattern " WireCrypt = Disabled" - ErrorMessage " Expected log message 'WireCrypt = Disabled' when using correct case. "
294
306
}
295
307
296
308
Use-Container - Parameters ' -e' , ' FIREBIRD_CONF_WIRECRYPT=Disabled' {
297
309
param ($cId )
298
310
299
311
$logs = docker logs $cId
300
- $logs | ContainsExactly - Pattern " WireCrypt = Disabled" - ExpectedCount 0
312
+ $logs | ContainsExactly - Pattern " WireCrypt = Disabled" - ExpectedCount 0 - ErrorMessage " Expected no log message 'WireCrypt = Disabled' when using incorrect case (WIRECRYPT). "
301
313
}
302
314
}
303
315
@@ -326,12 +338,12 @@ task Can_init_db_with_scripts {
326
338
param ($cId )
327
339
328
340
$logs = docker logs $cId
329
- $logs | Contains - Pattern " 10-create-table.sql"
330
- $logs | Contains - Pattern " 20-insert-data.sql"
341
+ $logs | Contains - Pattern " 10-create-table.sql" - ErrorMessage " Expected log message for '10-create-table.sql' execution. "
342
+ $logs | Contains - Pattern " 20-insert-data.sql" - ErrorMessage " Expected log message for '20-insert-data.sql' execution. "
331
343
332
344
' SET LIST ON; SELECT count(*) AS country_count FROM country;' |
333
345
docker exec - i $cId isql - b - q / var / lib/ firebird/ data / test.fdb |
334
- Contains - Pattern ' COUNTRY_COUNT(\s+)5'
346
+ Contains - Pattern ' COUNTRY_COUNT(\s+)5' - ErrorMessage " Expected country count to be 5 after init scripts. "
335
347
}
336
348
}
337
349
finally {
0 commit comments