add rudimentary test harness, turn example-configuration into a test
This commit is contained in:
parent
4b118bca19
commit
b38b0bd932
4 changed files with 32 additions and 3 deletions
57
tests/smoke/configuration.nix
Normal file
57
tests/smoke/configuration.nix
Normal file
|
@ -0,0 +1,57 @@
|
|||
{ config, tools, pkgs } :
|
||||
let
|
||||
inherit (tools.networking) interface address udhcpc odhcpc;
|
||||
inherit (tools.services) oneshot longrun bundle output;
|
||||
in rec {
|
||||
services.loopback =
|
||||
let iface = interface { type = "loopback"; device = "lo";};
|
||||
in bundle {
|
||||
name = "loopback";
|
||||
contents = [
|
||||
(address iface { family = "inet4"; addr ="127.0.0.1";})
|
||||
(address iface { family = "inet6"; addr ="::1";})
|
||||
];
|
||||
};
|
||||
services.dhcpv4 =
|
||||
let iface = interface { type = "hardware"; device = "eth0"; };
|
||||
in udhcpc iface {};
|
||||
|
||||
services.dhcpv6 =
|
||||
let iface = interface { type = "hardware"; device = "eth0"; };
|
||||
in odhcpc iface { uid = "e7"; };
|
||||
|
||||
services.ntp = longrun {
|
||||
# the simplest approach at the consumer end is to require the
|
||||
# producer to create a file per output variable.
|
||||
name = "ntp";
|
||||
run = let s = services;
|
||||
r = "${pkgs.ntp}/bin/ntp $(cat ${output s.dhcpv4 "ntp_servers"}) $(cat ${output s.dhcpv6 "NTP_IP"})";
|
||||
in (builtins.trace r r);
|
||||
# I don't think it's possible to standardise the file names
|
||||
# generally, as different services have different outputs, but it
|
||||
# would be cool if services that provide an interface could use
|
||||
# the same name as each other. e.g. for anything implementing
|
||||
# addressProvider you might expect (output svc "address") or
|
||||
# (output svc "family") to work. Otherwise switching a network link
|
||||
# from static to dhcp might require reviewing all the downstreams
|
||||
# that refer to it.
|
||||
# Also, services should declare the outputs they provide
|
||||
outputs = [];
|
||||
dependencies = [services.dhcpv4];
|
||||
};
|
||||
|
||||
services.defaultroute4 =
|
||||
let s = services;
|
||||
in oneshot {
|
||||
name = "defaultroute4";
|
||||
up = ''
|
||||
ip route add default gw $(cat ${output s.dhcpv4 "address"})
|
||||
echo "1" > /sys/net/ipv4/$(cat ${output s.dhcpv4 "ifname"})
|
||||
'';
|
||||
down = ''
|
||||
ip route del default gw $(cat ${output s.dhcpv4 "address"})
|
||||
echo "0" > /sys/net/ipv4/$(cat ${output s.dhcpv4 "ifname"})
|
||||
'';
|
||||
};
|
||||
systemPackages = [ pkgs.hello ] ;
|
||||
}
|
22
tests/smoke/run.sh
Executable file
22
tests/smoke/run.sh
Executable file
|
@ -0,0 +1,22 @@
|
|||
set -e
|
||||
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build -I liminix-config=./tests/smoke/configuration.nix -o smoke.img
|
||||
|
||||
TESTS=$(cat <<"EOF"
|
||||
|
||||
trap 'echo "command $(eval echo $BASH_COMMAND) failed with exit code $?"; exit $?' ERR
|
||||
dest_path=${TMPDIR}/smoke.img-$$
|
||||
echo $dest_path
|
||||
unsquashfs -q -d $dest_path smoke.img
|
||||
cd $dest_path;
|
||||
db=*-s6-rc-db/compiled/
|
||||
test -d $db
|
||||
chmod -R +w $db
|
||||
# check we have closure of config.services (lo.link.service exists only
|
||||
# as a dependency)
|
||||
test "$(s6-rc-db -c $db type lo.link.service)" = "oneshot"
|
||||
echo OK
|
||||
EOF
|
||||
)
|
||||
|
||||
|
||||
nix-shell -p s6-rc -p squashfsTools --run "$TESTS" || exit 1
|
Loading…
Add table
Add a link
Reference in a new issue