|
| 1 | +/*! |
| 2 | + * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import { Cluster, Container, Service } from '../../ecs/model' |
| 7 | +import { DefaultEcsClient } from '../../shared/clients/ecsClient' |
| 8 | +import { assertChildren, assertTreeItem } from '../shared/treeview/testUtil' |
| 9 | +import { createCollectionFromPages } from '../utilities/collectionUtils' |
| 10 | +import { stub } from '../utilities/stubber' |
| 11 | + |
| 12 | +const clusterData = { |
| 13 | + clusterArn: 'arn:aws:ecs:us-east-1:012345678910:cluster/my-cluster', |
| 14 | + clusterName: 'my-cluster', |
| 15 | +} |
| 16 | + |
| 17 | +const serviceData = { |
| 18 | + serviceArn: 'arn:aws:ecs:us-east-1:012345678910:service/my-cluster/my-service', |
| 19 | + serviceName: 'my-service', |
| 20 | + taskDefinition: 'arn:aws:ecs:us-east-1:012345678910:task-definition/my-task:1', |
| 21 | +} |
| 22 | + |
| 23 | +const containerData = { |
| 24 | + name: 'my-container', |
| 25 | + clusterArn: clusterData.clusterArn, |
| 26 | + taskRoleArn: 'arn:aws:iam::012345678910:role/my-role', |
| 27 | +} |
| 28 | + |
| 29 | +const getClient = () => stub(DefaultEcsClient, { regionCode: 'us-east-1' }) |
| 30 | + |
| 31 | +describe('Container', function () { |
| 32 | + it('has a tree item', async function () { |
| 33 | + const container = new Container(getClient(), containerData) |
| 34 | + |
| 35 | + await assertTreeItem(container, { |
| 36 | + label: containerData.name, |
| 37 | + contextValue: 'awsEcsContainerNodeExecDisabled', |
| 38 | + }) |
| 39 | + }) |
| 40 | + |
| 41 | + it('has a tree item when "enableExecuteCommand" is set', async function () { |
| 42 | + const container = new Container(getClient(), { ...containerData, enableExecuteCommand: true }) |
| 43 | + |
| 44 | + await assertTreeItem(container, { |
| 45 | + label: containerData.name, |
| 46 | + contextValue: 'awsEcsContainerNodeExecEnabled', |
| 47 | + }) |
| 48 | + }) |
| 49 | +}) |
| 50 | + |
| 51 | +describe('Service', function () { |
| 52 | + it('has a tree item', async function () { |
| 53 | + const service = new Service(getClient(), serviceData) |
| 54 | + |
| 55 | + await assertTreeItem(service, { |
| 56 | + label: serviceData.serviceName, |
| 57 | + contextValue: 'awsEcsServiceNode.DISABLED', |
| 58 | + }) |
| 59 | + }) |
| 60 | + |
| 61 | + it('lists containers', async function () { |
| 62 | + const client = getClient() |
| 63 | + client.describeTaskDefinition.resolves({ taskDefinition: { containerDefinitions: [containerData] } }) |
| 64 | + |
| 65 | + const cluster = new Service(client, serviceData) |
| 66 | + await assertChildren(cluster, containerData.name) |
| 67 | + }) |
| 68 | +}) |
| 69 | + |
| 70 | +describe('Cluster', function () { |
| 71 | + it('has a tree item', async function () { |
| 72 | + const cluster = new Cluster(getClient(), clusterData) |
| 73 | + |
| 74 | + await assertTreeItem(cluster, { |
| 75 | + label: clusterData.clusterName, |
| 76 | + tooltip: clusterData.clusterArn, |
| 77 | + contextValue: 'awsEcsClusterNode', |
| 78 | + }) |
| 79 | + }) |
| 80 | + |
| 81 | + it('lists services', async function () { |
| 82 | + const client = getClient() |
| 83 | + client.listServices.returns(createCollectionFromPages([serviceData])) |
| 84 | + |
| 85 | + const cluster = new Cluster(client, clusterData) |
| 86 | + await assertChildren(cluster, serviceData.serviceName) |
| 87 | + }) |
| 88 | +}) |
0 commit comments