github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/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          WriteAllocs: {
   177            'alloc-id-1': {
   178              TaskGroup: 'foobar',
   179              CreateTime: +REF_DATE * 1000000,
   180              ModifyTime: +REF_DATE * 1000000,
   181              JobID: 'the-job',
   182              Namespace: 'namespace-2',
   183            },
   184            'alloc-id-2': {
   185              TaskGroup: 'write-here',
   186              CreateTime: +REF_DATE * 1000000,
   187              ModifyTime: +REF_DATE * 1000000,
   188              JobID: 'the-job',
   189              Namespace: 'namespace-2',
   190            },
   191          },
   192          ReadAllocs: {
   193            'alloc-id-3': {
   194              TaskGroup: 'look-if-you-must',
   195              CreateTime: +REF_DATE * 1000000,
   196              ModifyTime: +REF_DATE * 1000000,
   197              JobID: 'the-job',
   198              Namespace: 'namespace-2',
   199            },
   200          },
   201        },
   202        out: {
   203          data: {
   204            id: '["csi/volume-id","namespace-2"]',
   205            type: 'volume',
   206            attributes: {
   207              plainId: 'volume-id',
   208              name: 'volume-id',
   209              externalId: 'external-uuid',
   210              topologies: {},
   211              accessMode: 'access-this-way',
   212              attachmentMode: 'attach-this-way',
   213              schedulable: true,
   214              provider: 'abc.123',
   215              version: '1.0.29',
   216              controllerRequired: true,
   217              controllersHealthy: 1,
   218              controllersExpected: 1,
   219              nodesHealthy: 1,
   220              nodesExpected: 2,
   221              createIndex: 1,
   222              modifyIndex: 38,
   223            },
   224            relationships: {
   225              plugin: {
   226                data: {
   227                  id: 'csi/plugin-1',
   228                  type: 'plugin',
   229                },
   230              },
   231              namespace: {
   232                data: {
   233                  id: 'namespace-2',
   234                  type: 'namespace',
   235                },
   236              },
   237              readAllocations: {
   238                data: [{ type: 'allocation', id: 'alloc-id-3' }],
   239              },
   240              writeAllocations: {
   241                data: [
   242                  { type: 'allocation', id: 'alloc-id-1' },
   243                  { type: 'allocation', id: 'alloc-id-2' },
   244                ],
   245              },
   246            },
   247          },
   248          included: [
   249            {
   250              id: 'alloc-id-1',
   251              type: 'allocation',
   252              attributes: {
   253                createTime: REF_DATE,
   254                modifyTime: REF_DATE,
   255                taskGroupName: 'foobar',
   256                wasPreempted: false,
   257                states: [],
   258                allocationTaskGroup: null,
   259              },
   260              relationships: {
   261                followUpEvaluation: {
   262                  data: null,
   263                },
   264                job: {
   265                  data: { type: 'job', id: '["the-job","namespace-2"]' },
   266                },
   267                nextAllocation: {
   268                  data: null,
   269                },
   270                previousAllocation: {
   271                  data: null,
   272                },
   273                preemptedAllocations: {
   274                  data: [],
   275                },
   276                preemptedByAllocation: {
   277                  data: null,
   278                },
   279              },
   280            },
   281            {
   282              id: 'alloc-id-2',
   283              type: 'allocation',
   284              attributes: {
   285                createTime: REF_DATE,
   286                modifyTime: REF_DATE,
   287                taskGroupName: 'write-here',
   288                wasPreempted: false,
   289                states: [],
   290                allocationTaskGroup: null,
   291              },
   292              relationships: {
   293                followUpEvaluation: {
   294                  data: null,
   295                },
   296                job: {
   297                  data: { type: 'job', id: '["the-job","namespace-2"]' },
   298                },
   299                nextAllocation: {
   300                  data: null,
   301                },
   302                previousAllocation: {
   303                  data: null,
   304                },
   305                preemptedAllocations: {
   306                  data: [],
   307                },
   308                preemptedByAllocation: {
   309                  data: null,
   310                },
   311              },
   312            },
   313            {
   314              id: 'alloc-id-3',
   315              type: 'allocation',
   316              attributes: {
   317                createTime: REF_DATE,
   318                modifyTime: REF_DATE,
   319                taskGroupName: 'look-if-you-must',
   320                wasPreempted: false,
   321                states: [],
   322                allocationTaskGroup: null,
   323              },
   324              relationships: {
   325                followUpEvaluation: {
   326                  data: null,
   327                },
   328                job: {
   329                  data: { type: 'job', id: '["the-job","namespace-2"]' },
   330                },
   331                nextAllocation: {
   332                  data: null,
   333                },
   334                previousAllocation: {
   335                  data: null,
   336                },
   337                preemptedAllocations: {
   338                  data: [],
   339                },
   340                preemptedByAllocation: {
   341                  data: null,
   342                },
   343              },
   344            },
   345          ],
   346        },
   347      },
   348    ];
   349  
   350    normalizationTestCases.forEach(testCase => {
   351      test(`normalization: ${testCase.name}`, async function(assert) {
   352        assert.deepEqual(this.subject().normalize(VolumeModel, testCase.in), testCase.out);
   353      });
   354    });
   355  });