github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/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 TaskLogs from 'nomad-ui/tests/pages/allocations/task/logs';
     7  
     8  let allocation;
     9  let task;
    10  
    11  module('Acceptance | task logs', function(hooks) {
    12    setupApplicationTest(hooks);
    13    setupMirage(hooks);
    14  
    15    hooks.beforeEach(async function() {
    16      server.create('agent');
    17      server.create('node', 'forceIPv4');
    18      const job = server.create('job', { createAllocations: false });
    19  
    20      allocation = server.create('allocation', { jobId: job.id, clientStatus: 'running' });
    21      task = server.db.taskStates.where({ allocationId: allocation.id })[0];
    22  
    23      run.later(run, run.cancelTimers, 1000);
    24      await TaskLogs.visit({ id: allocation.id, name: task.name });
    25    });
    26  
    27    test('/allocation/:id/:task_name/logs should have a log component', async function(assert) {
    28      assert.equal(currentURL(), `/allocations/${allocation.id}/${task.name}/logs`, 'No redirect');
    29      assert.ok(TaskLogs.hasTaskLog, 'Task log component found');
    30      assert.equal(document.title, `Task ${task.name} logs - Nomad`);
    31    });
    32  
    33    test('the stdout log immediately starts streaming', async function(assert) {
    34      const node = server.db.nodes.find(allocation.nodeId);
    35      const logUrlRegex = new RegExp(`${node.httpAddr}/v1/client/fs/logs/${allocation.id}`);
    36      assert.ok(
    37        server.pretender.handledRequests.filter(req => logUrlRegex.test(req.url)).length,
    38        'Log requests were made'
    39      );
    40    });
    41  });