github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/unit/serializers/allocation-test.js (about) 1 import { module, test } from 'qunit'; 2 import { setupTest } from 'ember-qunit'; 3 import AllocationModel from 'nomad-ui/models/allocation'; 4 5 module('Unit | Serializer | Allocation', function(hooks) { 6 setupTest(hooks); 7 hooks.beforeEach(function() { 8 this.store = this.owner.lookup('service:store'); 9 this.subject = () => this.store.serializerFor('allocation'); 10 }); 11 12 const sampleDate = new Date('2018-12-12T00:00:00'); 13 const normalizationTestCases = [ 14 { 15 name: 'Normal', 16 in: { 17 ID: 'test-allocation', 18 JobID: 'test-summary', 19 Name: 'test-summary[1]', 20 Namespace: 'test-namespace', 21 TaskGroup: 'test-group', 22 CreateTime: +sampleDate * 1000000, 23 ModifyTime: +sampleDate * 1000000, 24 TaskStates: { 25 testTask: { 26 State: 'running', 27 Failed: false, 28 }, 29 }, 30 }, 31 out: { 32 data: { 33 id: 'test-allocation', 34 type: 'allocation', 35 attributes: { 36 taskGroupName: 'test-group', 37 name: 'test-summary[1]', 38 modifyTime: sampleDate, 39 createTime: sampleDate, 40 states: [ 41 { 42 name: 'testTask', 43 state: 'running', 44 failed: false, 45 }, 46 ], 47 wasPreempted: false, 48 allocationTaskGroup: null, 49 }, 50 relationships: { 51 followUpEvaluation: { 52 data: null, 53 }, 54 nextAllocation: { 55 data: null, 56 }, 57 previousAllocation: { 58 data: null, 59 }, 60 preemptedAllocations: { 61 data: [], 62 }, 63 preemptedByAllocation: { 64 data: null, 65 }, 66 job: { 67 data: { 68 id: '["test-summary","test-namespace"]', 69 type: 'job', 70 }, 71 }, 72 }, 73 }, 74 }, 75 }, 76 77 { 78 name: 'Dots in task names', 79 in: { 80 ID: 'test-allocation', 81 JobID: 'test-summary', 82 Name: 'test-summary[1]', 83 Namespace: 'test-namespace', 84 TaskGroup: 'test-group', 85 CreateTime: +sampleDate * 1000000, 86 ModifyTime: +sampleDate * 1000000, 87 TaskStates: { 88 'one.two': { 89 State: 'running', 90 Failed: false, 91 }, 92 'three.four': { 93 State: 'pending', 94 Failed: true, 95 }, 96 }, 97 }, 98 out: { 99 data: { 100 id: 'test-allocation', 101 type: 'allocation', 102 attributes: { 103 taskGroupName: 'test-group', 104 name: 'test-summary[1]', 105 modifyTime: sampleDate, 106 createTime: sampleDate, 107 states: [ 108 { 109 name: 'one.two', 110 state: 'running', 111 failed: false, 112 }, 113 { 114 name: 'three.four', 115 state: 'pending', 116 failed: true, 117 }, 118 ], 119 wasPreempted: false, 120 allocationTaskGroup: null, 121 }, 122 relationships: { 123 followUpEvaluation: { 124 data: null, 125 }, 126 nextAllocation: { 127 data: null, 128 }, 129 previousAllocation: { 130 data: null, 131 }, 132 preemptedAllocations: { 133 data: [], 134 }, 135 preemptedByAllocation: { 136 data: null, 137 }, 138 job: { 139 data: { 140 id: '["test-summary","test-namespace"]', 141 type: 'job', 142 }, 143 }, 144 }, 145 }, 146 }, 147 }, 148 149 { 150 name: 'With preemptions', 151 in: { 152 ID: 'test-allocation', 153 JobID: 'test-summary', 154 Name: 'test-summary[1]', 155 Namespace: 'test-namespace', 156 TaskGroup: 'test-group', 157 CreateTime: +sampleDate * 1000000, 158 ModifyTime: +sampleDate * 1000000, 159 TaskStates: { 160 task: { 161 State: 'running', 162 Failed: false, 163 }, 164 }, 165 PreemptedByAllocation: 'preempter-allocation', 166 PreemptedAllocations: ['preempted-one-allocation', 'preempted-two-allocation'], 167 }, 168 out: { 169 data: { 170 id: 'test-allocation', 171 type: 'allocation', 172 attributes: { 173 taskGroupName: 'test-group', 174 name: 'test-summary[1]', 175 modifyTime: sampleDate, 176 createTime: sampleDate, 177 states: [ 178 { 179 name: 'task', 180 state: 'running', 181 failed: false, 182 }, 183 ], 184 wasPreempted: true, 185 allocationTaskGroup: null, 186 }, 187 relationships: { 188 followUpEvaluation: { 189 data: null, 190 }, 191 nextAllocation: { 192 data: null, 193 }, 194 previousAllocation: { 195 data: null, 196 }, 197 preemptedAllocations: { 198 data: [ 199 { id: 'preempted-one-allocation', type: 'allocation' }, 200 { id: 'preempted-two-allocation', type: 'allocation' }, 201 ], 202 }, 203 preemptedByAllocation: { 204 data: { 205 id: 'preempter-allocation', 206 type: 'allocation', 207 }, 208 }, 209 job: { 210 data: { 211 id: '["test-summary","test-namespace"]', 212 type: 'job', 213 }, 214 }, 215 }, 216 }, 217 }, 218 }, 219 220 { 221 name: 'Derives task group from embedded job when available', 222 in: { 223 ID: 'test-allocation', 224 JobID: 'test-summary', 225 Name: 'test-summary[1]', 226 Namespace: 'test-namespace', 227 TaskGroup: 'test-group', 228 CreateTime: +sampleDate * 1000000, 229 ModifyTime: +sampleDate * 1000000, 230 TaskStates: { 231 task: { 232 State: 'running', 233 Failed: false, 234 }, 235 }, 236 Job: { 237 ID: 'test-summary', 238 Name: 'test-summary', 239 TaskGroups: [ 240 { 241 Name: 'fake-group', 242 Count: 2, 243 Tasks: [], 244 EphemeralDisk: {}, 245 }, 246 { 247 Name: 'test-group', 248 Count: 3, 249 Tasks: [], 250 EphemeralDisk: {}, 251 }, 252 ], 253 }, 254 }, 255 out: { 256 data: { 257 id: 'test-allocation', 258 type: 'allocation', 259 attributes: { 260 taskGroupName: 'test-group', 261 name: 'test-summary[1]', 262 modifyTime: sampleDate, 263 createTime: sampleDate, 264 states: [ 265 { 266 name: 'task', 267 state: 'running', 268 failed: false, 269 }, 270 ], 271 wasPreempted: false, 272 allocationTaskGroup: { 273 name: 'test-group', 274 count: 3, 275 tasks: [], 276 services: [], 277 volumes: [], 278 }, 279 }, 280 relationships: { 281 followUpEvaluation: { 282 data: null, 283 }, 284 nextAllocation: { 285 data: null, 286 }, 287 previousAllocation: { 288 data: null, 289 }, 290 preemptedAllocations: { 291 data: [], 292 }, 293 preemptedByAllocation: { 294 data: null, 295 }, 296 job: { 297 data: { 298 id: '["test-summary","test-namespace"]', 299 type: 'job', 300 }, 301 }, 302 }, 303 }, 304 }, 305 }, 306 307 { 308 name: 'TaskStates are sorted for stable fragments', 309 in: { 310 ID: 'test-allocation', 311 JobID: 'test-summary', 312 Name: 'test-summary[1]', 313 Namespace: 'test-namespace', 314 TaskGroup: 'test-group', 315 CreateTime: +sampleDate * 1000000, 316 ModifyTime: +sampleDate * 1000000, 317 TaskStates: { 318 xyz: { 319 State: 'running', 320 Failed: false, 321 }, 322 abc: { 323 State: 'running', 324 Failed: false, 325 }, 326 }, 327 }, 328 out: { 329 data: { 330 id: 'test-allocation', 331 type: 'allocation', 332 attributes: { 333 taskGroupName: 'test-group', 334 name: 'test-summary[1]', 335 modifyTime: sampleDate, 336 createTime: sampleDate, 337 states: [ 338 { 339 name: 'abc', 340 state: 'running', 341 failed: false, 342 }, 343 { 344 name: 'xyz', 345 state: 'running', 346 failed: false, 347 }, 348 ], 349 wasPreempted: false, 350 allocationTaskGroup: null, 351 }, 352 relationships: { 353 followUpEvaluation: { 354 data: null, 355 }, 356 nextAllocation: { 357 data: null, 358 }, 359 previousAllocation: { 360 data: null, 361 }, 362 preemptedAllocations: { 363 data: [], 364 }, 365 preemptedByAllocation: { 366 data: null, 367 }, 368 job: { 369 data: { 370 id: '["test-summary","test-namespace"]', 371 type: 'job', 372 }, 373 }, 374 }, 375 }, 376 }, 377 }, 378 ]; 379 380 normalizationTestCases.forEach(testCase => { 381 test(`normalization: ${testCase.name}`, async function(assert) { 382 assert.deepEqual(this.subject().normalize(AllocationModel, testCase.in), testCase.out); 383 }); 384 }); 385 });