From 44f81118ec412c4945bff0a8cdb7e275a72e7477 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 11 Feb 2022 10:16:23 -0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20host=20fields?= =?UTF-8?q?=20to=20mirage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add host new fields to mirage. --- addons/api/mirage/factories/host.js | 39 +++++++++++++++++++ addons/api/mirage/generated/factories/host.js | 5 +-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/addons/api/mirage/factories/host.js b/addons/api/mirage/factories/host.js index 9386fc15b..ea188f3c4 100644 --- a/addons/api/mirage/factories/host.js +++ b/addons/api/mirage/factories/host.js @@ -1,5 +1,32 @@ import factory from '../generated/factories/host'; import permissions from '../helpers/permissions'; +import { internet, datatype } from 'faker'; + +/** + * Returns an array of strings with IP addresses. + * @returns {array} + */ +const returnIpAddressesArray = () => { + const addressesAmount = Math.floor(Math.random() * 6) + 1; + let result = []; + for (let i = 0; i < addressesAmount; ++i) { + result.push(internet.ip()); + } + return result; +}; + +/** + * Returns an array of strings with DNS names. + * @param {string} hostType + */ +const returnDnsNames = () => { + const dnsNamesAmount = Math.floor(Math.random() * 6) + 1; + let result = []; + for (let i = 0; i < dnsNamesAmount; i++) { + result.push(internet.domainName()); + } + return result; +}; export default factory.extend({ id: (i) => `host-id-${i}`, @@ -18,4 +45,16 @@ export default factory.extend({ return this.hostCatalog.plugin; } }, + attributes() { + return { + address: internet.ipv6(), + ip_addresses: returnIpAddressesArray(), + external_id: datatype.uuid(), + // Only aws plugins have dns_names + dns_names: + this.type != 'static' && this.plugin?.name === 'aws' + ? returnDnsNames() + : undefined, + }; + }, }); diff --git a/addons/api/mirage/generated/factories/host.js b/addons/api/mirage/generated/factories/host.js index db9de3b56..658c334bf 100644 --- a/addons/api/mirage/generated/factories/host.js +++ b/addons/api/mirage/generated/factories/host.js @@ -1,5 +1,5 @@ import { Factory } from 'ember-cli-mirage'; -import { random, date, internet, datatype } from 'faker'; +import { random, date, datatype } from 'faker'; /** * GeneratedHostModelFactory @@ -11,7 +11,4 @@ export default Factory.extend({ created_time: () => date.recent(), updated_time: () => date.recent(), version: () => datatype.number(), - attributes: () => { - return { address: internet.ipv6() }; - }, }); From fe3310ddd1a1987417483419713ff41aeb3644e1 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 11 Feb 2022 13:18:19 -0800 Subject: [PATCH 2/2] Simplify conditional --- addons/api/mirage/factories/host.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/addons/api/mirage/factories/host.js b/addons/api/mirage/factories/host.js index ea188f3c4..93323e965 100644 --- a/addons/api/mirage/factories/host.js +++ b/addons/api/mirage/factories/host.js @@ -51,10 +51,7 @@ export default factory.extend({ ip_addresses: returnIpAddressesArray(), external_id: datatype.uuid(), // Only aws plugins have dns_names - dns_names: - this.type != 'static' && this.plugin?.name === 'aws' - ? returnDnsNames() - : undefined, + dns_names: this.plugin?.name === 'aws' ? returnDnsNames() : undefined, }; }, });