mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-25 15:13:46 +00:00
4f0dadbf38
After final improvements to the official formatter implementation, this commit now performs the first treewide reformat of Nix files using it. This is part of the implementation of RFC 166. Only "inactive" files are reformatted, meaning only files that aren't being touched by any PR with activity in the past 2 months. This is to avoid conflicts for PRs that might soon be merged. Later we can do a full treewide reformat to get the rest, which should not cause as many conflicts. A CI check has already been running for some time to ensure that new and already-formatted files are formatted, so the files being reformatted here should also stay formatted. This commit was automatically created and can be verified using nix-builda08b3a4d19
.tar.gz \ --argstr baseRevb32a094368
result/bin/apply-formatting $NIXPKGS_PATH
99 lines
2.8 KiB
Nix
99 lines
2.8 KiB
Nix
# Test for cntr tool
|
|
{
|
|
system ? builtins.currentSystem,
|
|
config ? { },
|
|
pkgs ? import ../.. { inherit system config; },
|
|
lib ? pkgs.lib,
|
|
}:
|
|
|
|
let
|
|
inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest;
|
|
|
|
mkOCITest =
|
|
backend:
|
|
makeTest {
|
|
name = "cntr-${backend}";
|
|
|
|
meta = {
|
|
maintainers = with lib.maintainers; [
|
|
sorki
|
|
mic92
|
|
];
|
|
};
|
|
|
|
nodes = {
|
|
${backend} =
|
|
{ pkgs, ... }:
|
|
{
|
|
environment.systemPackages = [ pkgs.cntr ];
|
|
virtualisation.oci-containers = {
|
|
inherit backend;
|
|
containers.nginx = {
|
|
image = "nginx-container";
|
|
imageStream = pkgs.dockerTools.examples.nginxStream;
|
|
ports = [ "8181:80" ];
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
testScript = ''
|
|
start_all()
|
|
${backend}.wait_for_unit("${backend}-nginx.service")
|
|
${backend}.wait_for_open_port(8181)
|
|
# For some reason, the cntr command hangs when run without the &.
|
|
# As such, we have to do some messy things to ensure we check the exitcode and output in a race-condition-safe manner
|
|
${backend}.execute(
|
|
"(cntr attach -t ${backend} nginx sh -- -c 'curl localhost | grep Hello' > /tmp/result; echo $? > /tmp/exitcode; touch /tmp/done) &"
|
|
)
|
|
|
|
${backend}.wait_for_file("/tmp/done")
|
|
assert "0" == ${backend}.succeed("cat /tmp/exitcode").strip(), "non-zero exit code"
|
|
assert "Hello" in ${backend}.succeed("cat /tmp/result"), "no greeting in output"
|
|
'';
|
|
};
|
|
|
|
mkContainersTest = makeTest {
|
|
name = "cntr-containers";
|
|
|
|
meta = with pkgs.lib.maintainers; {
|
|
maintainers = [
|
|
sorki
|
|
mic92
|
|
];
|
|
};
|
|
|
|
nodes.machine =
|
|
{ lib, ... }:
|
|
{
|
|
environment.systemPackages = [ pkgs.cntr ];
|
|
containers.test = {
|
|
autoStart = true;
|
|
privateNetwork = true;
|
|
hostAddress = "172.16.0.1";
|
|
localAddress = "172.16.0.2";
|
|
config = { };
|
|
};
|
|
};
|
|
|
|
testScript = ''
|
|
machine.start()
|
|
machine.wait_for_unit("container@test.service")
|
|
# I haven't observed the same hanging behaviour in this version as in the OCI version which necessetates this messy invocation, but it's probably better to be safe than sorry and use it here as well
|
|
machine.execute(
|
|
"(cntr attach test sh -- -c 'ping -c5 172.16.0.1'; echo $? > /tmp/exitcode; touch /tmp/done) &"
|
|
)
|
|
|
|
machine.wait_for_file("/tmp/done")
|
|
assert "0" == machine.succeed("cat /tmp/exitcode").strip(), "non-zero exit code"
|
|
'';
|
|
};
|
|
in
|
|
{
|
|
nixos-container = mkContainersTest;
|
|
}
|
|
// (lib.foldl' (attrs: backend: attrs // { ${backend} = mkOCITest backend; }) { } [
|
|
"docker"
|
|
"podman"
|
|
])
|