Skip to content

Commit

Permalink
Address PR feedback on opensearch-project#124
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Kurait <[email protected]>
  • Loading branch information
AndreKurait committed Jun 14, 2024
1 parent b2f77fa commit 2b57b77
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/infra/infra-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ export class InfraStack extends Stack {
Tags.of(singleNodeInstance).add('role', 'client');

// Disable target security for now, can be provided as an option in the future
InfraStack.addTargets(
InfraStack.addTargetsToListener(
opensearchListener,
this.elbType,
'single-node-target',
Expand All @@ -516,7 +516,7 @@ export class InfraStack extends Stack {
false);

if (this.dashboardsUrl !== 'undefined') {
InfraStack.addTargets(
InfraStack.addTargetsToListener(
dashboardsListener!,
this.elbType,
'single-node-osd-target',
Expand Down Expand Up @@ -688,7 +688,7 @@ export class InfraStack extends Stack {
}

// Disable target security for now, can be provided as an option in the future
InfraStack.addTargets(
InfraStack.addTargetsToListener(
opensearchListener,
this.elbType,
'opensearchTarget',
Expand All @@ -697,7 +697,7 @@ export class InfraStack extends Stack {
false);

if (this.dashboardsUrl !== 'undefined') {
InfraStack.addTargets(
InfraStack.addTargetsToListener(
dashboardsListener!,
this.elbType,
'dashboardsTarget',
Expand Down Expand Up @@ -1090,7 +1090,7 @@ export class InfraStack extends Stack {
* Adds targets to the given listener.
* Works for both Application Load Balancers and Network Load Balancers.
*/
private static addTargets(listener: BaseListener, elbType: LoadBalancerType, id: string, port: number, target: AutoScalingGroup | InstanceTarget,
private static addTargetsToListener(listener: BaseListener, elbType: LoadBalancerType, id: string, port: number, target: AutoScalingGroup | InstanceTarget,
securityEnabled: boolean) {
switch(elbType) {
case LoadBalancerType.ALB: {
Expand Down
40 changes: 40 additions & 0 deletions test/infra-stack-props.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,43 @@ test('Throw error on invalid CPU Arch', () => {
expect(error.message).toEqual('distributionUrl parameter is required. Please provide the OpenSearch distribution artifact url to download');
}
});

test('Throw error on invalid load balancer type', () => {
const app = new App({
context: {
distVersion: '1.0.0',
securityDisabled: false,
minDistribution: false,
cpuArch: 'x64',
singleNodeCluster: false,
dashboardsUrl: 'www.example.com',
distributionUrl: 'www.example.com',
serverAccessType: 'ipv4',
restrictServerAccessTo: 'all',
additionalConfig: '{ "name": "John Doe", "age": 30, "email": "[email protected]" }',
additionalOsdConfig: '{ "something.enabled": "true", "something_else.enabled": "false" }',
loadBalancerType: 'invalid-type',
},
});

try {
// WHEN
const networkStack = new NetworkStack(app, 'opensearch-network-stack', {
env: { account: 'test-account', region: 'us-east-1' },
});

// @ts-ignore
const infraStack = new InfraStack(app, 'opensearch-infra-stack', {
vpc: networkStack.vpc,
securityGroup: networkStack.osSecurityGroup,
env: { account: 'test-account', region: 'us-east-1' },
});

// eslint-disable-next-line no-undef
fail('Expected an error to be thrown');
} catch (error) {
expect(error).toBeInstanceOf(Error);
// @ts-ignore
expect(error.message).toEqual('Unsupported load balancer type.');
}
});

0 comments on commit 2b57b77

Please sign in to comment.