diff --git a/monkey/tests/unit_tests/common/aws/test_aws_instance.py b/monkey/tests/unit_tests/common/aws/test_aws_instance.py new file mode 100644 index 000000000..3c1f22ab2 --- /dev/null +++ b/monkey/tests/unit_tests/common/aws/test_aws_instance.py @@ -0,0 +1,54 @@ +import pytest + +from common.aws import AWSInstance + +INSTANCE_ID = "1234" +REGION = "USA" +ACCOUNT_ID = "4321" + + +@pytest.fixture +def patch_fetch_metadata(monkeypatch): + def inner(instance_id: str, region: str, account_id: str): + return_value = (instance_id, region, account_id) + monkeypatch.setattr( + "common.aws.aws_instance.fetch_aws_instance_metadata", lambda: return_value + ) + + return inner + + +@pytest.fixture(autouse=True) +def patch_fetch_metadata_default_values(patch_fetch_metadata): + patch_fetch_metadata(INSTANCE_ID, REGION, ACCOUNT_ID) + + +def test_is_instance__true(): + aws_instance = AWSInstance() + + assert aws_instance.is_instance + + +def test_is_instance__false(patch_fetch_metadata): + patch_fetch_metadata(None, "", "") + aws_instance = AWSInstance() + + assert not aws_instance.is_instance + + +def test_instance_id(): + aws_instance = AWSInstance() + + assert aws_instance.instance_id == INSTANCE_ID + + +def test_region(): + aws_instance = AWSInstance() + + assert aws_instance.region == REGION + + +def test_account_id(): + aws_instance = AWSInstance() + + assert aws_instance.account_id == ACCOUNT_ID