Welcome to mirror list, hosted at ThFree Co, Russian Federation.

k8s_integration_helper_spec.js « helpers « kubernetes_dashboard « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2892d657aeac18c63d5dbdc4abfda9a0d9bc082b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {
  getAge,
  calculateDeploymentStatus,
  calculateStatefulSetStatus,
  calculateDaemonSetStatus,
} from '~/kubernetes_dashboard/helpers/k8s_integration_helper';
import { useFakeDate } from 'helpers/fake_date';

describe('k8s_integration_helper', () => {
  describe('getAge', () => {
    useFakeDate(2023, 10, 23, 10, 10);

    it.each`
      condition                          | measures     | timestamp                 | expected
      ${'timestamp > 1 day'}             | ${'days'}    | ${'2023-07-31T11:50:59Z'} | ${'114d'}
      ${'timestamp = 1 day'}             | ${'days'}    | ${'2023-11-21T11:50:59Z'} | ${'1d'}
      ${'1 day > timestamp > 1 hour'}    | ${'hours'}   | ${'2023-11-22T11:50:59Z'} | ${'22h'}
      ${'timestamp = 1 hour'}            | ${'hours'}   | ${'2023-11-23T08:50:59Z'} | ${'1h'}
      ${'1 hour > timestamp >1  minute'} | ${'minutes'} | ${'2023-11-23T09:50:59Z'} | ${'19m'}
      ${'timestamp = 1 minute'}          | ${'minutes'} | ${'2023-11-23T10:08:59Z'} | ${'1m'}
      ${'1 minute > timestamp'}          | ${'seconds'} | ${'2023-11-23T10:09:17Z'} | ${'43s'}
      ${'timestamp = 1 second'}          | ${'seconds'} | ${'2023-11-23T10:09:59Z'} | ${'1s'}
    `('returns age in $measures when $condition', ({ timestamp, expected }) => {
      expect(getAge(timestamp)).toBe(expected);
    });
  });

  describe('calculateDeploymentStatus', () => {
    const pending = {
      conditions: [
        { type: 'Available', status: 'False' },
        { type: 'Progressing', status: 'True' },
      ],
    };
    const ready = {
      conditions: [
        { type: 'Available', status: 'True' },
        { type: 'Progressing', status: 'False' },
      ],
    };
    const failed = {
      conditions: [
        { type: 'Available', status: 'False' },
        { type: 'Progressing', status: 'False' },
      ],
    };

    it.each`
      condition                                        | status     | expected
      ${'Available is false and Progressing is true'}  | ${pending} | ${'Pending'}
      ${'Available is true and Progressing is false'}  | ${ready}   | ${'Ready'}
      ${'Available is false and Progressing is false'} | ${failed}  | ${'Failed'}
    `('returns status as $expected when $condition', ({ status, expected }) => {
      expect(calculateDeploymentStatus({ status })).toBe(expected);
    });
  });

  describe('calculateStatefulSetStatus', () => {
    const ready = {
      status: { readyReplicas: 2 },
      spec: { replicas: 2 },
    };
    const failed = {
      status: { readyReplicas: 1 },
      spec: { replicas: 2 },
    };

    it.each`
      condition                                                  | item      | expected
      ${'there are less readyReplicas than replicas in spec'}    | ${failed} | ${'Failed'}
      ${'there are the same amount of readyReplicas as in spec'} | ${ready}  | ${'Ready'}
    `('returns status as $expected when $condition', ({ item, expected }) => {
      expect(calculateStatefulSetStatus(item)).toBe(expected);
    });
  });

  describe('calculateDaemonSetStatus', () => {
    const ready = {
      status: { numberMisscheduled: 0, numberReady: 2, desiredNumberScheduled: 2 },
    };
    const failed = {
      status: { numberMisscheduled: 1, numberReady: 1, desiredNumberScheduled: 2 },
    };

    it.each`
      condition                                                                                        | item      | expected
      ${'there are less numberReady than desiredNumberScheduled or the numberMisscheduled is present'} | ${failed} | ${'Failed'}
      ${'there are the same amount of numberReady and desiredNumberScheduled'}                         | ${ready}  | ${'Ready'}
    `('returns status as $expected when $condition', ({ item, expected }) => {
      expect(calculateDaemonSetStatus(item)).toBe(expected);
    });
  });
});