def test_list_clusters_no_service_given_lists_all_of_them(): fake_soa_dir = "/nail/etc/services" fake_cluster_configs = [ "/nail/etc/services/service1/marathon-cluster1.yaml", "/nail/etc/services/service2/chronos-cluster2.yaml", ] expected = ["cluster1", "cluster2"] with contextlib.nested( mock.patch("os.path.join", autospec=True, return_value="%s/*" % fake_soa_dir), mock.patch("glob.glob", autospec=True, return_value=fake_cluster_configs), ) as (mock_join_path, mock_glob): actual = utils.list_clusters(soa_dir=fake_soa_dir) assert actual == expected mock_join_path.assert_called_once_with(fake_soa_dir, "*") mock_glob.assert_called_once_with("%s/*/*.yaml" % fake_soa_dir)
def test_list_clusters_no_service_given_lists_all_of_them(): fake_soa_dir = '/nail/etc/services' fake_cluster_configs = ['/nail/etc/services/service1/marathon-cluster1.yaml', '/nail/etc/services/service2/chronos-cluster2.yaml'] expected = ['cluster1', 'cluster2'] with contextlib.nested( mock.patch('os.path.join', autospec=True, return_value='%s/*' % fake_soa_dir), mock.patch('glob.glob', autospec=True, return_value=fake_cluster_configs), ) as ( mock_join_path, mock_glob, ): actual = utils.list_clusters(soa_dir=fake_soa_dir) assert actual == expected mock_join_path.assert_called_once_with(fake_soa_dir, '*') mock_glob.assert_called_once_with('%s/*/*.yaml' % fake_soa_dir)
def test_list_clusters_ignores_bogus_clusters(): fake_soa_dir = "/nail/etc/services" fake_service = "fake_service" fake_cluster_configs = [ "/nail/etc/services/service1/marathon-cluster1.yaml", "/nail/etc/services/service1/marathon-PROD.yaml", "/nail/etc/services/service1/chronos-cluster2.yaml", "/nail/etc/services/service1/chronos-SHARED.yaml", ] expected = ["cluster1", "cluster2"] with contextlib.nested( mock.patch("os.path.join", autospec=True, return_value="%s/%s" % (fake_soa_dir, fake_service)), mock.patch("glob.glob", autospec=True, return_value=fake_cluster_configs), ) as (mock_join_path, mock_glob): actual = utils.list_clusters(service=fake_service) assert actual == expected
def test_list_clusters_ignores_bogus_clusters(): fake_soa_dir = '/nail/etc/services' fake_service = 'fake_service' fake_cluster_configs = ['/nail/etc/services/service1/marathon-cluster1.yaml', '/nail/etc/services/service1/marathon-PROD.yaml', '/nail/etc/services/service1/chronos-cluster2.yaml', '/nail/etc/services/service1/chronos-SHARED.yaml'] expected = ['cluster1', 'cluster2'] with contextlib.nested( mock.patch('os.path.join', autospec=True, return_value='%s/%s' % (fake_soa_dir, fake_service)), mock.patch('glob.glob', autospec=True, return_value=fake_cluster_configs), ) as ( mock_join_path, mock_glob, ): actual = utils.list_clusters(service=fake_service) assert actual == expected
def test_list_clusters_no_service_given_lists_all_of_them(): fake_soa_dir = '/nail/etc/services' fake_cluster_configs = [ '/nail/etc/services/service1/marathon-cluster1.yaml', '/nail/etc/services/service2/chronos-cluster2.yaml' ] expected = ['cluster1', 'cluster2'] with contextlib.nested( mock.patch('os.path.join', autospec=True, return_value='%s/*' % fake_soa_dir), mock.patch('glob.glob', autospec=True, return_value=fake_cluster_configs), ) as ( mock_join_path, mock_glob, ): actual = utils.list_clusters(soa_dir=fake_soa_dir) assert actual == expected mock_join_path.assert_called_once_with(fake_soa_dir, '*') mock_glob.assert_called_once_with('%s/*/*.yaml' % fake_soa_dir)
def test_list_clusters_ignores_bogus_clusters(): fake_soa_dir = '/nail/etc/services' fake_service = 'fake_service' fake_cluster_configs = [ '/nail/etc/services/service1/marathon-cluster1.yaml', '/nail/etc/services/service1/marathon-PROD.yaml', '/nail/etc/services/service1/chronos-cluster2.yaml', '/nail/etc/services/service1/chronos-SHARED.yaml' ] expected = ['cluster1', 'cluster2'] with contextlib.nested( mock.patch('os.path.join', autospec=True, return_value='%s/%s' % (fake_soa_dir, fake_service)), mock.patch('glob.glob', autospec=True, return_value=fake_cluster_configs), ) as ( mock_join_path, mock_glob, ): actual = utils.list_clusters(service=fake_service) assert actual == expected