|
| 1 | +import { test } from 'ember-qunit'; |
| 2 | +import AllocationModel from 'nomad-ui/models/allocation'; |
| 3 | +import moduleForSerializer from '../../helpers/module-for-serializer'; |
| 4 | + |
| 5 | +moduleForSerializer('allocation', 'Unit | Serializer | Allocation', { |
| 6 | + needs: [ |
| 7 | + 'service:token', |
| 8 | + 'service:system', |
| 9 | + 'serializer:allocation', |
| 10 | + 'transform:fragment', |
| 11 | + 'transform:fragment-array', |
| 12 | + 'model:job', |
| 13 | + 'model:node', |
| 14 | + 'model:namespace', |
| 15 | + 'model:evaluation', |
| 16 | + 'model:allocation', |
| 17 | + 'model:resources', |
| 18 | + 'model:task-state', |
| 19 | + 'model:reschedule-event', |
| 20 | + ], |
| 21 | +}); |
| 22 | + |
| 23 | +const sampleDate = new Date('2018-12-12T00:00:00'); |
| 24 | +const normalizationTestCases = [ |
| 25 | + { |
| 26 | + name: 'Normal', |
| 27 | + in: { |
| 28 | + ID: 'test-allocation', |
| 29 | + JobID: 'test-summary', |
| 30 | + Name: 'test-summary[1]', |
| 31 | + Namespace: 'test-namespace', |
| 32 | + TaskGroup: 'test-group', |
| 33 | + CreateTime: +sampleDate * 1000000, |
| 34 | + ModifyTime: +sampleDate * 1000000, |
| 35 | + TaskStates: { |
| 36 | + testTask: { |
| 37 | + State: 'running', |
| 38 | + Failed: false, |
| 39 | + }, |
| 40 | + }, |
| 41 | + }, |
| 42 | + out: { |
| 43 | + data: { |
| 44 | + id: 'test-allocation', |
| 45 | + type: 'allocation', |
| 46 | + attributes: { |
| 47 | + taskGroupName: 'test-group', |
| 48 | + name: 'test-summary[1]', |
| 49 | + modifyTime: sampleDate, |
| 50 | + createTime: sampleDate, |
| 51 | + states: [ |
| 52 | + { |
| 53 | + name: 'testTask', |
| 54 | + state: 'running', |
| 55 | + failed: false, |
| 56 | + }, |
| 57 | + ], |
| 58 | + }, |
| 59 | + relationships: { |
| 60 | + followUpEvaluation: { |
| 61 | + data: null, |
| 62 | + }, |
| 63 | + nextAllocation: { |
| 64 | + data: null, |
| 65 | + }, |
| 66 | + previousAllocation: { |
| 67 | + data: null, |
| 68 | + }, |
| 69 | + job: { |
| 70 | + data: { |
| 71 | + id: '["test-summary","test-namespace"]', |
| 72 | + type: 'job', |
| 73 | + }, |
| 74 | + }, |
| 75 | + }, |
| 76 | + }, |
| 77 | + }, |
| 78 | + }, |
| 79 | + |
| 80 | + { |
| 81 | + name: 'Dots in task names', |
| 82 | + in: { |
| 83 | + ID: 'test-allocation', |
| 84 | + JobID: 'test-summary', |
| 85 | + Name: 'test-summary[1]', |
| 86 | + Namespace: 'test-namespace', |
| 87 | + TaskGroup: 'test-group', |
| 88 | + CreateTime: +sampleDate * 1000000, |
| 89 | + ModifyTime: +sampleDate * 1000000, |
| 90 | + TaskStates: { |
| 91 | + 'one.two': { |
| 92 | + State: 'running', |
| 93 | + Failed: false, |
| 94 | + }, |
| 95 | + 'three.four': { |
| 96 | + State: 'pending', |
| 97 | + Failed: true, |
| 98 | + }, |
| 99 | + }, |
| 100 | + }, |
| 101 | + out: { |
| 102 | + data: { |
| 103 | + id: 'test-allocation', |
| 104 | + type: 'allocation', |
| 105 | + attributes: { |
| 106 | + taskGroupName: 'test-group', |
| 107 | + name: 'test-summary[1]', |
| 108 | + modifyTime: sampleDate, |
| 109 | + createTime: sampleDate, |
| 110 | + states: [ |
| 111 | + { |
| 112 | + name: 'one.two', |
| 113 | + state: 'running', |
| 114 | + failed: false, |
| 115 | + }, |
| 116 | + { |
| 117 | + name: 'three.four', |
| 118 | + state: 'pending', |
| 119 | + failed: true, |
| 120 | + }, |
| 121 | + ], |
| 122 | + }, |
| 123 | + relationships: { |
| 124 | + followUpEvaluation: { |
| 125 | + data: null, |
| 126 | + }, |
| 127 | + nextAllocation: { |
| 128 | + data: null, |
| 129 | + }, |
| 130 | + previousAllocation: { |
| 131 | + data: null, |
| 132 | + }, |
| 133 | + job: { |
| 134 | + data: { |
| 135 | + id: '["test-summary","test-namespace"]', |
| 136 | + type: 'job', |
| 137 | + }, |
| 138 | + }, |
| 139 | + }, |
| 140 | + }, |
| 141 | + }, |
| 142 | + }, |
| 143 | +]; |
| 144 | + |
| 145 | +normalizationTestCases.forEach(testCase => { |
| 146 | + test(`normalization: ${testCase.name}`, function(assert) { |
| 147 | + assert.deepEqual(this.subject().normalize(AllocationModel, testCase.in), testCase.out); |
| 148 | + }); |
| 149 | +}); |
0 commit comments