2019-03-14 02:17:12 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
2018-12-13 02:40:10 +00:00
|
|
|
import JobPlanModel from 'nomad-ui/models/job-plan';
|
|
|
|
|
2019-03-14 02:17:12 +00:00
|
|
|
module('Unit | Serializer | JobPlan', function(hooks) {
|
|
|
|
setupTest(hooks);
|
|
|
|
hooks.beforeEach(function() {
|
|
|
|
this.store = this.owner.lookup('service:store');
|
|
|
|
this.subject = () => this.store.serializerFor('job-plan');
|
|
|
|
});
|
2018-12-13 02:40:10 +00:00
|
|
|
|
2019-03-14 02:17:12 +00:00
|
|
|
const normalizationTestCases = [
|
|
|
|
{
|
|
|
|
name: 'Normal',
|
|
|
|
in: {
|
|
|
|
ID: 'test-plan',
|
|
|
|
Diff: {
|
|
|
|
Arbitrary: 'Value',
|
2018-12-13 02:40:10 +00:00
|
|
|
},
|
2019-03-14 02:17:12 +00:00
|
|
|
FailedTGAllocs: {
|
|
|
|
taskGroup: {
|
|
|
|
NodesAvailable: 10,
|
2018-12-13 02:40:10 +00:00
|
|
|
},
|
2019-03-14 02:17:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
out: {
|
|
|
|
data: {
|
|
|
|
id: 'test-plan',
|
|
|
|
type: 'job-plan',
|
|
|
|
attributes: {
|
|
|
|
diff: {
|
|
|
|
Arbitrary: 'Value',
|
2018-12-13 02:40:10 +00:00
|
|
|
},
|
2019-03-14 02:17:12 +00:00
|
|
|
failedTGAllocs: [
|
|
|
|
{
|
|
|
|
name: 'taskGroup',
|
|
|
|
nodesAvailable: 10,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-04-23 00:20:52 +00:00
|
|
|
relationships: {
|
|
|
|
preemptions: {
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
},
|
2018-12-13 02:40:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-03-14 02:17:12 +00:00
|
|
|
{
|
|
|
|
name: 'Dots in task names',
|
|
|
|
in: {
|
|
|
|
ID: 'test-plan',
|
|
|
|
Diff: {
|
|
|
|
Arbitrary: 'Value',
|
2018-12-13 02:40:10 +00:00
|
|
|
},
|
2019-03-14 02:17:12 +00:00
|
|
|
FailedTGAllocs: {
|
|
|
|
'one.two': {
|
|
|
|
NodesAvailable: 10,
|
|
|
|
},
|
|
|
|
'three.four': {
|
|
|
|
NodesAvailable: 25,
|
|
|
|
},
|
2018-12-13 02:40:10 +00:00
|
|
|
},
|
|
|
|
},
|
2019-03-14 02:17:12 +00:00
|
|
|
out: {
|
|
|
|
data: {
|
|
|
|
id: 'test-plan',
|
|
|
|
type: 'job-plan',
|
|
|
|
attributes: {
|
|
|
|
diff: {
|
|
|
|
Arbitrary: 'Value',
|
2018-12-13 02:40:10 +00:00
|
|
|
},
|
2019-03-14 02:17:12 +00:00
|
|
|
failedTGAllocs: [
|
|
|
|
{
|
|
|
|
name: 'one.two',
|
|
|
|
nodesAvailable: 10,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'three.four',
|
|
|
|
nodesAvailable: 25,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-04-23 00:20:52 +00:00
|
|
|
relationships: {
|
|
|
|
preemptions: {
|
|
|
|
data: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
name: 'With preemptions',
|
|
|
|
in: {
|
|
|
|
ID: 'test-plan',
|
|
|
|
Diff: {
|
|
|
|
Arbitrary: 'Value',
|
|
|
|
},
|
|
|
|
FailedTGAllocs: {
|
|
|
|
task: {
|
|
|
|
NodesAvailable: 10,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Annotations: {
|
|
|
|
PreemptedAllocs: [
|
|
|
|
{ ID: 'preemption-one-allocation' },
|
|
|
|
{ ID: 'preemption-two-allocation' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: {
|
|
|
|
data: {
|
|
|
|
id: 'test-plan',
|
|
|
|
type: 'job-plan',
|
|
|
|
attributes: {
|
|
|
|
diff: {
|
|
|
|
Arbitrary: 'Value',
|
|
|
|
},
|
|
|
|
failedTGAllocs: [
|
|
|
|
{
|
|
|
|
name: 'task',
|
|
|
|
nodesAvailable: 10,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
relationships: {
|
|
|
|
preemptions: {
|
|
|
|
data: [
|
|
|
|
{ id: 'preemption-one-allocation', type: 'allocation' },
|
|
|
|
{ id: 'preemption-two-allocation', type: 'allocation' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2018-12-13 02:40:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-03-14 02:17:12 +00:00
|
|
|
];
|
2018-12-13 02:40:10 +00:00
|
|
|
|
2019-03-14 02:17:12 +00:00
|
|
|
normalizationTestCases.forEach(testCase => {
|
2019-03-14 18:35:46 +00:00
|
|
|
test(`normalization: ${testCase.name}`, async function(assert) {
|
2019-03-14 02:17:12 +00:00
|
|
|
assert.deepEqual(this.subject().normalize(JobPlanModel, testCase.in), testCase.out);
|
|
|
|
});
|
2018-12-13 02:40:10 +00:00
|
|
|
});
|
|
|
|
});
|