UT: Add tests for AWSInstance
This commit is contained in:
parent
10136a325c
commit
09218ef3d3
|
@ -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
|
Loading…
Reference in New Issue