at 23.11-pre 1.7 kB view raw
1# Tests the contents attribute of nixos/lib/make-disk-image.nix 2# including its user, group, and mode attributes. 3{ system ? builtins.currentSystem, 4 config ? {}, 5 pkgs ? import ../.. { inherit system config; } 6}: 7 8with import ../lib/testing-python.nix { inherit system pkgs; }; 9with pkgs.lib; 10 11with import common/ec2.nix { inherit makeTest pkgs; }; 12 13let 14 config = (import ../lib/eval-config.nix { 15 inherit system; 16 modules = [ 17 ../modules/testing/test-instrumentation.nix 18 ../modules/profiles/qemu-guest.nix 19 { 20 fileSystems."/".device = "/dev/disk/by-label/nixos"; 21 boot.loader.grub.device = "/dev/vda"; 22 boot.loader.timeout = 0; 23 } 24 ]; 25 }).config; 26 image = (import ../lib/make-disk-image.nix { 27 inherit pkgs config; 28 lib = pkgs.lib; 29 format = "qcow2"; 30 contents = [ 31 { 32 source = pkgs.writeText "testFile" "contents"; 33 target = "/testFile"; 34 user = "1234"; 35 group = "5678"; 36 mode = "755"; 37 } 38 { 39 source = ./.; 40 target = "/testDir"; 41 } 42 ]; 43 }) + "/nixos.qcow2"; 44 45in makeEc2Test { 46 name = "image-contents"; 47 inherit image; 48 userData = null; 49 script = '' 50 machine.start() 51 # Test that if contents includes a file, it is copied to the target. 52 assert "content" in machine.succeed("cat /testFile") 53 fileDetails = machine.succeed("ls -l /testFile") 54 assert "1234" in fileDetails 55 assert "5678" in fileDetails 56 assert "rwxr-xr-x" in fileDetails 57 58 # Test that if contents includes a directory, it is copied to the target. 59 dirList = machine.succeed("ls /testDir") 60 assert "image-contents.nix" in dirList 61 ''; 62}