open-nomad/ui/mirage/factories/agent.js
Buck Doyle 5da134d074
UI: Change Mirage data to be stable in development (#6389)
This sets a default-but-query-configurable Faker seed in development,
via faker-seed. It also changes uses of Math.random to use Faker’s
randomness so auto-generated data remains stable in development.
2019-10-03 09:13:08 -05:00

28 lines
868 B
JavaScript

import { Factory } from 'ember-cli-mirage';
import faker from 'nomad-ui/mirage/faker';
import { provide } from '../utils';
import { DATACENTERS } from '../common';
const UUIDS = provide(100, faker.random.uuid.bind(faker.random));
const AGENT_STATUSES = ['alive', 'leaving', 'left', 'failed'];
export default Factory.extend({
id: i => (i / 100 >= 1 ? `${UUIDS[i]}-${i}` : UUIDS[i]),
name: () => `nomad@${faker.internet.ip()}`,
status: () => faker.helpers.randomize(AGENT_STATUSES),
serf_port: () => faker.random.number({ min: 4000, max: 4999 }),
address() {
return this.name.split('@')[1];
},
tags() {
const rpcPortCandidate = faker.random.number({ min: 4000, max: 4999 });
return {
port: rpcPortCandidate === this.serf_port ? rpcPortCandidate + 1 : rpcPortCandidate,
dc: faker.helpers.randomize(DATACENTERS),
};
},
});