about summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authorRyan Lahfa <masterancpp@gmail.com>2023-04-16 21:49:09 +0200
committerGitHub <noreply@github.com>2023-04-16 21:49:09 +0200
commit6bf4cde63f78b2d58346d2574beb6c49c23ff247 (patch)
tree47972c0f6fac83fb66c0c2abd4f64e23bd6feb10 /nixos/tests
parent91de60e122e657f978bc3fc047fd59ed7433c4cc (diff)
parent15c760d6b8fd425c4f10cda6f82959dd98ea191c (diff)
Merge pull request #226214 from leon-barrett/leon-make-disk-image-dir
nixos/make-disk-image: fix contents dir paths
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/common/ec2.nix9
-rw-r--r--nixos/tests/image-contents.nix25
2 files changed, 26 insertions, 8 deletions
diff --git a/nixos/tests/common/ec2.nix b/nixos/tests/common/ec2.nix
index 6ed420e0aae75..1a64c464039b4 100644
--- a/nixos/tests/common/ec2.nix
+++ b/nixos/tests/common/ec2.nix
@@ -17,6 +17,7 @@ with pkgs.lib;
           ln -s ${pkgs.writeText "sshPublicKey" sshPublicKey} $out/1.0/meta-data/public-keys/0/openssh-key
         '';
       };
+      indentLines = str: concatLines (map (s: "  " + s) (splitString "\n" str));
     in makeTest {
       name = "ec2-" + name;
       nodes = {};
@@ -36,6 +37,8 @@ with pkgs.lib;
                 "create",
                 "-f",
                 "qcow2",
+                "-F",
+                "qcow2",
                 "-o",
                 "backing_file=${image}",
                 disk_image,
@@ -59,7 +62,11 @@ with pkgs.lib;
         )
 
         machine = create_machine({"startCommand": start_command})
-      '' + script;
+        try:
+      '' + indentLines script + ''
+        finally:
+          machine.shutdown()
+      '';
 
       inherit meta;
     };
diff --git a/nixos/tests/image-contents.nix b/nixos/tests/image-contents.nix
index 90908968a7e27..858f7d8c68f40 100644
--- a/nixos/tests/image-contents.nix
+++ b/nixos/tests/image-contents.nix
@@ -27,13 +27,19 @@ let
     inherit pkgs config;
     lib = pkgs.lib;
     format = "qcow2";
-    contents = [{
-      source = pkgs.writeText "testFile" "contents";
-      target = "/testFile";
-      user = "1234";
-      group = "5678";
-      mode = "755";
-    }];
+    contents = [
+      {
+        source = pkgs.writeText "testFile" "contents";
+        target = "/testFile";
+        user = "1234";
+        group = "5678";
+        mode = "755";
+      }
+      {
+        source = ./.;
+        target = "/testDir";
+      }
+    ];
   }) + "/nixos.qcow2";
 
 in makeEc2Test {
@@ -42,10 +48,15 @@ in makeEc2Test {
   userData = null;
   script = ''
     machine.start()
+    # Test that if contents includes a file, it is copied to the target.
     assert "content" in machine.succeed("cat /testFile")
     fileDetails = machine.succeed("ls -l /testFile")
     assert "1234" in fileDetails
     assert "5678" in fileDetails
     assert "rwxr-xr-x" in fileDetails
+
+    # Test that if contents includes a directory, it is copied to the target.
+    dirList = machine.succeed("ls /testDir")
+    assert "image-contents.nix" in dirList
   '';
 }