From 0a09782cc8205397b3ff9d3787136394d77f19a7 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sat, 28 Feb 2026 13:19:13 +0100 Subject: [PATCH] testing: migrate store-ping.sh notably the bad-store test previously tested *bash*, not lix. we also need to extend the list of non-fatal errors, but that's probably fine Change-Id: I983f4adc8047fe800323099de4037711869ee547 --- lix/libstore/uds-remote-store.cc | 2 +- tests/functional/meson.build | 1 - tests/functional/store-ping.sh | 17 ------------ tests/functional2/cli/test_store_ping.py | 34 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 19 deletions(-) delete mode 100644 tests/functional/store-ping.sh create mode 100644 tests/functional2/cli/test_store_ping.py diff --git a/lix/libstore/uds-remote-store.cc b/lix/libstore/uds-remote-store.cc index 9093448f0..ccdff65e6 100644 --- a/lix/libstore/uds-remote-store.cc +++ b/lix/libstore/uds-remote-store.cc @@ -67,7 +67,7 @@ static void connectToFirstAvailableSocket(AutoCloseFD & sockFD, const std::list< return; } catch (SysError & e) { if (e.errNo == EACCES || e.errNo == EPERM || e.errNo == ECONNREFUSED || e.errNo == ENOENT - || e.errNo == ENOTDIR) + || e.errNo == ENOTDIR || e.errNo == ENOTSOCK) { debug("skipping socket %s: %s", socket, strerror(e.errNo)); } else { diff --git a/tests/functional/meson.build b/tests/functional/meson.build index f521510ec..fd86ad4fb 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -96,7 +96,6 @@ functional_tests_scripts = [ 'import-derivation.sh', 'db-migration.sh', 'bash-profile.sh', - 'store-ping.sh', 'flakes/show.sh', 'read-only-store.sh', 'nested-sandboxing.sh', diff --git a/tests/functional/store-ping.sh b/tests/functional/store-ping.sh deleted file mode 100644 index 7c0c11fa9..000000000 --- a/tests/functional/store-ping.sh +++ /dev/null @@ -1,17 +0,0 @@ -source common.sh - -STORE_INFO=$(nix store ping 2>&1) -STORE_INFO_JSON=$(nix store ping --json) - -echo "$STORE_INFO" | grep "Store URL: ${NIX_REMOTE}" - -if [[ -v NIX_DAEMON_PACKAGE ]] then - DAEMON_VERSION=$($NIX_DAEMON_PACKAGE/bin/nix daemon --version | cut -d' ' -f3) - echo "$STORE_INFO" | grep "Version: $DAEMON_VERSION" - [[ "$(echo "$STORE_INFO_JSON" | jq -r ".version")" == "$DAEMON_VERSION" ]] -fi - -expect 127 NIX_REMOTE=unix:$PWD/store nix store ping || \ - fail "nix store ping on a non-existent store should fail" - -[[ "$(echo "$STORE_INFO_JSON" | jq -r ".url")" == "${NIX_REMOTE:-local}" ]] diff --git a/tests/functional2/cli/test_store_ping.py b/tests/functional2/cli/test_store_ping.py new file mode 100644 index 000000000..fedf5b331 --- /dev/null +++ b/tests/functional2/cli/test_store_ping.py @@ -0,0 +1,34 @@ +import pytest +from testlib.fixtures.nix import Nix, NixDaemon + + +@pytest.fixture(autouse=True) +def setup(nix: Nix): + nix.settings.add_xp_feature("nix-command") + + +def test_ping(nix: Nix): + info = nix.nix(["store", "ping"]).run().ok().stderr_plain + assert "Store URL: local" in info + + +def test_ping_json(nix: Nix): + info = nix.nix(["store", "ping", "--json"]).run().ok().json() + assert info["url"] == "local" + + +def test_ping_daemon(nix: Nix, daemon: NixDaemon): + version = nix.nix(["daemon", "--version"]).run().ok().stdout_plain + version = version.splitlines()[0].split()[-1] + with daemon(nix) as inner: + info = nix.nix(["store", "ping"]).run().ok().stderr_plain + assert f"Version: {version}" in info + info = inner.nix(["store", "ping", "--json"]).run().ok().json() + assert info["url"] == inner.settings.store + assert info["version"] == version + + +def test_ping_bad_store(nix: Nix): + nix.settings.store = f"unix:{nix.env.dirs.home}" + error = nix.nix(["store", "ping"]).run().expect(1).stderr_plain + assert "could not connect" in error