#!/usr/local/cpanel/3rdparty/bin/perl -w
# cpanel - plugins/cpanel/koality/perl/usr/local/cpanel/t/medium/Cpanel-Plugins-ServerId.t  Copyright 2023 cPanel, L.L.C.
#                                                           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::MockAdmin;

use Test::Cpanel::Policy testing => 'Cpanel::Plugins::ServerId';
use Capture::Tiny;

use Cpanel::Plugins::ServerId;
use Cpanel::Admin::Modules::Cpanel::site_quality_monitoring;

my $mock_ips = Test::MockModule->new('Cpanel::DIp::MainIP');
$mock_ips->redefine(
    getpublicmainserverip => sub {
        return "42.42.42.42";
    }
);

my $server_uuid    = '4242424242424242424242424242424242424242424242424242424242424242';
my $mock_uuid_file = Test::MockFile->file( Cpanel::Admin::Modules::Cpanel::site_quality_monitoring::UUID_FILE(), $server_uuid );
my $expect         = '4242424242424242424242424242424242424242424242424242424242424242-42.42.42.42';

my $madmin = Test::MockAdmin->new();
my @mock   = $madmin->create_mock( 'site_quality_monitoring', 'GET_SERVER_UUID', sub { return $server_uuid } );

subtest 'get_server_id' => sub {
    my $got = Cpanel::Plugins::ServerId::get_server_id();
    is( $got, $expect, "Go the expected server id" );
};

done_testing;
