github.com/hernad/nomad@v1.6.112/ui/tests/unit/models/allocation-test.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import { run } from '@ember/runloop'; 7 import { module, test } from 'qunit'; 8 import { setupTest } from 'ember-qunit'; 9 10 module('Unit | Model | allocation', function (hooks) { 11 setupTest(hooks); 12 hooks.beforeEach(function () { 13 this.store = this.owner.lookup('service:store'); 14 }); 15 16 test("When the allocation's job version matches the job's version, the task group comes from the job.", function (assert) { 17 const job = run(() => 18 this.store.createRecord('job', { 19 name: 'this-job', 20 version: 1, 21 taskGroups: [ 22 { 23 name: 'from-job', 24 count: 1, 25 task: [], 26 }, 27 ], 28 }) 29 ); 30 31 const allocation = run(() => 32 this.store.createRecord('allocation', { 33 job, 34 jobVersion: 1, 35 taskGroupName: 'from-job', 36 allocationTaskGroup: { 37 name: 'from-allocation', 38 count: 1, 39 task: [], 40 }, 41 }) 42 ); 43 44 assert.equal(allocation.get('taskGroup.name'), 'from-job'); 45 }); 46 47 test("When the allocation's job version does not match the job's version, the task group comes from the alloc.", function (assert) { 48 const job = run(() => 49 this.store.createRecord('job', { 50 name: 'this-job', 51 version: 1, 52 taskGroups: [ 53 { 54 name: 'from-job', 55 count: 1, 56 task: [], 57 }, 58 ], 59 }) 60 ); 61 62 const allocation = run(() => 63 this.store.createRecord('allocation', { 64 job, 65 jobVersion: 2, 66 taskGroupName: 'from-job', 67 allocationTaskGroup: { 68 name: 'from-allocation', 69 count: 1, 70 task: [], 71 }, 72 }) 73 ); 74 75 assert.equal(allocation.get('taskGroup.name'), 'from-allocation'); 76 }); 77 78 test("When the allocation's job version does not match the job's version and the allocation has no task group, then task group is null", async function (assert) { 79 const job = run(() => 80 this.store.createRecord('job', { 81 name: 'this-job', 82 version: 1, 83 taskGroups: [ 84 { 85 name: 'from-job', 86 count: 1, 87 task: [], 88 }, 89 ], 90 }) 91 ); 92 93 const allocation = run(() => 94 this.store.createRecord('allocation', { 95 job, 96 jobVersion: 2, 97 taskGroupName: 'from-job', 98 }) 99 ); 100 101 assert.equal(allocation.get('taskGroup.name'), null); 102 }); 103 });