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

utils_spec.js « store « job_details « ci « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6105c53a3067912835283079a6b5d05b26bc3583 (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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
import { logLinesParser } from '~/ci/job_details/store/utils';

import {
  mockJobLines,
  mockEmptySection,
  mockContentSection,
  mockContentSectionClosed,
  mockContentSectionHiddenDuration,
  mockContentSubsection,
  mockTruncatedBottomSection,
  mockTruncatedTopSection,
} from '../components/log/mock_data';

describe('Jobs Store Utils', () => {
  describe('logLinesParser', () => {
    it('parses plain lines', () => {
      const result = logLinesParser(mockJobLines);

      expect(result).toEqual({
        lines: [
          {
            offset: 0,
            content: [
              {
                text: 'Running with gitlab-runner 12.1.0 (de7731dd)',
                style: 'term-fg-l-cyan term-bold',
              },
            ],
            lineNumber: 1,
          },
          {
            offset: 1001,
            content: [{ text: ' on docker-auto-scale-com 8a6210b8' }],
            lineNumber: 2,
          },
        ],
        sections: {},
      });
    });

    it('parses an empty section', () => {
      const result = logLinesParser(mockEmptySection);

      expect(result).toEqual({
        lines: [
          {
            offset: 1002,
            content: [
              {
                text: 'Resolving secrets',
                style: 'term-fg-l-cyan term-bold',
              },
            ],
            lineNumber: 1,
            section: 'resolve-secrets',
            isHeader: true,
          },
        ],
        sections: {
          'resolve-secrets': {
            startLineNumber: 1,
            endLineNumber: 1,
            duration: '00:00',
            isClosed: false,
          },
        },
      });
    });

    it('parses a section with content', () => {
      const result = logLinesParser(mockContentSection);

      expect(result).toEqual({
        lines: [
          {
            content: [{ text: 'Using Docker executor with image dev.gitlab.org3' }],
            isHeader: true,
            lineNumber: 1,
            offset: 1004,
            section: 'prepare-executor',
          },
          {
            content: [{ text: 'Docker executor with image registry.gitlab.com ...' }],
            lineNumber: 2,
            offset: 1005,
            section: 'prepare-executor',
          },
          {
            content: [{ style: 'term-fg-l-green', text: 'Starting service ...' }],
            lineNumber: 3,
            offset: 1006,
            section: 'prepare-executor',
          },
        ],
        sections: {
          'prepare-executor': {
            startLineNumber: 1,
            endLineNumber: 3,
            duration: '00:09',
            isClosed: false,
          },
        },
      });
    });

    it('parses a closed section with content', () => {
      const result = logLinesParser(mockContentSectionClosed);

      expect(result.sections['mock-closed-section']).toMatchObject({
        isClosed: true,
      });
    });

    it('parses a closed section as open when hash is present', () => {
      const result = logLinesParser(mockContentSectionClosed, {}, '#L1');

      expect(result.sections['mock-closed-section']).toMatchObject({
        isClosed: false,
      });
    });

    it('parses a section with a hidden duration', () => {
      const result = logLinesParser(mockContentSectionHiddenDuration);

      expect(result.sections['mock-hidden-duration-section']).toMatchObject({
        hideDuration: true,
        duration: '00:09',
      });
    });

    it('parses a section with a sub section', () => {
      const result = logLinesParser(mockContentSubsection);

      expect(result).toEqual({
        lines: [
          {
            offset: 0,
            content: [{ text: 'Line 1' }],
            lineNumber: 1,
            section: 'mock-section',
            isHeader: true,
          },
          {
            offset: 1002,
            content: [{ text: 'Line 2 - section content' }],
            lineNumber: 2,
            section: 'mock-section',
          },
          {
            offset: 1003,
            content: [{ text: 'Line 3 - sub section header' }],
            lineNumber: 3,
            section: 'sub-section',
            isHeader: true,
          },
          {
            offset: 1004,
            content: [{ text: 'Line 4 - sub section content' }],
            lineNumber: 4,
            section: 'sub-section',
          },
          {
            offset: 1005,
            content: [{ text: 'Line 5 - sub sub section header with no content' }],
            lineNumber: 5,
            section: 'sub-sub-section',
            isHeader: true,
          },
          {
            offset: 1007,
            content: [{ text: 'Line 6 - sub section content 2' }],
            lineNumber: 6,
            section: 'sub-section',
          },
          {
            offset: 1009,
            content: [{ text: 'Line 7 - section content' }],
            lineNumber: 7,
            section: 'mock-section',
          },
          {
            offset: 1011,
            content: [{ text: 'Job succeeded' }],
            lineNumber: 8,
          },
        ],
        sections: {
          'mock-section': {
            startLineNumber: 1,
            endLineNumber: 7,
            duration: '00:59',
            isClosed: false,
          },
          'sub-section': {
            startLineNumber: 3,
            endLineNumber: 6,
            duration: '00:29',
            isClosed: false,
          },
          'sub-sub-section': {
            startLineNumber: 5,
            endLineNumber: 5,
            duration: '00:00',
            isClosed: false,
          },
        },
      });
    });

    it('parsing repeated lines returns the same result', () => {
      const result1 = logLinesParser(mockJobLines);
      const result2 = logLinesParser(mockJobLines, {
        currentLines: result1.lines,
        currentSections: result1.sections,
      });

      // `toBe` is used to ensure objects do not change and trigger Vue reactivity
      expect(result1.lines).toBe(result2.lines);
      expect(result1.sections).toBe(result2.sections);
    });

    it('discards repeated lines and adds new ones', () => {
      const result1 = logLinesParser(mockContentSection);
      const result2 = logLinesParser(
        [
          ...mockContentSection,
          {
            content: [{ text: 'offset is too low, is ignored' }],
            offset: 500,
          },
          {
            content: [{ text: 'one new line' }],
            offset: 1007,
          },
        ],
        {
          currentLines: result1.lines,
          currentSections: result1.sections,
        },
      );

      expect(result2).toEqual({
        lines: [
          {
            content: [{ text: 'Using Docker executor with image dev.gitlab.org3' }],
            isHeader: true,
            lineNumber: 1,
            offset: 1004,
            section: 'prepare-executor',
          },
          {
            content: [{ text: 'Docker executor with image registry.gitlab.com ...' }],
            lineNumber: 2,
            offset: 1005,
            section: 'prepare-executor',
          },
          {
            content: [{ style: 'term-fg-l-green', text: 'Starting service ...' }],
            lineNumber: 3,
            offset: 1006,
            section: 'prepare-executor',
          },
          {
            content: [{ text: 'one new line' }],
            lineNumber: 4,
            offset: 1007,
          },
        ],
        sections: {
          'prepare-executor': {
            startLineNumber: 1,
            endLineNumber: 3,
            duration: '00:09',
            isClosed: false,
          },
        },
      });
    });

    it('parses an interrupted job', () => {
      const result = logLinesParser(mockTruncatedBottomSection);

      expect(result.sections).toEqual({
        'mock-section': {
          startLineNumber: 1,
          endLineNumber: Infinity,
          duration: null,
          isClosed: false,
        },
      });
    });

    it('parses the ending of an incomplete section', () => {
      const result = logLinesParser(mockTruncatedTopSection);

      expect(result.sections).toEqual({
        'mock-section': {
          startLineNumber: 0,
          endLineNumber: 2,
          duration: '00:59',
          isClosed: false,
        },
      });
    });
  });
});