Add tests for the upload and download commands.
authorRichard Jones <rjones@redhat.com>
Mon, 20 Apr 2009 12:14:07 +0000 (13:14 +0100)
committerRichard Jones <rjones@redhat.com>
Mon, 20 Apr 2009 12:14:07 +0000 (13:14 +0100)
.gitignore
src/generator.ml
tests.c

index 174489e..e41c076 100644 (file)
@@ -69,6 +69,7 @@ ruby/ext/guestfs/mkmf.log
 pod2htm?.tmp
 stamp-h1
 test*.img
 pod2htm?.tmp
 stamp-h1
 test*.img
+test*.tmp
 tests
 update-initramfs.sh
 vmlinuz.*
 tests
 update-initramfs.sh
 vmlinuz.*
index 191b94d..ae1dfe9 100755 (executable)
@@ -1273,7 +1273,10 @@ Reread the partition table on C<device>.
 This uses the L<blockdev(8)> command.");
 
   ("upload", (RErr, [FileIn "filename"; String "remotefilename"]), 66, [],
 This uses the L<blockdev(8)> command.");
 
   ("upload", (RErr, [FileIn "filename"; String "remotefilename"]), 66, [],
-   [],
+   [InitBasicFS, TestOutput (
+      (* Pick a file from cwd which isn't likely to change. *)
+    [["upload"; "COPYING.LIB"; "/COPYING.LIB"];
+     ["checksum"; "md5"; "/COPYING.LIB"]], "e3eda01d9815f8d24aae2dbd89b68b06")],
    "upload a file from the local machine",
    "\
 Upload local file C<filename> to C<remotefilename> on the
    "upload a file from the local machine",
    "\
 Upload local file C<filename> to C<remotefilename> on the
@@ -1284,7 +1287,12 @@ C<filename> can also be a named pipe.
 See also C<guestfs_download>.");
 
   ("download", (RErr, [String "remotefilename"; FileOut "filename"]), 67, [],
 See also C<guestfs_download>.");
 
   ("download", (RErr, [String "remotefilename"; FileOut "filename"]), 67, [],
-   [],
+   [InitBasicFS, TestOutput (
+      (* Pick a file from cwd which isn't likely to change. *)
+    [["upload"; "COPYING.LIB"; "/COPYING.LIB"];
+     ["download"; "/COPYING.LIB"; "testdownload.tmp"];
+     ["upload"; "testdownload.tmp"; "/upload"];
+     ["checksum"; "md5"; "/upload"]], "e3eda01d9815f8d24aae2dbd89b68b06")],
    "download a file to the local machine",
    "\
 Download file C<remotefilename> and save it as C<filename>
    "download a file to the local machine",
    "\
 Download file C<remotefilename> and save it as C<filename>
diff --git a/tests.c b/tests.c
index 9744575..876cc29 100644 (file)
--- a/tests.c
+++ b/tests.c
@@ -101,8 +101,6 @@ static void no_test_warnings (void)
   fprintf (stderr, "warning: \"guestfs_command_lines\" has no tests\n");
   fprintf (stderr, "warning: \"guestfs_tune2fs_l\" has no tests\n");
   fprintf (stderr, "warning: \"guestfs_blockdev_setbsz\" has no tests\n");
   fprintf (stderr, "warning: \"guestfs_command_lines\" has no tests\n");
   fprintf (stderr, "warning: \"guestfs_tune2fs_l\" has no tests\n");
   fprintf (stderr, "warning: \"guestfs_blockdev_setbsz\" has no tests\n");
-  fprintf (stderr, "warning: \"guestfs_upload\" has no tests\n");
-  fprintf (stderr, "warning: \"guestfs_download\" has no tests\n");
 }
 
 static int test_checksum_0 (void)
 }
 
 static int test_checksum_0 (void)
@@ -614,6 +612,150 @@ static int test_checksum_7 (void)
   return 0;
 }
 
   return 0;
 }
 
+static int test_download_0 (void)
+{
+  /* InitBasicFS for download (0): create ext2 on /dev/sda1 */
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_umount_all (g);
+    if (r == -1)
+      return -1;
+  }
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_lvm_remove_all (g);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char *lines[] = {
+      ",",
+      NULL
+    };
+    int r;
+    suppress_error = 0;
+    r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
+    if (r == -1)
+      return -1;
+  }
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_mkfs (g, "ext2", "/dev/sda1");
+    if (r == -1)
+      return -1;
+  }
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_mount (g, "/dev/sda1", "/");
+    if (r == -1)
+      return -1;
+  }
+  /* TestOutput for download (0) */
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_upload (g, "COPYING.LIB", "/COPYING.LIB");
+    if (r == -1)
+      return -1;
+  }
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_download (g, "/COPYING.LIB", "testdownload.tmp");
+    if (r == -1)
+      return -1;
+  }
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_upload (g, "testdownload.tmp", "/upload");
+    if (r == -1)
+      return -1;
+  }
+  {
+    char *r;
+    suppress_error = 0;
+    r = guestfs_checksum (g, "md5", "/upload");
+    if (r == NULL)
+      return -1;
+    if (strcmp (r, "e3eda01d9815f8d24aae2dbd89b68b06") != 0) {
+      fprintf (stderr, "test_download_0: expected \"e3eda01d9815f8d24aae2dbd89b68b06\" but got \"%s\"\n", r);
+      return -1;
+    }
+    free (r);
+  }
+  return 0;
+}
+
+static int test_upload_0 (void)
+{
+  /* InitBasicFS for upload (0): create ext2 on /dev/sda1 */
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_umount_all (g);
+    if (r == -1)
+      return -1;
+  }
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_lvm_remove_all (g);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char *lines[] = {
+      ",",
+      NULL
+    };
+    int r;
+    suppress_error = 0;
+    r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
+    if (r == -1)
+      return -1;
+  }
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_mkfs (g, "ext2", "/dev/sda1");
+    if (r == -1)
+      return -1;
+  }
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_mount (g, "/dev/sda1", "/");
+    if (r == -1)
+      return -1;
+  }
+  /* TestOutput for upload (0) */
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_upload (g, "COPYING.LIB", "/COPYING.LIB");
+    if (r == -1)
+      return -1;
+  }
+  {
+    char *r;
+    suppress_error = 0;
+    r = guestfs_checksum (g, "md5", "/COPYING.LIB");
+    if (r == NULL)
+      return -1;
+    if (strcmp (r, "e3eda01d9815f8d24aae2dbd89b68b06") != 0) {
+      fprintf (stderr, "test_upload_0: expected \"e3eda01d9815f8d24aae2dbd89b68b06\" but got \"%s\"\n", r);
+      return -1;
+    }
+    free (r);
+  }
+  return 0;
+}
+
 static int test_blockdev_rereadpt_0 (void)
 {
   /* InitEmpty for blockdev_rereadpt (0) */
 static int test_blockdev_rereadpt_0 (void)
 {
   /* InitEmpty for blockdev_rereadpt (0) */
@@ -5017,7 +5159,7 @@ int main (int argc, char *argv[])
     exit (1);
   }
 
     exit (1);
   }
 
-  nr_tests = 71;
+  nr_tests = 73;
 
   test_num++;
   printf ("%3d/%3d test_checksum_0\n", test_num, nr_tests);
 
   test_num++;
   printf ("%3d/%3d test_checksum_0\n", test_num, nr_tests);
@@ -5068,6 +5210,18 @@ int main (int argc, char *argv[])
     failed++;
   }
   test_num++;
     failed++;
   }
   test_num++;
+  printf ("%3d/%3d test_download_0\n", test_num, nr_tests);
+  if (test_download_0 () == -1) {
+    printf ("test_download_0 FAILED\n");
+    failed++;
+  }
+  test_num++;
+  printf ("%3d/%3d test_upload_0\n", test_num, nr_tests);
+  if (test_upload_0 () == -1) {
+    printf ("test_upload_0 FAILED\n");
+    failed++;
+  }
+  test_num++;
   printf ("%3d/%3d test_blockdev_rereadpt_0\n", test_num, nr_tests);
   if (test_blockdev_rereadpt_0 () == -1) {
     printf ("test_blockdev_rereadpt_0 FAILED\n");
   printf ("%3d/%3d test_blockdev_rereadpt_0\n", test_num, nr_tests);
   if (test_blockdev_rereadpt_0 () == -1) {
     printf ("test_blockdev_rereadpt_0 FAILED\n");