Parameterize generateResources to enable property overrides

This commit is contained in:
Michael Lange 2020-08-24 09:21:53 -07:00
parent d3b41b0d69
commit f9864930ce

View file

@ -27,10 +27,10 @@ export const STORAGE_PROVIDERS = ['ebs', 'zfs', 'nfs', 'cow', 'moo'];
export function generateResources(options = {}) { export function generateResources(options = {}) {
return { return {
CPU: faker.helpers.randomize(CPU_RESERVATIONS), CPU: options.CPU || faker.helpers.randomize(CPU_RESERVATIONS),
MemoryMB: faker.helpers.randomize(MEMORY_RESERVATIONS), MemoryMB: options.MemoryMB || faker.helpers.randomize(MEMORY_RESERVATIONS),
DiskMB: faker.helpers.randomize(DISK_RESERVATIONS), DiskMB: options.DiskMB || faker.helpers.randomize(DISK_RESERVATIONS),
IOPS: faker.helpers.randomize(IOPS_RESERVATIONS), IOPS: options.IOPS || faker.helpers.randomize(IOPS_RESERVATIONS),
Networks: generateNetworks(options.networks), Networks: generateNetworks(options.networks),
Ports: generatePorts(options.networks), Ports: generatePorts(options.networks),
}; };
@ -73,15 +73,17 @@ export function generateNetworks(options = {}) {
} }
export function generatePorts(options = {}) { export function generatePorts(options = {}) {
return Array(faker.random.number({ return Array(
min: options.minPorts != null ? options.minPorts : 0, faker.random.number({
max: options.maxPorts != null ? options.maxPorts : 2 min: options.minPorts != null ? options.minPorts : 0,
})) max: options.maxPorts != null ? options.maxPorts : 2,
})
)
.fill(null) .fill(null)
.map(() => ({ .map(() => ({
Label: faker.hacker.noun(), Label: faker.hacker.noun(),
Value: faker.random.number({ min: 5000, max: 60000 }), Value: faker.random.number({ min: 5000, max: 60000 }),
To: faker.random.number({ min: 5000, max: 60000 }), To: faker.random.number({ min: 5000, max: 60000 }),
HostIP: faker.random.boolean() ? faker.internet.ip() : faker.internet.ipv6(), HostIP: faker.random.boolean() ? faker.internet.ip() : faker.internet.ipv6(),
})) }));
} }