github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/unit/serializers/volume-test.js (about)

     1  import { module, test } from 'qunit';
     2  import { setupTest } from 'ember-qunit';
     3  import VolumeModel from 'nomad-ui/models/volume';
     4  
     5  module('Unit | Serializer | Volume', function(hooks) {
     6    setupTest(hooks);
     7    hooks.beforeEach(function() {
     8      this.store = this.owner.lookup('service:store');
     9      this.subject = () => this.store.serializerFor('volume');
    10    });
    11  
    12    // Set the milliseconds to avoid possible floating point precision
    13    // issue that arises from converting to nanos and back.
    14    const REF_DATE = new Date();
    15    REF_DATE.setMilliseconds(0);
    16  
    17    const normalizationTestCases = [
    18      {
    19        name:
    20          '`default` is used as the namespace in the volume ID when there is no namespace in the payload',
    21        in: {
    22          ID: 'volume-id',
    23          Name: 'volume-id',
    24          PluginID: 'plugin-1',
    25          ExternalID: 'external-uuid',
    26          Topologies: {},
    27          AccessMode: 'access-this-way',
    28          AttachmentMode: 'attach-this-way',
    29          Schedulable: true,
    30          Provider: 'abc.123',
    31          Version: '1.0.29',
    32          ControllerRequired: true,
    33          ControllersHealthy: 1,
    34          ControllersExpected: 1,
    35          NodesHealthy: 1,
    36          NodesExpected: 2,
    37          CreateIndex: 1,
    38          ModifyIndex: 38,
    39          WriteAllocs: {},
    40          ReadAllocs: {},
    41        },
    42        out: {
    43          data: {
    44            id: '["csi/volume-id","default"]',
    45            type: 'volume',
    46            attributes: {
    47              plainId: 'volume-id',
    48              name: 'volume-id',
    49              externalId: 'external-uuid',
    50              topologies: {},
    51              accessMode: 'access-this-way',
    52              attachmentMode: 'attach-this-way',
    53              schedulable: true,
    54              provider: 'abc.123',
    55              version: '1.0.29',
    56              controllerRequired: true,
    57              controllersHealthy: 1,
    58              controllersExpected: 1,
    59              nodesHealthy: 1,
    60              nodesExpected: 2,
    61              createIndex: 1,
    62              modifyIndex: 38,
    63            },
    64            relationships: {
    65              plugin: {
    66                data: {
    67                  id: 'csi/plugin-1',
    68                  type: 'plugin',
    69                },
    70              },
    71              readAllocations: {
    72                data: [],
    73              },
    74              writeAllocations: {
    75                data: [],
    76              },
    77            },
    78          },
    79          included: [],
    80        },
    81      },
    82  
    83      {
    84        name: 'The ID of the record is a composite of both the name and the namespace',
    85        in: {
    86          ID: 'volume-id',
    87          Name: 'volume-id',
    88          Namespace: 'namespace-2',
    89          PluginID: 'plugin-1',
    90          ExternalID: 'external-uuid',
    91          Topologies: {},
    92          AccessMode: 'access-this-way',
    93          AttachmentMode: 'attach-this-way',
    94          Schedulable: true,
    95          Provider: 'abc.123',
    96          Version: '1.0.29',
    97          ControllerRequired: true,
    98          ControllersHealthy: 1,
    99          ControllersExpected: 1,
   100          NodesHealthy: 1,
   101          NodesExpected: 2,
   102          CreateIndex: 1,
   103          ModifyIndex: 38,
   104          WriteAllocs: {},
   105          ReadAllocs: {},
   106        },
   107        out: {
   108          data: {
   109            id: '["csi/volume-id","namespace-2"]',
   110            type: 'volume',
   111            attributes: {
   112              plainId: 'volume-id',
   113              name: 'volume-id',
   114              externalId: 'external-uuid',
   115              topologies: {},
   116              accessMode: 'access-this-way',
   117              attachmentMode: 'attach-this-way',
   118              schedulable: true,
   119              provider: 'abc.123',
   120              version: '1.0.29',
   121              controllerRequired: true,
   122              controllersHealthy: 1,
   123              controllersExpected: 1,
   124              nodesHealthy: 1,
   125              nodesExpected: 2,
   126              createIndex: 1,
   127              modifyIndex: 38,
   128            },
   129            relationships: {
   130              plugin: {
   131                data: {
   132                  id: 'csi/plugin-1',
   133                  type: 'plugin',
   134                },
   135              },
   136              namespace: {
   137                data: {
   138                  id: 'namespace-2',
   139                  type: 'namespace',
   140                },
   141              },
   142              readAllocations: {
   143                data: [],
   144              },
   145              writeAllocations: {
   146                data: [],
   147              },
   148            },
   149          },
   150          included: [],
   151        },
   152      },
   153  
   154      {
   155        name:
   156          'Allocations are interpreted as embedded records and are properly normalized into included resources in a JSON API shape',
   157        in: {
   158          ID: 'volume-id',
   159          Name: 'volume-id',
   160          Namespace: 'namespace-2',
   161          PluginID: 'plugin-1',
   162          ExternalID: 'external-uuid',
   163          Topologies: {},
   164          AccessMode: 'access-this-way',
   165          AttachmentMode: 'attach-this-way',
   166          Schedulable: true,
   167          Provider: 'abc.123',
   168          Version: '1.0.29',
   169          ControllerRequired: true,
   170          ControllersHealthy: 1,
   171          ControllersExpected: 1,
   172          NodesHealthy: 1,
   173          NodesExpected: 2,
   174          CreateIndex: 1,
   175          ModifyIndex: 38,
   176          Allocations: [
   177            {
   178              ID: 'alloc-id-1',
   179              TaskGroup: 'foobar',
   180              CreateTime: +REF_DATE * 1000000,
   181              ModifyTime: +REF_DATE * 1000000,
   182              JobID: 'the-job',
   183              Namespace: 'namespace-2',
   184            },
   185            {
   186              ID: 'alloc-id-2',
   187              TaskGroup: 'write-here',
   188              CreateTime: +REF_DATE * 1000000,
   189              ModifyTime: +REF_DATE * 1000000,
   190              JobID: 'the-job',
   191              Namespace: 'namespace-2',
   192            },
   193            {
   194              ID: 'alloc-id-3',
   195              TaskGroup: 'look-if-you-must',
   196              CreateTime: +REF_DATE * 1000000,
   197              ModifyTime: +REF_DATE * 1000000,
   198              JobID: 'the-job',
   199              Namespace: 'namespace-2',
   200            },
   201          ],
   202          WriteAllocs: {
   203            'alloc-id-1': null,
   204            'alloc-id-2': null,
   205          },
   206          ReadAllocs: {
   207            'alloc-id-3': null,
   208          },
   209        },
   210        out: {
   211          data: {
   212            id: '["csi/volume-id","namespace-2"]',
   213            type: 'volume',
   214            attributes: {
   215              plainId: 'volume-id',
   216              name: 'volume-id',
   217              externalId: 'external-uuid',
   218              topologies: {},
   219              accessMode: 'access-this-way',
   220              attachmentMode: 'attach-this-way',
   221              schedulable: true,
   222              provider: 'abc.123',
   223              version: '1.0.29',
   224              controllerRequired: true,
   225              controllersHealthy: 1,
   226              controllersExpected: 1,
   227              nodesHealthy: 1,
   228              nodesExpected: 2,
   229              createIndex: 1,
   230              modifyIndex: 38,
   231            },
   232            relationships: {
   233              plugin: {
   234                data: {
   235                  id: 'csi/plugin-1',
   236                  type: 'plugin',
   237                },
   238              },
   239              namespace: {
   240                data: {
   241                  id: 'namespace-2',
   242                  type: 'namespace',
   243                },
   244              },
   245              readAllocations: {
   246                data: [{ type: 'allocation', id: 'alloc-id-3' }],
   247              },
   248              writeAllocations: {
   249                data: [
   250                  { type: 'allocation', id: 'alloc-id-1' },
   251                  { type: 'allocation', id: 'alloc-id-2' },
   252                ],
   253              },
   254            },
   255          },
   256          included: [
   257            {
   258              id: 'alloc-id-1',
   259              type: 'allocation',
   260              attributes: {
   261                createTime: REF_DATE,
   262                modifyTime: REF_DATE,
   263                taskGroupName: 'foobar',
   264                wasPreempted: false,
   265                states: [],
   266                allocationTaskGroup: null,
   267              },
   268              relationships: {
   269                followUpEvaluation: {
   270                  data: null,
   271                },
   272                job: {
   273                  data: { type: 'job', id: '["the-job","namespace-2"]' },
   274                },
   275                nextAllocation: {
   276                  data: null,
   277                },
   278                previousAllocation: {
   279                  data: null,
   280                },
   281                preemptedAllocations: {
   282                  data: [],
   283                },
   284                preemptedByAllocation: {
   285                  data: null,
   286                },
   287              },
   288            },
   289            {
   290              id: 'alloc-id-2',
   291              type: 'allocation',
   292              attributes: {
   293                createTime: REF_DATE,
   294                modifyTime: REF_DATE,
   295                taskGroupName: 'write-here',
   296                wasPreempted: false,
   297                states: [],
   298                allocationTaskGroup: null,
   299              },
   300              relationships: {
   301                followUpEvaluation: {
   302                  data: null,
   303                },
   304                job: {
   305                  data: { type: 'job', id: '["the-job","namespace-2"]' },
   306                },
   307                nextAllocation: {
   308                  data: null,
   309                },
   310                previousAllocation: {
   311                  data: null,
   312                },
   313                preemptedAllocations: {
   314                  data: [],
   315                },
   316                preemptedByAllocation: {
   317                  data: null,
   318                },
   319              },
   320            },
   321            {
   322              id: 'alloc-id-3',
   323              type: 'allocation',
   324              attributes: {
   325                createTime: REF_DATE,
   326                modifyTime: REF_DATE,
   327                taskGroupName: 'look-if-you-must',
   328                wasPreempted: false,
   329                states: [],
   330                allocationTaskGroup: null,
   331              },
   332              relationships: {
   333                followUpEvaluation: {
   334                  data: null,
   335                },
   336                job: {
   337                  data: { type: 'job', id: '["the-job","namespace-2"]' },
   338                },
   339                nextAllocation: {
   340                  data: null,
   341                },
   342                previousAllocation: {
   343                  data: null,
   344                },
   345                preemptedAllocations: {
   346                  data: [],
   347                },
   348                preemptedByAllocation: {
   349                  data: null,
   350                },
   351              },
   352            },
   353          ],
   354        },
   355      },
   356    ];
   357  
   358    normalizationTestCases.forEach(testCase => {
   359      test(`normalization: ${testCase.name}`, async function(assert) {
   360        assert.deepEqual(this.subject().normalize(VolumeModel, testCase.in), testCase.out);
   361      });
   362    });
   363  });