github.com/hernad/nomad@v1.6.112/ui/tests/unit/serializers/job-plan-test.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import { module, test } from 'qunit'; 7 import { setupTest } from 'ember-qunit'; 8 import JobPlanModel from 'nomad-ui/models/job-plan'; 9 10 module('Unit | Serializer | JobPlan', function (hooks) { 11 setupTest(hooks); 12 hooks.beforeEach(function () { 13 this.store = this.owner.lookup('service:store'); 14 this.subject = () => this.store.serializerFor('job-plan'); 15 }); 16 17 const normalizationTestCases = [ 18 { 19 name: 'Normal', 20 in: { 21 ID: 'test-plan', 22 Diff: { 23 Arbitrary: 'Value', 24 }, 25 FailedTGAllocs: { 26 taskGroup: { 27 NodesAvailable: 10, 28 }, 29 }, 30 }, 31 out: { 32 data: { 33 id: 'test-plan', 34 type: 'job-plan', 35 attributes: { 36 diff: { 37 Arbitrary: 'Value', 38 }, 39 failedTGAllocs: [ 40 { 41 name: 'taskGroup', 42 nodesAvailable: 10, 43 }, 44 ], 45 }, 46 relationships: { 47 preemptions: { 48 data: [], 49 }, 50 }, 51 }, 52 }, 53 }, 54 55 { 56 name: 'Dots in task names', 57 in: { 58 ID: 'test-plan', 59 Diff: { 60 Arbitrary: 'Value', 61 }, 62 FailedTGAllocs: { 63 'one.two': { 64 NodesAvailable: 10, 65 }, 66 'three.four': { 67 NodesAvailable: 25, 68 }, 69 }, 70 }, 71 out: { 72 data: { 73 id: 'test-plan', 74 type: 'job-plan', 75 attributes: { 76 diff: { 77 Arbitrary: 'Value', 78 }, 79 failedTGAllocs: [ 80 { 81 name: 'one.two', 82 nodesAvailable: 10, 83 }, 84 { 85 name: 'three.four', 86 nodesAvailable: 25, 87 }, 88 ], 89 }, 90 relationships: { 91 preemptions: { 92 data: [], 93 }, 94 }, 95 }, 96 }, 97 }, 98 99 { 100 name: 'With preemptions', 101 in: { 102 ID: 'test-plan', 103 Diff: { 104 Arbitrary: 'Value', 105 }, 106 FailedTGAllocs: { 107 task: { 108 NodesAvailable: 10, 109 }, 110 }, 111 Annotations: { 112 PreemptedAllocs: [ 113 { ID: 'preemption-one-allocation' }, 114 { ID: 'preemption-two-allocation' }, 115 ], 116 }, 117 }, 118 out: { 119 data: { 120 id: 'test-plan', 121 type: 'job-plan', 122 attributes: { 123 diff: { 124 Arbitrary: 'Value', 125 }, 126 failedTGAllocs: [ 127 { 128 name: 'task', 129 nodesAvailable: 10, 130 }, 131 ], 132 }, 133 relationships: { 134 preemptions: { 135 data: [ 136 { id: 'preemption-one-allocation', type: 'allocation' }, 137 { id: 'preemption-two-allocation', type: 'allocation' }, 138 ], 139 }, 140 }, 141 }, 142 }, 143 }, 144 ]; 145 146 normalizationTestCases.forEach((testCase) => { 147 test(`normalization: ${testCase.name}`, async function (assert) { 148 assert.deepEqual( 149 this.subject().normalize(JobPlanModel, testCase.in), 150 testCase.out 151 ); 152 }); 153 }); 154 });