#!/usr/local/cpanel/3rdparty/bin/perl -w
#                                      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 Test2::V0;
use Test2::Tools::Explain;
use Test2::Plugin::NoWarnings;
use Test2::Tools::Subtest;
use Test2::Tools::Exception;

use Test::MockModule qw/strict/;
use Test::MockFile   qw/strict/;

use Test::Cpanel::Policy testing => 'Common::Plugins::ServerInfo';

use Common::Plugins::ServerInfo ();

subtest 'Test when file does not have uuid' => sub {
    my $mock = Test::MockFile->file( Common::Plugins::ServerInfo::UUID_FILE(), '' );

    my $uuid = Common::Plugins::ServerInfo::get_server_uuid();
    is $uuid, '', 'uuid returns empty when the file does not exist';

    diag explain $uuid;
};

subtest 'Test when uuid file does not exist' => sub {
    my $mock = Test::MockFile->file( Common::Plugins::ServerInfo::UUID_FILE() );

    my $uuid = Common::Plugins::ServerInfo::get_server_uuid();
    is $uuid, '', 'uuid returns empty when the file does not exist';

    diag explain $uuid;
};

subtest 'Test loading a valid uuid file' => sub {
    my $server_uuid = '4242424242424242424242424242424242424242424242424242424242424242';
    my $mock        = Test::MockFile->file( Common::Plugins::ServerInfo::UUID_FILE(), $server_uuid );

    my $uuid = Common::Plugins::ServerInfo::get_server_uuid();
    is $uuid, $server_uuid, 'uuid returned correctly';

    diag explain $uuid;
};

done_testing;
