-
Notifications
You must be signed in to change notification settings - Fork 18
/
freebsd.spec.ts
140 lines (121 loc) · 3.86 KB
/
freebsd.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import {basename} from 'path'
import FreeBsd from '../../../src/operating_systems/freebsd/freebsd'
import * as hostModule from '../../../src/host'
import * as arch from '../../../src/architecture'
import * as os from '../../../src/operating_systems/kind'
import {Accelerator} from '../../../src/vm'
import HostQemu from '../../../src/host_qemu'
import * as hypervisor from '../../../src/hypervisor'
import * as qemu from '../../../src/qemu_vm'
import * as xhyve from '../../../src/xhyve_vm'
import {Input} from '../../../src/action/input'
describe('FreeBSD OperatingSystem', () => {
class MockHost extends hostModule.Host {
get vmModule(): typeof xhyve | typeof qemu {
return qemu
}
override get qemu(): HostQemu {
return new HostQemu.LinuxHostQemu()
}
override get hypervisor(): hypervisor.Hypervisor {
return new hypervisor.Qemu()
}
override get efiHypervisor(): hypervisor.Hypervisor {
return new hypervisor.QemuEfi()
}
override get defaultMemory(): string {
return '6G'
}
override get defaultCpuCount(): number {
return 6
}
override validateHypervisor(_kind: hypervisor.Kind): void {}
}
let host = new MockHost()
let osKind = os.Kind.for('freebsd')
let vmm = host.hypervisor
let architecture = arch.Architecture.for(arch.Kind.x86_64, host, osKind, vmm)
let freebsd = new FreeBsd(architecture, '0.0.0')
let hypervisorDirectory = 'hypervisor/directory'
let resourcesDirectory = 'resources/directory'
let firmwareDirectory = 'firmware/directory'
let input = new Input()
let config = {
memory: '4G',
cpuCount: 7,
diskImage: '',
resourcesDiskImage: '',
userboot: ''
}
describe('createVirtualMachine', () => {
let vmModule = jasmine.createSpy('vmModule')
beforeEach(() => {
spyOn(hostModule, 'getHost').and.returnValue(host)
})
it('creates a virtual machine with the correct configuration', () => {
spyOn(vmm, 'resolve').and.returnValue(vmModule)
freebsd.createVirtualMachine(
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
input,
config
)
expect(vmModule).toHaveBeenCalledOnceWith(
hypervisorDirectory,
resourcesDirectory,
architecture,
input,
{
...config,
ssHostPort: 2847,
cpu: 'max',
accelerator: Accelerator.tcg,
machineType: 'q35',
uuid: '864ED7F0-7876-4AA7-8511-816FABCFA87F',
firmware: `${firmwareDirectory}/share/qemu/bios-256k.bin`
}
)
})
describe('when the given hypervisor is Xhyve', () => {
it('creates a virtual machine using the Xhyve hypervisor', () => {
let archObject = arch.Architecture.for(
arch.Kind.x86_64,
host,
osKind,
new hypervisor.Xhyve()
)
let freebsd = new FreeBsd(archObject, '0.0.0')
const vm = freebsd.createVirtualMachine(
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
input,
config
)
const hypervisorBinary = basename(vm.hypervisorPath.toString())
expect(hypervisorBinary).toEqual('xhyve')
})
})
describe('when the given hypervisor is Qemu', () => {
it('creates a virtual machine using the Qemu hypervisor', () => {
let archObject = arch.Architecture.for(
arch.Kind.x86_64,
host,
osKind,
new hypervisor.Qemu()
)
let freebsd = new FreeBsd(archObject, '0.0.0')
const vm = freebsd.createVirtualMachine(
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
input,
config
)
const hypervisorBinary = basename(vm.hypervisorPath.toString())
expect(hypervisorBinary).toEqual('qemu')
})
})
})
})