#!/usr/local/cpanel/3rdparty/bin/perl

#                                      Copyright 2025 WebPros International, LLC
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited.

use cPstrict;
use Test::Cpanel::Policy;

use Test2::V0;
use Test2::Tools::Explain;
use Test2::Tools::Compare;
use Test2::Plugin::NoWarnings;

use Whostmgr::CometBackup::Constants ();

subtest 'Constants - file path constants exist' => sub {
    ok( defined $Whostmgr::CometBackup::Constants::CREDENTIALS_FILE, 'CREDENTIALS_FILE defined' );
    ok( defined $Whostmgr::CometBackup::Constants::BACKUP_JOBS_DB, 'BACKUP_JOBS_DB defined' );
    ok( defined $Whostmgr::CometBackup::Constants::PROTECTED_ITEMS_DB, 'PROTECTED_ITEMS_DB defined' );
    ok( defined $Whostmgr::CometBackup::Constants::PROTECTED_ITEM_MAP_DB, 'PROTECTED_ITEM_MAP_DB defined' );
    ok( defined $Whostmgr::CometBackup::Constants::BACKUP_TOOL_PATH, 'BACKUP_TOOL_PATH defined' );
};

subtest 'Constants - recovery data constants' => sub {
    ok( defined $Whostmgr::CometBackup::Constants::RECOVERY_DATA_PATH, 'RECOVERY_DATA_PATH defined' );
    ok( defined $Whostmgr::CometBackup::Constants::RECOVERY_DATA_ITEM_NAME, 'RECOVERY_DATA_ITEM_NAME defined' );
};

subtest 'Constants - backup runner constants' => sub {
    ok( defined $Whostmgr::CometBackup::Constants::BACKUP_RUNNER_PATH, 'BACKUP_RUNNER_PATH defined' );
    ok( defined $Whostmgr::CometBackup::Constants::RUN_LOG_DB, 'RUN_LOG_DB defined' );
    ok( defined $Whostmgr::CometBackup::Constants::PID_FILE, 'PID_FILE defined' );
    ok( defined $Whostmgr::CometBackup::Constants::CANCEL_FILE_PATTERN, 'CANCEL_FILE_PATTERN defined' );
    ok( defined $Whostmgr::CometBackup::Constants::DISABLED_TOUCHFILE, 'DISABLED_TOUCHFILE defined' );
    ok( defined $Whostmgr::CometBackup::Constants::TEXT_LOG_DIR, 'TEXT_LOG_DIR defined' );
    ok( defined $Whostmgr::CometBackup::Constants::MAX_PARALLEL_USERS, 'MAX_PARALLEL_USERS defined' );
    ok( defined $Whostmgr::CometBackup::Constants::MAX_LOAD_AVERAGE, 'MAX_LOAD_AVERAGE defined' );
};

subtest 'Constants - get_cancel_file_path' => sub {
    my $job_uuid = '00000000-0000-0000-0000-000000000001';
    my $cancel_file = Whostmgr::CometBackup::Constants::get_cancel_file_path($job_uuid);
    
    ok( defined $cancel_file, 'Returns cancel file path' );
    like( $cancel_file, qr/$job_uuid/, 'Cancel file path contains job UUID' );
    like( $cancel_file, qr/^\/var\/run/, 'Cancel file is in /var/run' );
};

subtest 'Constants - get_text_log_file_path' => sub {
    my $job_uuid = '00000000-0000-0000-0000-000000000001';
    my $run_uuid = '00000000-0000-0000-0000-000000000002';
    my $log_file = Whostmgr::CometBackup::Constants::get_text_log_file_path($job_uuid, $run_uuid);
    
    ok( defined $log_file, 'Returns log file path' );
    like( $log_file, qr/$job_uuid/, 'Log file path contains job UUID' );
    like( $log_file, qr/$run_uuid/, 'Log file path contains run UUID' );
    like( $log_file, qr/\.log$/, 'Log file ends with .log extension' );
};

exit 0 if done_testing();
