| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import argparse | 5 import argparse |
| 6 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import requests | 8 import requests |
| 9 import tempfile | 9 import tempfile |
| 10 import unittest | 10 import unittest |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 config.add_argparse_options(p) | 297 config.add_argparse_options(p) |
| 298 args = p.parse_args(['--ts-mon-credentials', '/path/to/creds.p8.json', | 298 args = p.parse_args(['--ts-mon-credentials', '/path/to/creds.p8.json', |
| 299 '--ts-mon-target-type', 'task', | 299 '--ts-mon-target-type', 'task', |
| 300 '--ts-mon-task-service-name', 'serv', | 300 '--ts-mon-task-service-name', 'serv', |
| 301 '--ts-mon-task-region', 'reg', | 301 '--ts-mon-task-region', 'reg', |
| 302 '--ts-mon-task-hostname', 'host', | 302 '--ts-mon-task-hostname', 'host', |
| 303 '--ts-mon-task-number', '1']) | 303 '--ts-mon-task-number', '1']) |
| 304 with self.assertRaises(SystemExit): | 304 with self.assertRaises(SystemExit): |
| 305 config.process_argparse_options(args) | 305 config.process_argparse_options(args) |
| 306 | 306 |
| 307 def test_metric_name_prefix(self): |
| 308 p = argparse.ArgumentParser() |
| 309 config.add_argparse_options(p) |
| 310 args = p.parse_args(['--ts-mon-metric-name-prefix', '/test/random/']) |
| 311 config.process_argparse_options(args) |
| 312 self.assertEqual('/test/random/', interface.state.metric_name_prefix) |
| 313 |
| 307 @mock.patch('infra_libs.ts_mon.common.monitors.NullMonitor', autospec=True) | 314 @mock.patch('infra_libs.ts_mon.common.monitors.NullMonitor', autospec=True) |
| 308 def test_no_args(self, fake_monitor): | 315 def test_no_args(self, fake_monitor): |
| 309 singleton = mock.Mock() | 316 singleton = mock.Mock() |
| 310 fake_monitor.return_value = singleton | 317 fake_monitor.return_value = singleton |
| 311 p = argparse.ArgumentParser() | 318 p = argparse.ArgumentParser() |
| 312 config.add_argparse_options(p) | 319 config.add_argparse_options(p) |
| 313 args = p.parse_args([]) | 320 args = p.parse_args([]) |
| 314 config.process_argparse_options(args) | 321 config.process_argparse_options(args) |
| 315 self.assertEqual(1, len(fake_monitor.mock_calls)) | 322 self.assertEqual(1, len(fake_monitor.mock_calls)) |
| 323 self.assertEqual('/chrome/infra/', interface.state.metric_name_prefix) |
| 316 self.assertIs(interface.state.global_monitor, singleton) | 324 self.assertIs(interface.state.global_monitor, singleton) |
| 317 | 325 |
| 318 @mock.patch('requests.get', autospec=True) | 326 @mock.patch('requests.get', autospec=True) |
| 319 def test_gce_region(self, mock_get): | 327 def test_gce_region(self, mock_get): |
| 320 r = mock_get.return_value | 328 r = mock_get.return_value |
| 321 r.status_code = 200 | 329 r.status_code = 200 |
| 322 r.text = 'projects/182615506979/zones/us-central1-f' | 330 r.text = 'projects/182615506979/zones/us-central1-f' |
| 323 | 331 |
| 324 self.assertEquals('us-central1-f', config._default_region('foo.golo')) | 332 self.assertEquals('us-central1-f', config._default_region('foo.golo')) |
| 325 | 333 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 350 with infra_libs.temporary_directory() as temp_dir: | 358 with infra_libs.temporary_directory() as temp_dir: |
| 351 filename = os.path.join(temp_dir, 'config') | 359 filename = os.path.join(temp_dir, 'config') |
| 352 with open(filename, 'w') as fh: | 360 with open(filename, 'w') as fh: |
| 353 fh.write('not a json file') | 361 fh.write('not a json file') |
| 354 | 362 |
| 355 with self.assertRaises(ValueError): | 363 with self.assertRaises(ValueError): |
| 356 config.load_machine_config(filename) | 364 config.load_machine_config(filename) |
| 357 | 365 |
| 358 def test_load_machine_config_not_exists(self): | 366 def test_load_machine_config_not_exists(self): |
| 359 self.assertEquals({}, config.load_machine_config('does not exist')) | 367 self.assertEquals({}, config.load_machine_config('does not exist')) |
| OLD | NEW |