Skip to content

Commit ee324bd

Browse files
committed
test(bats): replace mock-based provisioning tests by end-to-end tests
Signed-off-by: Daniel Vérité <dverite@gmail.com>
1 parent e9dd176 commit ee324bd

File tree

2 files changed

+96
-138
lines changed

2 files changed

+96
-138
lines changed

pkg/ppm/provisioning_test.go

Lines changed: 0 additions & 138 deletions
This file was deleted.

scripts/bats/30_provisioning.bats

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,99 @@ EOF
261261
assert_output "$expected_mix"
262262

263263
}
264+
265+
@test "Test provisioning with multiple partition sets in the configuration" {
266+
local CONFIGURATION=$(cat << EOF
267+
partitions:
268+
unittest1:
269+
schema: public
270+
table: table_unittest1
271+
interval: daily
272+
partitionKey: created_at
273+
cleanupPolicy: detach
274+
retention: 1
275+
preProvisioned: 1
276+
unittest2:
277+
schema: public
278+
table: table_unittest2
279+
interval: daily
280+
partitionKey: created_at
281+
cleanupPolicy: drop
282+
retention: 2
283+
preProvisioned: 2
284+
EOF
285+
)
286+
local CONFIGURATION_FILE=$(generate_configuration_file "${CONFIGURATION}")
287+
288+
create_partitioned_table "table_unittest1"
289+
create_partitioned_table "table_unittest2"
290+
291+
PPM_WORK_DATE="2025-02-01" run postgresql-partition-manager run provisioning -c ${CONFIGURATION_FILE}
292+
assert_success
293+
294+
local expected1=$(cat <<'EOF'
295+
public|table_unittest1_2025_01_31|2025-01-31|2025-02-01
296+
public|table_unittest1_2025_02_01|2025-02-01|2025-02-02
297+
public|table_unittest1_2025_02_02|2025-02-02|2025-02-03
298+
EOF
299+
)
300+
run list_existing_partitions "unittest" "public" "table_unittest1"
301+
assert_output "$expected1"
302+
303+
local expected2=$(cat <<'EOF'
304+
public|table_unittest2_2025_01_30|2025-01-30|2025-01-31
305+
public|table_unittest2_2025_01_31|2025-01-31|2025-02-01
306+
public|table_unittest2_2025_02_01|2025-02-01|2025-02-02
307+
public|table_unittest2_2025_02_02|2025-02-02|2025-02-03
308+
public|table_unittest2_2025_02_03|2025-02-03|2025-02-04
309+
EOF
310+
)
311+
312+
run list_existing_partitions "unittest" "public" "table_unittest2"
313+
assert_output "$expected2"
314+
}
315+
316+
@test "Test that provisioning continues after an error on a partition set" {
317+
# Have a non-existing parent table, plus a normal set of partitions
318+
local CONFIGURATION=$(cat << EOF
319+
partitions:
320+
unittest1:
321+
schema: public
322+
table: DOES_NOT_EXIST
323+
interval: daily
324+
partitionKey: created_at
325+
cleanupPolicy: detach
326+
retention: 1
327+
preProvisioned: 1
328+
unittest2:
329+
schema: public
330+
table: table_unittest2
331+
interval: daily
332+
partitionKey: created_at
333+
cleanupPolicy: drop
334+
retention: 2
335+
preProvisioned: 2
336+
EOF
337+
)
338+
local CONFIGURATION_FILE=$(generate_configuration_file "${CONFIGURATION}")
339+
340+
create_partitioned_table "table_unittest2"
341+
342+
PPM_WORK_DATE="2025-02-01" run postgresql-partition-manager run provisioning -c ${CONFIGURATION_FILE}
343+
344+
# The status must reflect the fact that one partition set failed
345+
[ "$status" -eq 4 ] # PartitionsProvisioningFailedExitCode
346+
347+
# Check the success of the second set of partitions
348+
local expected2=$(cat <<'EOF'
349+
public|table_unittest2_2025_01_30|2025-01-30|2025-01-31
350+
public|table_unittest2_2025_01_31|2025-01-31|2025-02-01
351+
public|table_unittest2_2025_02_01|2025-02-01|2025-02-02
352+
public|table_unittest2_2025_02_02|2025-02-02|2025-02-03
353+
public|table_unittest2_2025_02_03|2025-02-03|2025-02-04
354+
EOF
355+
)
356+
357+
run list_existing_partitions "unittest" "public" "table_unittest2"
358+
assert_output "$expected2"
359+
}

0 commit comments

Comments
 (0)