php: Combine tests to reduce number of launches.

This commit is contained in:
Richard W.M. Jones
2010-11-30 14:17:37 +00:00
parent 2860b21ee1
commit b79e075d63
3 changed files with 40 additions and 65 deletions

View File

@@ -1,5 +1,5 @@
--TEST--
Launch the appliance.
Launch the appliance and run basic tests.
--FILE--
<?php
@@ -11,14 +11,25 @@ if ($g == false) {
echo ("Failed to create guestfs_php handle.\n");
exit;
}
if (guestfs_add_drive ($g, "/dev/null") == false) {
echo ("Error: ".guestfs_last_error ($g)."\n");
exit;
$tmp = dirname(__FILE__)."/test.img";
$size = 100 * 1024 * 1024;
if (! $fp = fopen ($tmp, 'w+')) {
die ("Error: cannot create file '".$tmp."'\n");
}
if (guestfs_launch ($g) == false) {
echo ("Error: ".guestfs_last_error ($g)."\n");
exit;
ftruncate ($fp, $size);
fclose ($fp);
if (! guestfs_add_drive ($g, $tmp) ||
! guestfs_launch ($g) ||
! guestfs_part_disk ($g, "/dev/sda", "mbr") ||
! guestfs_pvcreate ($g, "/dev/sda") ||
! guestfs_vgcreate ($g, "VG", array ("/dev/sda")) ||
! guestfs_lvcreate ($g, "LV", "VG", 64) ||
! guestfs_mkfs ($g, "ext2", "/dev/VG/LV")) {
die ("Error: ".guestfs_last_error ($g)."\n");
}
$version = guestfs_version ($g);
if ($version == false) {
echo ("Error: ".guestfs_last_error ($g)."\n");
@@ -30,6 +41,9 @@ if (!is_int ($version["major"]) ||
!is_string ($version["extra"])) {
echo ("Error: incorrect return type from guestfs_version\n");
}
unlink ($tmp);
echo ("OK\n");
?>
--EXPECT--

View File

@@ -1,5 +1,5 @@
--TEST--
Create a disk containing LV and filesystem.
Check function with optional arguments.
--FILE--
<?php
@@ -8,32 +8,26 @@ Create a disk containing LV and filesystem.
$g = guestfs_create ();
if ($g == false) {
die ("Failed to create guestfs_php handle.\n");
echo ("Failed to create guestfs_php handle.\n");
exit;
}
$tmp = dirname(__FILE__)."/test.img";
$size = 100 * 1024 * 1024;
if (! $fp = fopen ($tmp, 'w+')) {
die ("Error: cannot create file '".$tmp."'\n");
if (guestfs_add_drive_opts ($g, "/dev/null") == false) {
echo ("Failed add_drive_opts, no optional arguments.\n");
exit;
}
ftruncate ($fp, $size);
fclose ($fp);
if (! guestfs_add_drive ($g, "test.img") ||
! guestfs_launch ($g) ||
! guestfs_part_disk ($g, "/dev/sda", "mbr") ||
! guestfs_pvcreate ($g, "/dev/sda") ||
! guestfs_vgcreate ($g, "VG", array ("/dev/sda")) ||
! guestfs_lvcreate ($g, "LV", "VG", 64) ||
! guestfs_mkfs ($g, "ext2", "/dev/VG/LV")) {
die ("Error: ".guestfs_last_error ($g)."\n");
if (guestfs_add_drive_opts ($g, "/dev/null", 0) == false) {
echo ("Failed add_drive_opts, one optional argument.\n");
exit;
}
echo ("OK\n");
?>
--CLEAN--
<?php
$tmp = dirname(__FILE__)."/test.img";
unlink ($tmp);
if (guestfs_add_drive_opts ($g, "/dev/null", 1) == false) {
echo ("Failed add_drive_opts, one optional argument.\n");
exit;
}
if (guestfs_add_drive_opts ($g, "/dev/null", 1, "qcow2") == false) {
echo ("Failed add_drive_opts, two optional arguments.\n");
exit;
}
echo ("Completed tests OK.\n");
?>
--EXPECT--
OK
Completed tests OK.

View File

@@ -1,33 +0,0 @@
--TEST--
Check function with optional arguments.
--FILE--
<?php
// See comment in php/run-php-tests.sh.
//putenv ('LIBGUESTFS_DEBUG=1');
$g = guestfs_create ();
if ($g == false) {
echo ("Failed to create guestfs_php handle.\n");
exit;
}
if (guestfs_add_drive_opts ($g, "/dev/null") == false) {
echo ("Failed add_drive_opts, no optional arguments.\n");
exit;
}
if (guestfs_add_drive_opts ($g, "/dev/null", 0) == false) {
echo ("Failed add_drive_opts, one optional argument.\n");
exit;
}
if (guestfs_add_drive_opts ($g, "/dev/null", 1) == false) {
echo ("Failed add_drive_opts, one optional argument.\n");
exit;
}
if (guestfs_add_drive_opts ($g, "/dev/null", 1, "qcow2") == false) {
echo ("Failed add_drive_opts, two optional arguments.\n");
exit;
}
echo ("Completed tests OK.\n");
?>
--EXPECT--
Completed tests OK.