Merge pull request #698 from rhansen/tests

t/get_ip_from_if.pl test improvements
This commit is contained in:
Richard Hansen 2024-07-11 00:35:22 -04:00 committed by GitHub
commit 2e26a63c2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 31 deletions

View file

@ -64,21 +64,11 @@ jobs:
- fedora:rawhide - fedora:rawhide
- almalinux:8 - almalinux:8
- almalinux:latest - almalinux:latest
# RedHat UBI is mostly garbage due to a profound lack of basic
# packages. It is tested anyway because it's the closest available
# approximation of RHEL, aside from AlmaLinux. Some of the packages
# needed for some tests aren't available, so those tests will be
# skipped. I guess it's still better than nothing.
- registry.access.redhat.com/ubi7/ubi:latest
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: ${{ matrix.image }} image: ${{ matrix.image }}
steps: steps:
- if: ${{ matrix.image != 'registry.access.redhat.com/ubi7/ubi:latest' }} - uses: actions/checkout@v4
uses: actions/checkout@v4
# ubi7 is too old for checkout@v4.
- if: ${{ matrix.image == 'registry.access.redhat.com/ubi7/ubi:latest' }}
uses: actions/checkout@v3
- name: enable repositories (AlmaLinux 8) - name: enable repositories (AlmaLinux 8)
if: ${{ matrix.image == 'almalinux:8' }} if: ${{ matrix.image == 'almalinux:8' }}
run: | run: |
@ -93,12 +83,7 @@ jobs:
# The --skip-broken argument works around RedHat UBI's missing packages. # The --skip-broken argument works around RedHat UBI's missing packages.
# (They're only used for testing, so it's OK to not install them.) # (They're only used for testing, so it's OK to not install them.)
run: | run: |
inst="dnf --refresh --skip-broken install -y" dnf --refresh --skip-broken install -y \
case '${{ matrix.image }}' in
# RedHat UBI 7 (RHEL 7) doesn't have dnf.
*ubi7*) inst="yum --skip-broken install -y";;
esac
${inst} \
automake \ automake \
findutils \ findutils \
iproute \ iproute \

View file

@ -39,23 +39,30 @@ subtest "get_ip_from_interface tests" => sub {
} }
}; };
subtest "Get default interface and IP for test system" => sub { subtest "Get default interface and IP for test system (IPv4)" => sub {
my $interface = ddclient::get_default_interface(4); my $interface = ddclient::get_default_interface(4);
if ($interface) { plan(skip_all => 'no IPv4 interface') if !$interface;
isnt($interface, "lo", "Check for loopback 'lo'"); isnt($interface, "lo", "Check for loopback 'lo'");
isnt($interface, "lo0", "Check for loopback 'lo0'"); isnt($interface, "lo0", "Check for loopback 'lo0'");
my $ip1 = ddclient::get_ip_from_interface("default", 4); my $ip1 = ddclient::get_ip_from_interface("default", 4);
my $ip2 = ddclient::get_ip_from_interface($interface, 4); my $ip2 = ddclient::get_ip_from_interface($interface, 4);
is($ip1, $ip2, "Check IPv4 from default interface"); is($ip1, $ip2, "Check IPv4 from default interface");
SKIP: {
skip('default interface does not have an appropriate IPv4 addresses') if !$ip1;
ok(ddclient::is_ipv4($ip1), "Valid IPv4 from get_ip_from_interface($interface)"); ok(ddclient::is_ipv4($ip1), "Valid IPv4 from get_ip_from_interface($interface)");
} }
$interface = ddclient::get_default_interface(6); };
if ($interface) {
isnt($interface, "lo", "Check for loopback 'lo'"); subtest "Get default interface and IP for test system (IPv6)" => sub {
isnt($interface, "lo0", "Check for loopback 'lo0'"); my $interface = ddclient::get_default_interface(6);
my $ip1 = ddclient::get_ip_from_interface("default", 6); plan(skip_all => 'no IPv6 interface') if !$interface;
my $ip2 = ddclient::get_ip_from_interface($interface, 6); isnt($interface, "lo", "Check for loopback 'lo'");
is($ip1, $ip2, "Check IPv6 from default interface"); isnt($interface, "lo0", "Check for loopback 'lo0'");
my $ip1 = ddclient::get_ip_from_interface("default", 6);
my $ip2 = ddclient::get_ip_from_interface($interface, 6);
is($ip1, $ip2, "Check IPv6 from default interface");
SKIP: {
skip('default interface does not have an appropriate IPv6 addresses') if !$ip1;
ok(ddclient::is_ipv6($ip1), "Valid IPv6 from get_ip_from_interface($interface)"); ok(ddclient::is_ipv6($ip1), "Valid IPv6 from get_ip_from_interface($interface)");
} }
}; };