virshtest: Adapt 'snapshot-create-as' arg handling tests from 'virsh-optparse'

Move the argument parsing tests excercising 'virsh snapshot-create-as'
from 'virsh-optparse' to 'virshtest'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2024-03-18 15:38:39 +01:00
parent 1b3f148866
commit 6a2712262e
4 changed files with 92 additions and 60 deletions

View File

@ -32,66 +32,6 @@ fail=0
test_url=test:///default
# Another complex parsing example
cat <<\EOF > exp-out || framework_failure
<domainsnapshot>
<description>1&lt;2</description>
<memory file='d,e'/>
<disks>
<disk name='vda' snapshot='external'>
<source file='a&amp;b,c'/>
</disk>
<disk name='vdb'/>
</disks>
</domainsnapshot>
EOF
$VIRSH -q -c $test_url snapshot-create-as --print-xml test \
--diskspec 'vda,file=a&b,,c,snapshot=external' --description '1<2' \
--diskspec vdb --memspec file=d,,e >out 2>>err || fail=1
compare exp-out out || fail=1
cat <<\EOF > exp-out || framework_failure
<domainsnapshot>
<name>name</name>
<description>vda</description>
<disks>
<disk name='vdb'/>
</disks>
</domainsnapshot>
EOF
$VIRSH -q -c $test_url snapshot-create-as --print-xml test name vda vdb \
>out 2>>err || fail=1
compare exp-out out || fail=1
cat <<\EOF > exp-out || framework_failure
<domainsnapshot>
<name>name</name>
<description>desc</description>
<disks>
<disk name='vda'/>
<disk name='vdb'/>
</disks>
</domainsnapshot>
EOF
for args in \
'test name desc vda vdb' \
'test name desc --diskspec vda vdb' \
'test name desc --diskspec vda --diskspec vdb' \
'test name desc vda vdb' \
'test --diskspec vda name --diskspec vdb desc' \
'--description desc --name name --domain test vda vdb' \
'--description desc --diskspec vda --name name --domain test vdb' \
; do
$VIRSH -q -c $test_url snapshot-create-as --print-xml $args \
>out 2>>err || fail=1
compare exp-out out || fail=1
done
test -s err && fail=1
# Test a required argv
cat <<\EOF > exp-err || framework_failure
error: this function is not supported by the connection driver: virDomainQemuMonitorCommand

View File

@ -200,6 +200,7 @@ mymain(void)
/* comprehensive coverage of argument assignment */
DO_TEST_SCRIPT("argument-assignment", NULL, VIRSH_DEFAULT, "-k0", "-d0");
DO_TEST_SCRIPT("snapshot-create-args", NULL, VIRSH_DEFAULT, "-q");
VIR_FREE(custom_uri);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;

View File

@ -0,0 +1,9 @@
snapshot-create-as --print-xml test name desc vda vdb
snapshot-create-as --print-xml test name desc --diskspec vda vdb
snapshot-create-as --print-xml test name desc --diskspec vda --diskspec vdb
snapshot-create-as --print-xml test name desc vda vdb
snapshot-create-as --print-xml test --diskspec vda name --diskspec vdb desc
snapshot-create-as --print-xml --description desc --name name --domain test vda vdb
snapshot-create-as --print-xml --description desc --diskspec vda --name name --domain test vdb
snapshot-create-as --print-xml test name vda vdb
snapshot-create-as --print-xml test --diskspec vda,file=a&b,,c,snapshot=external --description 1<2 --diskspec vdb --memspec file=d,,e

View File

@ -0,0 +1,82 @@
<domainsnapshot>
<name>name</name>
<description>desc</description>
<disks>
<disk name='vda'/>
<disk name='vdb'/>
</disks>
</domainsnapshot>
<domainsnapshot>
<name>name</name>
<description>desc</description>
<disks>
<disk name='vda'/>
<disk name='vdb'/>
</disks>
</domainsnapshot>
<domainsnapshot>
<name>name</name>
<description>desc</description>
<disks>
<disk name='vda'/>
<disk name='vdb'/>
</disks>
</domainsnapshot>
<domainsnapshot>
<name>name</name>
<description>desc</description>
<disks>
<disk name='vda'/>
<disk name='vdb'/>
</disks>
</domainsnapshot>
<domainsnapshot>
<name>name</name>
<description>desc</description>
<disks>
<disk name='vda'/>
<disk name='vdb'/>
</disks>
</domainsnapshot>
<domainsnapshot>
<name>name</name>
<description>desc</description>
<disks>
<disk name='vda'/>
<disk name='vdb'/>
</disks>
</domainsnapshot>
<domainsnapshot>
<name>name</name>
<description>desc</description>
<disks>
<disk name='vda'/>
<disk name='vdb'/>
</disks>
</domainsnapshot>
<domainsnapshot>
<name>name</name>
<description>vda</description>
<disks>
<disk name='vdb'/>
</disks>
</domainsnapshot>
<domainsnapshot>
<description>1&lt;2</description>
<memory file='d,e'/>
<disks>
<disk name='vda' snapshot='external'>
<source file='a&amp;b,c'/>
</disk>
<disk name='vdb'/>
</disks>
</domainsnapshot>