test: Add Unit Test for LibvirtVMDef DiskDef

This commit is contained in:
Wido den Hollander 2014-01-22 00:04:03 +01:00
parent c0da0a884a
commit f7ee27cd1c

View File

@ -20,6 +20,7 @@
package com.cloud.hypervisor.kvm.resource;
import junit.framework.TestCase;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef;
public class LibvirtVMDefTest extends TestCase {
@ -65,4 +66,28 @@ public class LibvirtVMDefTest extends TestCase {
}
public void testDiskDef() {
String filePath = "/var/lib/libvirt/images/disk.qcow2";
String diskLabel = "vda";
DiskDef disk = new DiskDef();
DiskDef.diskBus bus = DiskDef.diskBus.VIRTIO;
DiskDef.diskFmtType type = DiskDef.diskFmtType.QCOW2;
DiskDef.diskCacheMode cacheMode = DiskDef.diskCacheMode.WRITEBACK;
disk.defFileBasedDisk(filePath, diskLabel, bus, type);
disk.setCacheMode(cacheMode);
assertEquals(filePath, disk.getDiskPath());
assertEquals(diskLabel, disk.getDiskLabel());
assertEquals(bus, disk.getBusType());
assertEquals(DiskDef.deviceType.DISK, disk.getDeviceType());
String xmlDef = disk.toString();
String expectedXml = "<disk device='disk' type='file'>\n<driver name='qemu' type='" + type.toString() + "' cache='" + cacheMode.toString() + "' />\n" +
"<source file='" + filePath + "'/>\n<target dev='" + diskLabel + "' bus='" + bus.toString() + "'/>\n</disk>\n";
assertEquals(xmlDef, expectedXml);
}
}