def test_main_yaml(mock_getfqdn, mock_parse_args, tmpdir, mock_namespaces): services_file = tmpdir.join('services.yaml') fake_args = mock.Mock() fake_args.output_format = 'yaml' fake_args.output_filename = services_file.strpath mock_parse_args.return_value = fake_args expected_value = ( '# This file is automatically generated by paasta_tools.\n' '# It was automatically generated at $TIME on somehost.yelp.\n' '---\n' 'bar.canary:\n' ' host: 169.254.255.254\n' ' port: 1025\n' 'foo.main:\n' ' host: 169.254.255.254\n' ' port: 1024\n') with mock.patch.object(generate_services_file, 'datetime') as m: m.now().isoformat.return_value = '$TIME' generate_services_file.main() assert services_file.read() == expected_value # If the only difference is the timestamp, the file should not be regenerated. with mock.patch.object(generate_services_file, 'datetime') as m: m.now().isoformat.return_value = '$TIME+1' generate_services_file.main() assert services_file.read() == expected_value
def test_main_json(mock_parse_args, tmpdir, mock_namespaces): services_file = tmpdir.join('services.json') fake_args = mock.Mock() fake_args.output_format = 'json' fake_args.output_filename = services_file.strpath mock_parse_args.return_value = fake_args generate_services_file.main() assert services_file.read() == """{
def test_main_json(mock_parse_args, tmpdir, mock_namespaces): services_file = tmpdir.join("services.json") fake_args = mock.Mock() fake_args.output_format = "json" fake_args.output_filename = services_file.strpath mock_parse_args.return_value = fake_args generate_services_file.main() assert (services_file.read() == """{ "bar.canary": { "host": "169.254.255.254", "port": 1025 }, "foo.main": { "host": "169.254.255.254", "port": 1024 } }""")