|
| 1 | +# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 2 | +# or more contributor license agreements. See the NOTICE file distributed with |
| 3 | +# this work for additional information regarding copyright |
| 4 | +# ownership. Elasticsearch B.V. licenses this file to you under |
| 5 | +# the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +from unittest import TestCase, mock |
| 18 | + |
| 19 | +from elasticotel.distro.resource_detectors import get_cloud_resource_detectors |
| 20 | + |
| 21 | + |
| 22 | +class TestGetCloudResourceDetectors(TestCase): |
| 23 | + @mock.patch.dict("os.environ", {"AWS_LAMBDA_FUNCTION_NAME": "lambda"}, clear=True) |
| 24 | + def test_aws_lambda(self): |
| 25 | + resource_detectors = get_cloud_resource_detectors() |
| 26 | + self.assertEqual(resource_detectors, ["aws_lambda"]) |
| 27 | + |
| 28 | + @mock.patch.dict("os.environ", {"FUNCTIONS_WORKER_RUNTIME": "azure"}, clear=True) |
| 29 | + def test_azure_functions(self): |
| 30 | + resource_detectors = get_cloud_resource_detectors() |
| 31 | + self.assertEqual(resource_detectors, ["azure_functions"]) |
| 32 | + |
| 33 | + @mock.patch.dict("os.environ", {"K_CONFIGURATION": "cloudrun"}, clear=True) |
| 34 | + def test_gcp_cloud_run(self): |
| 35 | + resource_detectors = get_cloud_resource_detectors() |
| 36 | + self.assertEqual(resource_detectors, ["_gcp"]) |
| 37 | + |
| 38 | + @mock.patch.dict("os.environ", {"KUBERNETES_SERVICE_HOST": "k8s"}, clear=True) |
| 39 | + def test_kubernetes_pod(self): |
| 40 | + resource_detectors = get_cloud_resource_detectors() |
| 41 | + self.assertEqual(resource_detectors, ["_gcp", "aws_eks", "container"]) |
| 42 | + |
| 43 | + @mock.patch.dict("os.environ", {}, clear=True) |
| 44 | + def test_other_cloud_detectors(self): |
| 45 | + resource_detectors = get_cloud_resource_detectors() |
| 46 | + self.assertEqual( |
| 47 | + resource_detectors, |
| 48 | + ["_gcp", "aws_ec2", "aws_ecs", "aws_elastic_beanstalk", "azure_app_service", "azure_vm", "container"], |
| 49 | + ) |
0 commit comments