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
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>
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)
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) */
exit (1);
}
- nr_tests = 71;
+ nr_tests = 73;
test_num++;
printf ("%3d/%3d test_checksum_0\n", test_num, nr_tests);
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");