Compare commits

...

2 Commits

Author SHA1 Message Date
c07aa0c406 delete list-usb-drives test 2025-08-19 23:48:04 -04:00
170e124dd2 update 2025-08-19 23:25:15 -04:00
4 changed files with 10 additions and 72 deletions

18
flake.lock generated
View File

@@ -238,11 +238,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1755514248, "lastModified": 1755656257,
"narHash": "sha256-uPg3P8pRR1B3/b/ddDvdSOTRm4zUBKU0XhwVFO6K2XM=", "narHash": "sha256-5IZbp78APGYBsdfhBWCPVEIH1I0j81sfiN+ctGiHW2o=",
"owner": "ggml-org", "owner": "ggml-org",
"repo": "llama.cpp", "repo": "llama.cpp",
"rev": "618575c5825d7d4f170e686e772178d2aae148ae", "rev": "a094f381432d92c4bf92d2d6167284316ba73a62",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -260,11 +260,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1755483699, "lastModified": 1755655202,
"narHash": "sha256-dj5cNx+WvDv5fbsE4h/Q6UuTttc/BHBE3BVGVn2TUNk=", "narHash": "sha256-UeQs2b1u99hthaiEqW/wkhL0aDDhp10/pA0keQqfkcY=",
"owner": "Infinidoge", "owner": "Infinidoge",
"repo": "nix-minecraft", "repo": "nix-minecraft",
"rev": "aa5ed59e2570c7adfd6f5ca6ec08fff3140d7565", "rev": "fdd3b8ec61a25e5a1c9bbf2041d64129f51000a5",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -291,11 +291,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1755471983, "lastModified": 1755593991,
"narHash": "sha256-axUoWcm4cNQ36jOlnkD9D40LTfSQgk8ExfHSRm3rTtg=", "narHash": "sha256-BA9MuPjBDx/WnpTJ0EGhStyfE7hug8g85Y3Ju9oTsM4=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "48f4c982de68d966421d2b6f1ddbeb6227cc5ceb", "rev": "a58390ab6f1aa810eb8e0f0fc74230e7cc06de03",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -61,22 +61,7 @@ final: prev: {
]; ];
text = '' text = ''
# Allow overriding the disk-by-id directory for testing
DISK_BY_ID_DIR="''${LIST_USB_DRIVES_DISK_DIR:-/dev/disk/by-id}"
# Mock lsblk for testing
if [ -n "''${LIST_USB_DRIVES_TEST_MODE:-}" ]; then
lsblk() {
echo "''$LIST_USB_DRIVES_MOCK_DATA" | tr '|' '\n' | while IFS=: read -r pattern response; do
case "$(basename "$3")" in *"$pattern"*) echo "$response"; return ;; esac
done || echo "UNKNOWN_MODEL UNKNOWN_SERIAL"
}
fi
# Scan for USB devices in the specified directory
if [ -d "$DISK_BY_ID_DIR" ]; then
find "$DISK_BY_ID_DIR" -name "usb*" | grep -v "part[0-9]\$" | while read -r drive; do lsblk -no model,serial "$drive" | head -n1 | tr -d '\n' | tr " " "_" && echo -e " $(echo \"$drive\" | cut -d':' -f2-)"; done | column -t --table-columns=DRIVE,BAY | sort -n -k 2 find "$DISK_BY_ID_DIR" -name "usb*" | grep -v "part[0-9]\$" | while read -r drive; do lsblk -no model,serial "$drive" | head -n1 | tr -d '\n' | tr " " "_" && echo -e " $(echo \"$drive\" | cut -d':' -f2-)"; done | column -t --table-columns=DRIVE,BAY | sort -n -k 2
fi
''; '';
}; };
} }

View File

@@ -1,46 +0,0 @@
{
config,
lib,
pkgs,
inputs,
...
}:
let
# Create pkgs with list-usb-drives overlay
testPkgs = import inputs.nixpkgs {
system = pkgs.system;
overlays = [ (import ../overlays.nix) ];
};
in
testPkgs.testers.runNixOSTest {
name = "list-usb-drives test";
nodes.machine =
{ pkgs, ... }:
{
environment.systemPackages = [
testPkgs.list-usb-drives
];
};
testScript = ''
start_all()
machine.wait_for_unit("multi-user.target")
# Create mock USB device symlinks
machine.succeed("mkdir -p /tmp/mock-by-id")
machine.succeed("touch /tmp/mock-by-id/usb-drive1-0:0")
machine.succeed("touch /tmp/mock-by-id/usb-drive2-0:1")
machine.succeed("touch /tmp/mock-by-id/usb-drive1-0:0-part1") # Should be filtered out
# Test with mock data
mock_data = "drive1:Model1 Serial1|drive2:Model2 Serial2"
output = machine.succeed(f"LIST_USB_DRIVES_DISK_DIR=/tmp/mock-by-id LIST_USB_DRIVES_TEST_MODE=1 LIST_USB_DRIVES_MOCK_DATA='{mock_data}' list-usb-drives")
# Expected exact output
expected = 'DRIVE BAY\nModel1_Serial1 0"\nModel2_Serial2 1"\n'
assert output == expected
print(" Mock USB device test passed")
'';
}

View File

@@ -11,5 +11,4 @@ in
zfsTest = handleTest ./zfs.nix; zfsTest = handleTest ./zfs.nix;
testTest = handleTest ./testTest.nix; testTest = handleTest ./testTest.nix;
minecraftTest = handleTest ./minecraft.nix; minecraftTest = handleTest ./minecraft.nix;
listUsbDrivesTest = handleTest ./list-usb-drives.nix;
} }