summaryrefslogtreecommitdiff
path: root/buildscripts/tests/resmokelib/test_parser.py
blob: 2e1ff9c9e70060f044d5a9e67b6648c3ad19a3cc (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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
"""Unit tests for buildscripts/resmokelib/parser.py."""

import unittest

from buildscripts.resmokelib.parser import parse, parse_command_line
from buildscripts.resmokelib.run import to_local_args


class TestLocalCommandLine(unittest.TestCase):
    """Unit tests for the to_local_args() function."""

    def test_keeps_any_positional_arguments(self):
        cmdline = to_local_args([
            "run",
            "test_file1.js",
            "test_file2.js",
            "test_file3.js",
            "test_file4.js",
            "--suites=my_suite",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, [
            "run",
            "--suites=my_suite",
            "--storageEngine=my_storage_engine",
            "test_file1.js",
            "test_file2.js",
            "test_file3.js",
            "test_file4.js",
        ])

    def test_keeps_continue_on_failure_option(self):
        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--continueOnFailure",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, [
            "run",
            "--suites=my_suite",
            "--storageEngine=my_storage_engine",
            "--continueOnFailure",
        ])

    def test_keeps_exclude_with_any_tags_option(self):
        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--excludeWithAnyTags=tag1,tag2,tag4",
            "--excludeWithAnyTags=tag3,tag5",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, [
            "run",
            "--suites=my_suite",
            "--storageEngine=my_storage_engine",
            "--excludeWithAnyTags=tag1,tag2,tag4",
            "--excludeWithAnyTags=tag3,tag5",
        ])

    def test_keeps_include_with_any_tags_option(self):
        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--includeWithAnyTags=tag1,tag2,tag4",
            "--includeWithAnyTags=tag3,tag5",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, [
            "run",
            "--suites=my_suite",
            "--storageEngine=my_storage_engine",
            "--includeWithAnyTags=tag1,tag2,tag4",
            "--includeWithAnyTags=tag3,tag5",
        ])

    def test_keeps_num_clients_per_fixture_option(self):
        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--numClientsPerFixture=10",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, [
            "run",
            "--suites=my_suite",
            "--storageEngine=my_storage_engine",
            "--numClientsPerFixture=10",
        ])

    def test_keeps_repeat_options(self):
        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--repeatSuites=1000",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, [
            "run",
            "--suites=my_suite",
            "--storageEngine=my_storage_engine",
            "--repeatSuites=1000",
        ])

        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--repeatTests=1000",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, [
            "run",
            "--suites=my_suite",
            "--storageEngine=my_storage_engine",
            "--repeatTests=1000",
        ])

        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--repeatTestsMax=1000",
            "--repeatTestsMin=20",
            "--repeatTestsSecs=300",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, [
            "run",
            "--suites=my_suite",
            "--storageEngine=my_storage_engine",
            "--repeatTestsMax=1000",
            "--repeatTestsMin=20",
            "--repeatTestsSecs=300.0",
        ])

    def test_keeps_shuffle_option(self):
        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--shuffle",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, [
            "run",
            "--suites=my_suite",
            "--storageEngine=my_storage_engine",
            "--shuffle",
        ])

    def test_keeps_storage_engine_cache_size_option(self):
        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--storageEngineCacheSizeGB=1",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, [
            "run",
            "--suites=my_suite",
            "--storageEngine=my_storage_engine",
            "--storageEngineCacheSizeGB=1",
        ])

    def test_origin_suite_option_replaces_suite_option(self):
        cmdline = to_local_args([
            # We intentionally say --suite rather than --suites here to protect against this command
            # line option from becoming ambiguous if more similarly named command line options are
            # added in the future.
            "run",
            "--suite=part_of_my_suite",
            "--originSuite=my_entire_suite",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline,
                         ["run", "--suites=my_entire_suite", "--storageEngine=my_storage_engine"])

    def test_removes_archival_options(self):
        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--archiveLimitMb=100",
            "--archiveLimitTests=10",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, ["run", "--suites=my_suite", "--storageEngine=my_storage_engine"])

    def test_removes_evergreen_options(self):
        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--buildId=some_build_id",
            "--distroId=some_distro_id",
            "--executionNumber=1",
            "--gitRevision=c0de",
            "--patchBuild",
            "--projectName=some_project",
            "--revisionOrderId=20",
            "--taskName=some_task",
            "--taskId=some_task_id",
            "--variantName=some_variant",
            "--versionId=some_version_id",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, ["run", "--suites=my_suite", "--storageEngine=my_storage_engine"])

    def test_removes_log_option(self):
        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--log=buildlogger",
            "--buildloggerUrl=some_url",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, ["run", "--suites=my_suite", "--storageEngine=my_storage_engine"])

    def test_removes_report_file_options(self):
        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--reportFailureStatus=fail",
            "--reportFile=report.json",
            "--perfReportFile=perf.json",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, ["run", "--suites=my_suite", "--storageEngine=my_storage_engine"])

    def test_removes_stagger_jobs_option(self):
        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--staggerJobs=on",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, ["run", "--suites=my_suite", "--storageEngine=my_storage_engine"])

    def test_removes_tag_file_option(self):
        cmdline = to_local_args([
            "run",
            "--suites=my_suite",
            "--tagFile=etc/test_retrial.yml",
            "--storageEngine=my_storage_engine",
        ])

        self.assertEqual(cmdline, ["run", "--suites=my_suite", "--storageEngine=my_storage_engine"])

    def test_accepts_space_delimited_args(self):
        cmdline = to_local_args([
            "run",
            "--suites",
            "my_suite",
            "--tagFile=etc/test_retrial.yml",
            "--storageEngine",
            "my_storage_engine",
            "--includeWithAnyTags",
            "tag1,tag2,tag4",
            "--includeWithAnyTags",
            "tag3,tag5",
        ])

        self.assertEqual(cmdline, [
            "run",
            "--suites=my_suite",
            "--storageEngine=my_storage_engine",
            "--includeWithAnyTags=tag1,tag2,tag4",
            "--includeWithAnyTags=tag3,tag5",
        ])


class TestParseArgs(unittest.TestCase):
    """Unit tests for the parse() function."""

    def test_files_at_end(self):
        _, args = parse([
            "run",
            "--suites=my_suite1,my_suite2",
            "test_file1.js",
            "test_file2.js",
            "test_file3.js",
        ])

        self.assertEqual(args.test_files, [
            "test_file1.js",
            "test_file2.js",
            "test_file3.js",
        ])
        # suites get split up when config.py gets populated
        self.assertEqual(args.suite_files, "my_suite1,my_suite2")

    def test_files_in_the_middle(self):
        _, args = parse([
            "run",
            "--storageEngine=my_storage_engine",
            "test_file1.js",
            "test_file2.js",
            "test_file3.js",
            "--suites=my_suite1",
        ])

        self.assertEqual(args.test_files, [
            "test_file1.js",
            "test_file2.js",
            "test_file3.js",
        ])
        self.assertEqual(args.suite_files, "my_suite1")


class TestParseCommandLine(unittest.TestCase):
    """Unit tests for the parse_command_line() function."""

    def test_find_suites(self):
        subcommand_obj = parse_command_line(['find-suites'])
        self.assertTrue(hasattr(subcommand_obj, 'execute'))

    def test_list_suites(self):
        subcommand_obj = parse_command_line(['list-suites'])
        self.assertTrue(hasattr(subcommand_obj, 'execute'))

    def test_run(self):
        subcommand_obj = parse_command_line(['run', '--suite=my_suite', 'my_test.js'])
        self.assertTrue(hasattr(subcommand_obj, 'execute'))