# Copyright (c) 2020 CloudZero - ALL RIGHTS RESERVED - PROPRIETARY AND CONFIDENTIAL
# Unauthorized copying of this file and/or project, via any medium is strictly prohibited.
# Direct all questions to legal@cloudzero.com

import pytest

from czc.aws_provider import Provider, ProviderConnectionError

ROLE_ARN = 'foo-arn-role-role-ok'
EXTERNAL_ID = 'bar-id-bar-bar-bar-b'


@pytest.mark.unit
def test_initialization_fails_without_EXTERNAL_ID(mock_sts):
    with pytest.raises(ProviderConnectionError):
        # should not be able to initialize provider without all parameters
        Provider(ROLE_ARN, None, 'us-east-2')


@pytest.mark.unit
def test_configuring_resource_fails(mock_sts):
    provider = Provider(ROLE_ARN, EXTERNAL_ID, 'us-east-2', service='not-service')
    resource = provider.resource  # attempt to create resource that will fail
    assert resource is None


@pytest.mark.unit
def test_client(mock_sts):
    provider = Provider(ROLE_ARN, EXTERNAL_ID, 'us-east-2', service='ec2')
    client = provider.client
    assert client.meta.region_name == 'us-east-2'
    assert client.meta.service_model.service_name == 'ec2'


@pytest.mark.unit
def test_resource(mock_sts):
    provider = Provider(ROLE_ARN, EXTERNAL_ID, 'us-east-2', service='ec2')
    resource = provider.resource
    assert resource.meta.service_name == 'ec2'
    assert resource.meta.client.meta.region_name == 'us-east-2'
