(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestVMConfig_ParseAndBuild(t *testing.T) { |
| 10 | tests := []struct { |
| 11 | name string |
| 12 | vmType string |
| 13 | input map[string]interface{} |
| 14 | expected *VMConfig |
| 15 | }{ |
| 16 | { |
| 17 | name: "QEMU VM with name", |
| 18 | vmType: VMTypeQemu, |
| 19 | input: map[string]interface{}{ |
| 20 | "name": "test-vm", |
| 21 | "cores": 4.0, |
| 22 | "sockets": 2.0, |
| 23 | "memory": "8192", |
| 24 | "description": "Test VM", |
| 25 | "onboot": 1.0, |
| 26 | "cpu": "host", |
| 27 | "maxmem": 16384.0, |
| 28 | "boot": "order=scsi0;net0", |
| 29 | "agent": "enabled=1,fstrim_cloned_disks=1", |
| 30 | "tags": "prod;db", |
| 31 | "net0": "virtio=AA:BB:CC:DD:EE:FF,bridge=vmbr0,tag=100", |
| 32 | }, |
| 33 | expected: &VMConfig{ |
| 34 | Name: "test-vm", |
| 35 | Cores: 4, |
| 36 | Sockets: 2, |
| 37 | Memory: 8 * 1024 * 1024 * 1024, // 8GB in bytes |
| 38 | Description: "Test VM", |
| 39 | OnBoot: &[]bool{true}[0], |
| 40 | CPUType: "host", |
| 41 | MaxMem: 16384, |
| 42 | BootOrder: "order=scsi0;net0", |
| 43 | Agent: &[]bool{true}[0], |
| 44 | Tags: "prod;db", |
| 45 | TagsExplicit: true, |
| 46 | NetworkInterfaces: map[string]string{ |
| 47 | "net0": "virtio=AA:BB:CC:DD:EE:FF,bridge=vmbr0,tag=100", |
| 48 | }, |
| 49 | }, |
| 50 | }, |
| 51 | { |
| 52 | name: "LXC container with hostname", |
| 53 | vmType: VMTypeLXC, |
| 54 | input: map[string]interface{}{ |
| 55 | "hostname": "test-container", |
| 56 | "cores": 2.0, |
| 57 | "memory": 4096.0, |
| 58 | "description": "Test Container", |
| 59 | "onboot": 0.0, |
| 60 | "swap": 1024.0, |
| 61 | "nameserver": "1.1.1.1 8.8.8.8", |
| 62 | "searchdomain": "lab.local", |
| 63 | "net0": "name=eth0,bridge=vmbr1,ip=dhcp,gw=10.0.0.1", |
| 64 | }, |
| 65 | expected: &VMConfig{ |
| 66 | Hostname: "test-container", |
nothing calls this directly
no test coverage detected