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

k8s_integration_helper_spec.js « helpers « environments « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 97100557ef3d738931cc8b69035539f5038e1597 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import {
  generateServicePortsString,
  getDeploymentsStatuses,
  getDaemonSetStatuses,
  getStatefulSetStatuses,
  getReplicaSetStatuses,
  getJobsStatuses,
  getCronJobsStatuses,
  humanizeClusterErrors,
} from '~/environments/helpers/k8s_integration_helper';

import { CLUSTER_AGENT_ERROR_MESSAGES } from '~/environments/constants';

describe('k8s_integration_helper', () => {
  describe('generateServicePortsString', () => {
    const port = '8080';
    const protocol = 'TCP';
    const nodePort = '31732';

    it('returns empty string if no ports provided', () => {
      expect(generateServicePortsString([])).toBe('');
    });

    it('returns port and protocol when provided', () => {
      expect(generateServicePortsString([{ port, protocol }])).toBe(`${port}/${protocol}`);
    });

    it('returns port, protocol and nodePort when provided', () => {
      expect(generateServicePortsString([{ port, protocol, nodePort }])).toBe(
        `${port}:${nodePort}/${protocol}`,
      );
    });

    it('returns joined strings of ports if multiple are provided', () => {
      expect(
        generateServicePortsString([
          { port, protocol },
          { port, protocol, nodePort },
        ]),
      ).toBe(`${port}/${protocol}, ${port}:${nodePort}/${protocol}`);
    });
  });

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

    it.each`
      condition                              | items                              | expected
      ${'there are only pending items'}      | ${[pending]}                       | ${{ pending: [pending] }}
      ${'there are pending and ready items'} | ${[pending, ready]}                | ${{ pending: [pending], ready: [ready] }}
      ${'there are all kind of items'}       | ${[failed, ready, ready, pending]} | ${{ pending: [pending], failed: [failed], ready: [ready, ready] }}
    `('returns correct object of statuses when $condition', ({ items, expected }) => {
      expect(getDeploymentsStatuses(items)).toEqual(expected);
    });
  });

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

    it.each`
      condition                        | items                             | expected
      ${'there are only failed items'} | ${[failed, anotherFailed]}        | ${{ failed: [failed, anotherFailed] }}
      ${'there are only ready items'}  | ${[ready]}                        | ${{ ready: [ready] }}
      ${'there are all kind of items'} | ${[failed, ready, anotherFailed]} | ${{ failed: [failed, anotherFailed], ready: [ready] }}
    `('returns correct object of statuses when $condition', ({ items, expected }) => {
      expect(getDaemonSetStatuses(items)).toEqual(expected);
    });
  });

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

    it.each`
      condition                        | items                      | expected
      ${'there are only failed items'} | ${[failed, failed]}        | ${{ failed: [failed, failed] }}
      ${'there are only ready items'}  | ${[ready]}                 | ${{ ready: [ready] }}
      ${'there are all kind of items'} | ${[failed, failed, ready]} | ${{ failed: [failed, failed], ready: [ready] }}
    `('returns correct object of statuses when $condition', ({ items, expected }) => {
      expect(getStatefulSetStatuses(items)).toEqual(expected);
    });
  });

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

    it.each`
      condition                        | items                      | expected
      ${'there are only failed items'} | ${[failed, failed]}        | ${{ failed: [failed, failed] }}
      ${'there are only ready items'}  | ${[ready]}                 | ${{ ready: [ready] }}
      ${'there are all kind of items'} | ${[failed, failed, ready]} | ${{ failed: [failed, failed], ready: [ready] }}
    `('returns correct object of statuses when $condition', ({ items, expected }) => {
      expect(getReplicaSetStatuses(items)).toEqual(expected);
    });
  });

  describe('getJobsStatuses', () => {
    const completed = {
      status: {
        succeeded: 1,
      },
      spec: { completions: 1 },
    };
    const failed = {
      status: {
        failed: 1,
      },
      spec: { completions: 2 },
    };

    const anotherFailed = {
      status: {
        succeeded: 1,
      },
      spec: { completions: 2 },
    };

    it.each`
      condition                           | items                                 | expected
      ${'there are only failed items'}    | ${[failed, anotherFailed]}            | ${{ failed: [failed, anotherFailed] }}
      ${'there are only completed items'} | ${[completed]}                        | ${{ completed: [completed] }}
      ${'there are all kind of items'}    | ${[failed, completed, anotherFailed]} | ${{ failed: [failed, anotherFailed], completed: [completed] }}
    `('returns correct object of statuses when $condition', ({ items, expected }) => {
      expect(getJobsStatuses(items)).toEqual(expected);
    });
  });

  describe('getCronJobsStatuses', () => {
    const suspended = {
      spec: { suspend: true },
    };
    const ready = {
      status: {
        active: 2,
        lastScheduleTime: new Date(),
      },
    };
    const failed = {
      status: {
        active: 2,
      },
    };

    it.each`
      condition                                | items                                | expected
      ${'there are only suspended items'}      | ${[suspended]}                       | ${{ suspended: [suspended] }}
      ${'there are suspended and ready items'} | ${[suspended, ready]}                | ${{ suspended: [suspended], ready: [ready] }}
      ${'there are all kind of items'}         | ${[failed, ready, ready, suspended]} | ${{ suspended: [suspended], failed: [failed], ready: [ready, ready] }}
    `('returns correct object of statuses when $condition', ({ items, expected }) => {
      expect(getCronJobsStatuses(items)).toEqual(expected);
    });
  });

  describe('humanizeClusterErrors', () => {
    it.each(['unauthorized', 'forbidden', 'not found', 'other'])(
      'returns correct object of statuses when error reason is %s',
      (reason) => {
        expect(humanizeClusterErrors(reason)).toEqual(CLUSTER_AGENT_ERROR_MESSAGES[reason]);
      },
    );
  });
});