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

#                                      Copyright 2024 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 Test::More;

use experimental 'builtin';

use lib 't/lib';
use Whostmgr::360Monitoring::Agent;
use Whostmgr::360Monitoring::Agent::Test;

use constant {
    PACKAGE_TO_TEST => test_to_package(__FILE__),
};

use_ok(PACKAGE_TO_TEST);

{
    my $agent = Whostmgr::360Monitoring::Agent->new();
    my $obj   = new_ok( PACKAGE_TO_TEST() => [ $agent, {} ] );
    is( $obj->interfaces, undef, "interfaces when unset is undef" );
}

{
    my $agent = Whostmgr::360Monitoring::Agent->new();
    my $obj   = new_ok( PACKAGE_TO_TEST() => [ $agent, { interfaces => "eth0,eth1" } ] );
    is_deeply( $obj->interfaces, [ "eth0", "eth1" ], "interfaces is internally represented as array" );
}

{
    my $role = do {
        my $pkg = PACKAGE_TO_TEST;
        $pkg =~ s/.*:://;
        $pkg;
    };
    my $agent = Whostmgr::360Monitoring::Agent->new();
    $agent->add_to_plugins( $role => { interfaces => "eth0,eth1" } );
    like( $agent->to_INI(), qr/interfaces=eth0,eth1/, "to_INI() returns eth0,eth1 as a string" );
}

done_testing();
