Skip to content

Commit

Permalink
chore(bats): Add Monthly, Quarterly and Yearly tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vmercierfr committed May 27, 2024
1 parent 8a36d2e commit 4abbd39
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions scripts/bats/30_provisioning.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

0 comments on commit 4abbd39

Please sign in to comment.