github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/acceptance/task-logs-test.js (about)

     1  import { currentURL } from '@ember/test-helpers';
     2  import { run } from '@ember/runloop';
     3  import { module, test } from 'qunit';
     4  import { setupApplicationTest } from 'ember-qunit';
     5  import { setupMirage } from 'ember-cli-mirage/test-support';
     6  import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
     7  import TaskLogs from 'nomad-ui/tests/pages/allocations/task/logs';
     8  
     9  let allocation;
    10  let task;
    11  
    12  module('Acceptance | task logs', function(hooks) {
    13    setupApplicationTest(hooks);
    14    setupMirage(hooks);
    15  
    16    hooks.beforeEach(async function() {
    17      server.create('agent');
    18      server.create('node', 'forceIPv4');
    19      const job = server.create('job', { createAllocations: false });
    20  
    21      allocation = server.create('allocation', { jobId: job.id, clientStatus: 'running' });
    22      task = server.db.taskStates.where({ allocationId: allocation.id })[0];
    23  
    24      run.later(run, run.cancelTimers, 1000);
    25      await TaskLogs.visit({ id: allocation.id, name: task.name });
    26    });
    27  
    28    test('it passes an accessibility audit', async function(assert) {
    29      await a11yAudit(assert);
    30    });
    31  
    32    test('/allocation/:id/:task_name/logs should have a log component', async function(assert) {
    33      assert.equal(currentURL(), `/allocations/${allocation.id}/${task.name}/logs`, 'No redirect');
    34      assert.ok(TaskLogs.hasTaskLog, 'Task log component found');
    35      assert.equal(document.title, `Task ${task.name} logs - Nomad`);
    36    });
    37  
    38    test('the stdout log immediately starts streaming', async function(assert) {
    39      const node = server.db.nodes.find(allocation.nodeId);
    40      const logUrlRegex = new RegExp(`${node.httpAddr}/v1/client/fs/logs/${allocation.id}`);
    41      assert.ok(
    42        server.pretender.handledRequests.filter(req => logUrlRegex.test(req.url)).length,
    43        'Log requests were made'
    44      );
    45    });
    46  });