summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-04-20 13:14:07 +0100
committerRichard Jones <rjones@redhat.com>2009-04-20 13:14:07 +0100
commitc5d37435aa9e257fac1c2d517fadc7630fa0d869 (patch)
tree28b59f9c2354ab14e1d526dae79145a81458c74b
parent469c6cdfd5f2ffb07eaf01c16a21ed1e5cb174c1 (diff)
downloadlibguestfs-c5d37435aa9e257fac1c2d517fadc7630fa0d869.tar.gz
libguestfs-c5d37435aa9e257fac1c2d517fadc7630fa0d869.tar.xz
libguestfs-c5d37435aa9e257fac1c2d517fadc7630fa0d869.zip
Add tests for the upload and download commands.
-rw-r--r--.gitignore1
-rwxr-xr-xsrc/generator.ml12
-rw-r--r--tests.c160
3 files changed, 168 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index 174489e0..e41c0767 100644
--- a/.gitignore
+++ b/.gitignore
@@ -69,6 +69,7 @@ ruby/ext/guestfs/mkmf.log
pod2htm?.tmp
stamp-h1
test*.img
+test*.tmp
tests
update-initramfs.sh
vmlinuz.*
diff --git a/src/generator.ml b/src/generator.ml
index 191b94df..ae1dfe9f 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -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, [],
- [],
+ [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
@@ -1284,7 +1287,12 @@ C<filename> can also be a named pipe.
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>
diff --git a/tests.c b/tests.c
index 9744575f..876cc29e 100644
--- 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_upload\" has no tests\n");
- fprintf (stderr, "warning: \"guestfs_download\" has no tests\n");
}
static int test_checksum_0 (void)
@@ -614,6 +612,150 @@ static int test_checksum_7 (void)
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) */
@@ -5017,7 +5159,7 @@ int main (int argc, char *argv[])
exit (1);
}
- nr_tests = 71;
+ nr_tests = 73;
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++;
+ 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");