github.com/hernad/nomad@v1.6.112/ui/tests/unit/serializers/node-pool-test.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import { setupTest } from 'ember-qunit';
     7  import { module, test } from 'qunit';
     8  
     9  module('Unit | Serializer | NodePool', function (hooks) {
    10    setupTest(hooks);
    11  
    12    hooks.beforeEach(function () {
    13      this.store = this.owner.lookup('service:store');
    14      this.subject = () => this.store.serializerFor('node-pool');
    15    });
    16  
    17    test('should serialize a NodePool', function (assert) {
    18      const testCases = [
    19        {
    20          name: 'full node pool',
    21          input: {
    22            name: 'prod-eng',
    23            description: 'Production workloads',
    24            meta: {
    25              env: 'production',
    26              team: 'engineering',
    27            },
    28            schedulerConfiguration: {
    29              SchedulerAlgorithm: 'spread',
    30              MemoryOversubscriptionEnabled: true,
    31            },
    32          },
    33          expected: {
    34            Name: 'prod-eng',
    35            Description: 'Production workloads',
    36            Meta: {
    37              env: 'production',
    38              team: 'engineering',
    39            },
    40            SchedulerConfiguration: {
    41              SchedulerAlgorithm: 'spread',
    42              MemoryOversubscriptionEnabled: true,
    43            },
    44          },
    45        },
    46        {
    47          name: 'node pool without scheduler configuration',
    48          input: {
    49            name: 'prod-eng',
    50            description: 'Production workloads',
    51            meta: {
    52              env: 'production',
    53              team: 'engineering',
    54            },
    55          },
    56          expected: {
    57            Name: 'prod-eng',
    58            Description: 'Production workloads',
    59            Meta: {
    60              env: 'production',
    61              team: 'engineering',
    62            },
    63            SchedulerConfiguration: undefined,
    64          },
    65        },
    66        {
    67          name: 'node pool with null scheduler configuration',
    68          input: {
    69            name: 'prod-eng',
    70            description: 'Production workloads',
    71            meta: {
    72              env: 'production',
    73              team: 'engineering',
    74            },
    75            schedulerConfiguration: null,
    76          },
    77          expected: {
    78            Name: 'prod-eng',
    79            Description: 'Production workloads',
    80            Meta: {
    81              env: 'production',
    82              team: 'engineering',
    83            },
    84            SchedulerConfiguration: null,
    85          },
    86        },
    87        {
    88          name: 'node pool with empty scheduler configuration',
    89          input: {
    90            name: 'prod-eng',
    91            description: 'Production workloads',
    92            meta: {
    93              env: 'production',
    94              team: 'engineering',
    95            },
    96            schedulerConfiguration: {},
    97          },
    98          expected: {
    99            Name: 'prod-eng',
   100            Description: 'Production workloads',
   101            Meta: {
   102              env: 'production',
   103              team: 'engineering',
   104            },
   105            SchedulerConfiguration: {},
   106          },
   107        },
   108      ];
   109  
   110      assert.expect(testCases.length);
   111      for (const tc of testCases) {
   112        const nodePool = this.store.createRecord('node-pool', tc.input);
   113        const got = this.subject().serialize(nodePool._createSnapshot());
   114        assert.deepEqual(
   115          got,
   116          tc.expected,
   117          `${tc.name} failed, got ${JSON.stringify(got)}`
   118        );
   119      }
   120    });
   121  });