git.iko.soy/typeable/nixpkgs
on master help sign in
Rewrite test script

Thanks to @flokli and @tfc

commit8d36536c2e998c4885bbaf25c2f05634b0473405 authorChristian Kauhaus <kc@flyingcircus.io> dateWed 4 Dec 2019, 11:25 (7 years ago) parent918c2ca
1 file changed+13−44
nixos/tests/resolv.nix+13−44
nixos/tests/resolv.nix+13−44
@@ -21,57 +21,26 @@ import ./make-test-python.nix ({ pkgs, ... } : {
2121 '';
2222 };
2323
24− testScript = let
25− getaddrinfo_py = pkgs.writeScript "getaddrinfo.py" ''
26− import socket
27− import sys
28−
29− result = set()
30− for gai in socket.getaddrinfo(sys.argv[1], 0):
31− result.add(gai[4][0])
32−
33− print(' '.join(sorted(list(result))))
34− '';
35−
36− getaddrinfo = "${pkgs.python3.interpreter} ${getaddrinfo_py}";
37−
38− in
39− ''
40− def compare(test, should, is_):
41− should = should.strip()
42− is_ = is_.strip()
43− resolv.log("{}: expected '{}', actual '{}'".format(test, should, is_))
44− if should == is_:
45− resolv.log("* OK")
46− return True
47− else:
48− resolv.log("* FAILED")
49− return False
24+ testScript = ''
25+ def addrs_in(hostname, addrs):
26+ res = resolv.succeed("getent ahosts {}".format(hostname))
27+ for addr in addrs:
28+ assert addr in res, "Expected output '{}' not found in\n{}".format(addr, res)
5029
5130
5231 start_all()
5332 resolv.wait_for_unit("nscd")
54− res = []
5533
56− out = resolv.succeed(
57− "${getaddrinfo} host-ipv4.example.net"
58− )
59− res.append(compare("resolve IPv4", "192.0.2.1 192.0.2.2", out))
34+ ipv4 = ["192.0.2.1", "192.0.2.2"]
35+ ipv6 = ["2001:db8::2:1", "2001:db8::2:2"]
6036
61− out = resolv.succeed(
62− "${getaddrinfo} host-ipv6.example.net"
63− )
64− res.append(compare("resolve IPv6", "2001:db8::2:1 2001:db8::2:2", out))
37+ with subtest("IPv4 resolves"):
38+ addrs_in("host-ipv4.example.net", ipv4)
6539
66− out = resolv.succeed(
67− "${getaddrinfo} host-dual.example.net"
68− )
69− res.append(
70− compare(
71− "resolve dual stack", "192.0.2.1 192.0.2.2 2001:db8::2:1 2001:db8::2:2", out
72− )
73− )
40+ with subtest("IPv6 resolves"):
41+ addrs_in("host-ipv6.example.net", ipv6)
7442
75− assert all(res) is True
43+ with subtest("Dual stack resolves"):
44+ addrs_in("host-dual.example.net", ipv4 + ipv6)
7645 '';
7746})