diff --git a/scripts/bats/30_provisioning.bats b/scripts/bats/30_provisioning.bats index e76d826..9be68da 100644 --- a/scripts/bats/30_provisioning.bats +++ b/scripts/bats/30_provisioning.bats @@ -87,3 +87,111 @@ EOF assert_table_exists public $(generate_daily_partition_name ${TABLE} -${NEW_RETENTION}) # New retention partition assert_table_exists public $(generate_daily_partition_name ${TABLE} ${NEW_PREPROVISIONED}) # New preProvisioned partition } + +@test "Test monthly partitions" { + local TABLE=$(generate_table_name) + local INTERVAL=monthly + local RETENTION=1 + local PREPROVISIONED=1 + local EXPECTED_LAST_TABLE="${TABLE}_$(get_current_date_adjusted_by_month -1)" + local EXPECTED_CURRENT_TABLE="${TABLE}_$(get_current_date_adjusted_by_month 0)" + local EXPECTED_NEXT_TABLE="${TABLE}_$(get_current_date_adjusted_by_month +1)" + + # Create partioned table + create_partioned_table ${TABLE} ${INTERVAL} ${RETENTION} ${PREPROVISIONED} + + local CONFIGURATION=$(cat << EOF +partitions: + unittest: + schema: public + table: ${TABLE} + interval: ${INTERVAL} + partitionKey: created_at + cleanupPolicy: drop + retention: ${RETENTION} + preProvisioned: ${PREPROVISIONED} +EOF +) + local CONFIGURATION_FILE=$(generate_configuration_file "${CONFIGURATION}") + + cat ${CONFIGURATION_FILE} + + run postgresql-partition-manager run provisioning -c ${CONFIGURATION_FILE} + + assert_success + assert_output --partial "All partitions are correctly provisioned" + assert_table_exists public ${EXPECTED_LAST_TABLE} + assert_table_exists public ${EXPECTED_CURRENT_TABLE} + assert_table_exists public ${EXPECTED_NEXT_TABLE} +} + +@test "Test quarterly partitions" { + local TABLE=$(generate_table_name) + local INTERVAL=quarterly + local RETENTION=1 + local PREPROVISIONED=1 + local EXPECTED_LAST_TABLE="${TABLE}_$(get_current_date_adjusted_by_quarter -1)" + local EXPECTED_CURRENT_TABLE="${TABLE}_$(get_current_date_adjusted_by_quarter 0)" + local EXPECTED_NEXT_TABLE="${TABLE}_$(get_current_date_adjusted_by_quarter +1)" + + # Create partioned table + create_partioned_table ${TABLE} ${INTERVAL} ${RETENTION} ${PREPROVISIONED} + + local CONFIGURATION=$(cat << EOF +partitions: + unittest: + schema: public + table: ${TABLE} + interval: ${INTERVAL} + partitionKey: created_at + cleanupPolicy: drop + retention: ${RETENTION} + preProvisioned: ${PREPROVISIONED} +EOF +) + local CONFIGURATION_FILE=$(generate_configuration_file "${CONFIGURATION}") + + run postgresql-partition-manager run provisioning -c ${CONFIGURATION_FILE} + + + assert_success + assert_output --partial "All partitions are correctly provisioned" + assert_table_exists public ${EXPECTED_LAST_TABLE} + assert_table_exists public ${EXPECTED_CURRENT_TABLE} + assert_table_exists public ${EXPECTED_NEXT_TABLE} +} + +@test "Test yearly partitions" { + local TABLE=$(generate_table_name) + local INTERVAL=yearly + local RETENTION=1 + local PREPROVISIONED=1 + local EXPECTED_LAST_TABLE="${TABLE}_$(get_current_date_adjusted_by_year -1)" + local EXPECTED_CURRENT_TABLE="${TABLE}_$(get_current_date_adjusted_by_year 0)" + local EXPECTED_NEXT_TABLE="${TABLE}_$(get_current_date_adjusted_by_year +1)" + + # Create partioned table + create_partioned_table ${TABLE} ${INTERVAL} ${RETENTION} ${PREPROVISIONED} + + local CONFIGURATION=$(cat << EOF +partitions: + unittest: + schema: public + table: ${TABLE} + interval: ${INTERVAL} + partitionKey: created_at + cleanupPolicy: drop + retention: ${RETENTION} + preProvisioned: ${PREPROVISIONED} +EOF +) + local CONFIGURATION_FILE=$(generate_configuration_file "${CONFIGURATION}") + + run postgresql-partition-manager run provisioning -c ${CONFIGURATION_FILE} + + assert_success + assert_output --partial "All partitions are correctly provisioned" + assert_table_exists public ${EXPECTED_LAST_TABLE} + assert_table_exists public ${EXPECTED_CURRENT_TABLE} + assert_table_exists public ${EXPECTED_NEXT_TABLE} +}