diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/frontend/create_cluster/eks_cluster/services/aws_services_facade_spec.js | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/frontend/create_cluster/eks_cluster/services/aws_services_facade_spec.js')
-rw-r--r-- | spec/frontend/create_cluster/eks_cluster/services/aws_services_facade_spec.js | 178 |
1 files changed, 0 insertions, 178 deletions
diff --git a/spec/frontend/create_cluster/eks_cluster/services/aws_services_facade_spec.js b/spec/frontend/create_cluster/eks_cluster/services/aws_services_facade_spec.js deleted file mode 100644 index 7b93b6d0a09..00000000000 --- a/spec/frontend/create_cluster/eks_cluster/services/aws_services_facade_spec.js +++ /dev/null @@ -1,178 +0,0 @@ -import EC2 from 'aws-sdk/clients/ec2'; -import AWS from 'aws-sdk/global'; -import { - setAWSConfig, - fetchRoles, - fetchKeyPairs, - fetchVpcs, - fetchSubnets, - fetchSecurityGroups, -} from '~/create_cluster/eks_cluster/services/aws_services_facade'; - -const mockListRolesPromise = jest.fn(); -const mockDescribeRegionsPromise = jest.fn(); -const mockDescribeKeyPairsPromise = jest.fn(); -const mockDescribeVpcsPromise = jest.fn(); -const mockDescribeSubnetsPromise = jest.fn(); -const mockDescribeSecurityGroupsPromise = jest.fn(); - -jest.mock('aws-sdk/clients/iam', () => - jest.fn().mockImplementation(() => ({ - listRoles: jest.fn().mockReturnValue({ promise: mockListRolesPromise }), - })), -); - -jest.mock('aws-sdk/clients/ec2', () => - jest.fn().mockImplementation(() => ({ - describeRegions: jest.fn().mockReturnValue({ promise: mockDescribeRegionsPromise }), - describeKeyPairs: jest.fn().mockReturnValue({ promise: mockDescribeKeyPairsPromise }), - describeVpcs: jest.fn().mockReturnValue({ promise: mockDescribeVpcsPromise }), - describeSubnets: jest.fn().mockReturnValue({ promise: mockDescribeSubnetsPromise }), - describeSecurityGroups: jest - .fn() - .mockReturnValue({ promise: mockDescribeSecurityGroupsPromise }), - })), -); - -describe('awsServicesFacade', () => { - let region; - let vpc; - - beforeEach(() => { - region = 'west-1'; - vpc = 'vpc-2'; - }); - - it('setAWSConfig configures AWS SDK with provided credentials', () => { - const awsCredentials = { - accessKeyId: 'access-key', - secretAccessKey: 'secret-key', - sessionToken: 'session-token', - region, - }; - - setAWSConfig({ awsCredentials }); - - expect(AWS.config).toEqual(awsCredentials); - }); - - describe('when fetchRoles succeeds', () => { - let roles; - let rolesOutput; - - beforeEach(() => { - roles = [ - { RoleName: 'admin', Arn: 'aws::admin' }, - { RoleName: 'read-only', Arn: 'aws::read-only' }, - ]; - rolesOutput = roles.map(({ RoleName: name, Arn: value }) => ({ name, value })); - - mockListRolesPromise.mockResolvedValueOnce({ Roles: roles }); - }); - - it('return list of regions where each item has a name and value', () => { - return expect(fetchRoles()).resolves.toEqual(rolesOutput); - }); - }); - - describe('when fetchKeyPairs succeeds', () => { - let keyPairs; - let keyPairsOutput; - - beforeEach(() => { - keyPairs = [{ KeyName: 'key-pair' }, { KeyName: 'key-pair-2' }]; - keyPairsOutput = keyPairs.map(({ KeyName: name }) => ({ name, value: name })); - - mockDescribeKeyPairsPromise.mockResolvedValueOnce({ KeyPairs: keyPairs }); - }); - - it('instantatiates ec2 service with provided region', () => { - fetchKeyPairs({ region }); - expect(EC2).toHaveBeenCalledWith({ region }); - }); - - it('return list of key pairs where each item has a name and value', () => { - return expect(fetchKeyPairs({ region })).resolves.toEqual(keyPairsOutput); - }); - }); - - describe('when fetchVpcs succeeds', () => { - let vpcs; - let vpcsOutput; - - beforeEach(() => { - vpcs = [ - { VpcId: 'vpc-1', Tags: [] }, - { VpcId: 'vpc-2', Tags: [] }, - ]; - vpcsOutput = vpcs.map(({ VpcId: vpcId }) => ({ name: vpcId, value: vpcId })); - - mockDescribeVpcsPromise.mockResolvedValueOnce({ Vpcs: vpcs }); - }); - - it('instantatiates ec2 service with provided region', () => { - fetchVpcs({ region }); - expect(EC2).toHaveBeenCalledWith({ region }); - }); - - it('return list of vpcs where each item has a name and value', () => { - return expect(fetchVpcs({ region })).resolves.toEqual(vpcsOutput); - }); - }); - - describe('when vpcs has a Name tag', () => { - const vpcName = 'vpc name'; - const vpcId = 'vpc id'; - let vpcs; - let vpcsOutput; - - beforeEach(() => { - vpcs = [{ VpcId: vpcId, Tags: [{ Key: 'Name', Value: vpcName }] }]; - vpcsOutput = [{ name: vpcName, value: vpcId }]; - - mockDescribeVpcsPromise.mockResolvedValueOnce({ Vpcs: vpcs }); - }); - - it('uses name tag value as the vpc name', () => { - return expect(fetchVpcs({ region })).resolves.toEqual(vpcsOutput); - }); - }); - - describe('when fetchSubnets succeeds', () => { - let subnets; - let subnetsOutput; - - beforeEach(() => { - subnets = [{ SubnetId: 'subnet-1' }, { SubnetId: 'subnet-2' }]; - subnetsOutput = subnets.map(({ SubnetId }) => ({ name: SubnetId, value: SubnetId })); - - mockDescribeSubnetsPromise.mockResolvedValueOnce({ Subnets: subnets }); - }); - - it('return list of subnets where each item has a name and value', () => { - return expect(fetchSubnets({ region, vpc })).resolves.toEqual(subnetsOutput); - }); - }); - - describe('when fetchSecurityGroups succeeds', () => { - let securityGroups; - let securityGroupsOutput; - - beforeEach(() => { - securityGroups = [ - { GroupName: 'admin group', GroupId: 'group-1' }, - { GroupName: 'basic group', GroupId: 'group-2' }, - ]; - securityGroupsOutput = securityGroups.map(({ GroupId: value, GroupName: name }) => ({ - name, - value, - })); - - mockDescribeSecurityGroupsPromise.mockResolvedValueOnce({ SecurityGroups: securityGroups }); - }); - - it('return list of security groups where each item has a name and value', () => { - return expect(fetchSecurityGroups({ region, vpc })).resolves.toEqual(securityGroupsOutput); - }); - }); -}); |