diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 05:42:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 05:42:59 +0000 |
commit | c45bd7dca7394d3a25f5bbf416f3b75c50759190 (patch) | |
tree | f7dbbfcc2f6b787eea456d1f1e28525ca2ceb9ba /tests | |
parent | Initial commit. (diff) | |
download | initramfs-tools-upstream.tar.xz initramfs-tools-upstream.zip |
Adding upstream version 0.143.upstream/0.143upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/functions_test | 54 | ||||
-rw-r--r-- | tests/netinfo/net-eth0.conf | 17 | ||||
-rw-r--r-- | tests/netinfo/net-eth1.conf | 17 |
3 files changed, 88 insertions, 0 deletions
diff --git a/tests/functions_test b/tests/functions_test new file mode 100755 index 0000000..c5db566 --- /dev/null +++ b/tests/functions_test @@ -0,0 +1,54 @@ +#!/bin/sh +set -u + +# Unit tests for scripts/functions + +TEST_DIR="${0%/*}" +ROOT_DIR="$TEST_DIR/.." +CR=" +" + +oneTimeSetUp() { + . "$ROOT_DIR/scripts/functions" +} + +HOSTS_FOOTER=" +# The following lines are desirable for IPv6 capable hosts +::1 localhost ip6-localhost ip6-loopback +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters" + +test_generate_hosts_content_with_domain() { + hosts_content=$(_generate_hosts_content example com) + assertEquals "127.0.0.1 localhost${CR}127.0.1.1 example.com example${CR}${HOSTS_FOOTER}" "$hosts_content" +} + +test_generate_hosts_content_without_domain() { + hosts_content=$(_generate_hosts_content example "") + assertEquals "127.0.0.1 localhost${CR}127.0.1.1 example${CR}${HOSTS_FOOTER}" "$hosts_content" +} + +test_netinfo_to_resolv_conf_IPv4() { + resolv_conf=$(netinfo_to_resolv_conf - "$TEST_DIR/netinfo/net-eth0.conf") + assertEquals "domain example.net${CR}nameserver 192.0.2.42${CR}search example.net. example.com." "$resolv_conf" +} + +test_netinfo_to_resolv_conf_duplicates() { + resolv_conf=$(netinfo_to_resolv_conf - "$TEST_DIR/netinfo/net-eth0.conf" "$TEST_DIR/netinfo/net-eth0.conf") + assertEquals "domain example.net${CR}nameserver 192.0.2.42${CR}search example.net. example.com." "$resolv_conf" +} + +test_netinfo_to_resolv_conf_mutliple() { + resolv_conf=$(netinfo_to_resolv_conf - "$TEST_DIR/netinfo/net-eth0.conf" "$TEST_DIR/netinfo/net-eth1.conf") + assertEquals "domain example.org${CR}nameserver 192.0.2.42${CR}nameserver 192.0.2.84${CR}search example.net. example.com. example.org." "$resolv_conf" +} + +test_netinfo_to_resolv_conf_write_output() { + tmpfile=$(mktemp -t initramfs-tools.XXXXXXXXXX) + netinfo_to_resolv_conf "$tmpfile" "$TEST_DIR/netinfo/net-eth0.conf" + assertEquals "domain example.net${CR}nameserver 192.0.2.42${CR}search example.net. example.com." "$(cat "$tmpfile")" + rm -f "$tmpfile" +} + +# Load shUnit2. +. shunit2 diff --git a/tests/netinfo/net-eth0.conf b/tests/netinfo/net-eth0.conf new file mode 100644 index 0000000..3c79b6d --- /dev/null +++ b/tests/netinfo/net-eth0.conf @@ -0,0 +1,17 @@ +DEVICE='eth0' +PROTO='dhcp' +IPV4ADDR='192.0.2.101' +IPV4BROADCAST='192.0.2.255' +IPV4NETMASK='255.255.255.0' +IPV4GATEWAY='192.0.2.1' +IPV4DNS0='192.0.2.42' +IPV4DNS1='0.0.0.0' +HOSTNAME='example-host' +DNSDOMAIN='example.net' +NISDOMAIN='' +ROOTSERVER='192.0.2.1' +ROOTPATH='' +filename='' +UPTIME='4' +DHCPLEASETIME='86400' +DOMAINSEARCH='example.net. example.com.' diff --git a/tests/netinfo/net-eth1.conf b/tests/netinfo/net-eth1.conf new file mode 100644 index 0000000..fb3fb27 --- /dev/null +++ b/tests/netinfo/net-eth1.conf @@ -0,0 +1,17 @@ +DEVICE='eth1' +PROTO='dhcp' +IPV4ADDR='192.0.2.150' +IPV4BROADCAST='192.0.2.255' +IPV4NETMASK='255.255.255.0' +IPV4GATEWAY='192.0.2.254' +IPV4DNS0='192.0.2.84' +IPV4DNS1='0.0.0.0' +HOSTNAME='example-host' +DNSDOMAIN='example.org' +NISDOMAIN='' +ROOTSERVER='192.0.2.254' +ROOTPATH='' +filename='' +UPTIME='4' +DHCPLEASETIME='86400' +DOMAINSEARCH='example.org.' |