def test_add_matched_to_empty_set_metric(node_scenario, pod_scenario): node_scenario.schema = {"match": [{"namespace": {"name": "non-existent"}}]} with mock.patch('powerfulseal.metriccollectors.StdoutCollector.add_matched_to_empty_set_metric') \ as metric_function: metric_function.assert_not_called() node_scenario.match() metric_function.assert_called_once_with(NODE_SOURCE) pod_scenario.schema = {"match": [{"namespace": {"name": "non-existent"}}]} with mock.patch('powerfulseal.metriccollectors.StdoutCollector.add_matched_to_empty_set_metric') \ as metric_function: metric_function.assert_not_called() pod_scenario.match() metric_function.assert_called_once_with(POD_SOURCE)
def test_matching_namespace(pod_scenario): a, b = make_dummy_object(), make_dummy_object() pod_scenario.schema = { "matches": [ { "namespace": "something", }, ] } pod_scenario.k8s_inventory.find_pods = MagicMock(return_value=[a, b]) matched = pod_scenario.match() assert matched == list(set([a, b])) assert pod_scenario.k8s_inventory.find_pods.call_args[1] == { "namespace": "something" }
def test_matching_labels(pod_scenario): a, b = dummy_object(), dummy_object() pod_scenario.schema = { "match": [ { "labels": { "selector": "yes=true", "namespace": "something", } }, ] } pod_scenario.k8s_inventory.find_pods = MagicMock(return_value=[a, b]) matched = pod_scenario.match() assert matched == list(set([a, b])) assert pod_scenario.k8s_inventory.find_pods.call_args[1] == { "selector": "yes=true", "namespace": "something" }
def test_matching_deployment(pod_scenario): a, b = dummy_object(), dummy_object() pod_scenario.schema = { "match": [ { "deployment": { "name": "lol", "namespace": "something", } }, ] } pod_scenario.k8s_inventory.find_pods = MagicMock(return_value=[a, b]) matched = pod_scenario.match() assert matched == list(set([a, b])) assert pod_scenario.k8s_inventory.find_pods.call_args[1] == { "deployment_name": "lol", "namespace": "something" }