async def test_fetch_clients_managed(AuthForClients, make_client): "When a client is present and managed, it is included" resources = Resources([], [".*"]) api_client = make_client() AuthForClients.clients.append(api_client) await fetch_clients(resources) assert list(resources) == [Client.from_api(api_client)]
async def test_fetch_roles_managed(AuthForRoles, make_role): "When a role is present and managed, it is included" resources = Resources([], [".*"]) api_role = make_role() AuthForRoles.roles.append(api_role) await fetch_roles(resources) assert list(resources) == [Role.from_api(api_role)]
async def test_fetch_roles_unmanaged(AuthForRoles, make_role): "When a role is present and unmanaged, it is not included" resources = Resources([], ["Role=managed*"]) api_role1 = make_role(roleId="managed-role") api_role2 = make_role(roleId="un-managed-role") AuthForRoles.roles.extend([api_role1, api_role2]) await fetch_roles(resources) assert list(resources) == [Role.from_api(api_role1)]
async def test_fetch_secrets_managed(Secrets): "Only managed secrets are returned" with test_options(with_secrets=True): Secrets.secrets.append({"name": "secret1", "secret": "AA"}) Secrets.secrets.append({"name": "unmanaged-secret2"}) resources = Resources([], ["Secret=secret"]) await fetch_secrets(resources) assert list(sorted(resources)) == [Secret(name="secret1", secret="AA")]
async def test_fetch_clients_unmanaged(AuthForClients, make_client): "When a client is present and unmanaged, it is not included" resources = Resources([], ["Client=managed*"]) api_client1 = make_client(clientId="managed-client") api_client2 = make_client(clientId="un-managed-client") AuthForClients.clients.extend([api_client1, api_client2]) await fetch_clients(resources) assert list(resources) == [Client.from_api(api_client1)]
async def test_fetch_secrets_with_secrets(Secrets): "When there are secrets and --with-secrets, we get names and values" with test_options(with_secrets=True): Secrets.secrets.append({"name": "secret1", "secret": "AA"}) Secrets.secrets.append({"name": "secret2", "secret": "BB"}) resources = Resources([], [".*"]) await fetch_secrets(resources) assert list(sorted(resources)) == [ Secret(name="secret1", secret="AA"), Secret(name="secret2", secret="BB"), ]
async def test_fetch_secrets_without_secrets(Secrets): "When there are secrets but --without-secrets, we just get names" with test_options(with_secrets=False): Secrets.secrets.append({"name": "secret1"}) Secrets.secrets.append({"name": "secret2"}) resources = Resources([], [".*"]) await fetch_secrets(resources) assert list(sorted(resources)) == [ Secret(name="secret1"), Secret(name="secret2"), ]
def test_from_resources(): resources = Resources( resources=[ Role(roleId="role1", description="1", scopes=["one"]), Role(roleId="role2", description="2", scopes=["two"]), ], managed=["Role=role*"], ) res = Resolver.from_resources(resources) assert sorted(res.expandScopes(["assume:role1" ])) == ["assume:role1", "one"]
async def test_fetch_hook_managed_filter(Hooks, make_hook): "The managed resource dictate which hooks are fetched, including which groups" resources = Resources( [], ["Hook=garbage/.*", "Hook=proj.*", "Hook=imbstack/test4.*"]) hooks = [ # managed: make_hook(hookGroupId="garbage", hookId="test1"), make_hook(hookGroupId="garbage", hookId="test2"), make_hook(hookGroupId="project:gecko", hookId="test3"), # not managed: make_hook(hookGroupId="imbstack", hookId="test5"), # but imbstack is fetched make_hook(hookGroupId="notmanaged", hookId="test5"), ] Hooks.hooks.extend(hooks) await fetch_hooks(resources) assert list(resources) == sorted([Hook.from_api(h) for h in hooks[:3]]) assert Hooks.listHookCalls == ["garbage", "imbstack", "project:gecko"]
async def test_fetch_worker_pools(WorkerManager): resources = Resources([], ["WorkerPool=managed*"]) WorkerManager.workerPools = [ { "config": { "is": "config" }, "created": "2019-07-20T22:49:23.761Z", "lastModified": "2019-07-20T22:49:23.761Z", "workerPoolId": wpid, "description": "descr", "owner": "owner", "emailOnError": True, "providerId": "cirrus", } for wpid in ["managed-one", "unmanaged-two", "managed-three", "unmanaged-four"] ] await fetch_worker_pools(resources) assert [res.workerPoolId for res in resources] == ["managed-one", "managed-three"]
async def test_fetch_aws_provisioner_workertypes(AwsProvisioner, monkeypatch): monkeypatch.setenv("TASKCLUSTER_ROOT_URL", "https://taskcluster.net") resources = Resources([], ["AwsProvisionerWorkerType=managed*"]) AwsProvisioner.workerTypes = [{ "workerType": workerTypeId, "launchSpec": { "SecurityGroups": ["docker-worker"] }, "description": "** WRITE THIS**", "owner": "** WRITE THIS **", "userData": {}, "minCapacity": 0, "maxCapacity": 200, "scalingRatio": 0, "minPrice": 4, "maxPrice": 4.2, "instanceTypes": [], "regions": [], "availabilityZones": [], } for workerTypeId in ["managed-one", "unmanaged-two"]] await fetch_aws_provisioner_workertypes(resources) assert [res.workerType for res in resources] == ["managed-one"]
async def test_fetch_hook(Hooks, make_hook): resources = Resources([], [".*"]) api_hook = make_hook() Hooks.hooks.append(api_hook) await fetch_hooks(resources) assert list(resources) == [Hook.from_api(api_hook)]
async def test_fetch_roles_empty(AuthForRoles): "When there are no roles, nothing happens" resources = Resources([], [".*"]) await fetch_roles(resources) assert list(resources) == []
async def test_fetch_secrets_empty(Secrets): "When there are no secrets, nothing happens" with test_options(with_secrets=True): resources = Resources([], [".*"]) await fetch_secrets(resources) assert list(resources) == []