Skip to content

Commit 69464a8

Browse files
committed
Remove duplicate updateTargetLambdaMetadata call
1 parent 651d340 commit 69464a8

File tree

3 files changed

+17
-59
lines changed

3 files changed

+17
-59
lines changed

packages/infra/src/handlers/framework/context.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,19 @@ describe('updateTargetLambdaMetadata', () => {
172172
expect(getContext().targetLambdaService).toBe('my-function');
173173
});
174174
});
175+
176+
it('does not throw if context is not available', () => {
177+
const lambdaMetaData = {
178+
Configuration: {
179+
FunctionName: 'my-function',
180+
Environment: {
181+
Variables: {},
182+
},
183+
},
184+
Tags: {},
185+
$metadata: {},
186+
};
187+
188+
expect(() => updateTargetLambdaMetadata(lambdaMetaData)).not.toThrow();
189+
});
175190
});

packages/infra/src/handlers/process/lambda/prune.test.ts

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'aws-sdk-client-mock-jest';
22

33
import {
44
DeleteFunctionCommand,
5-
GetFunctionCommand,
65
LambdaClient,
76
ListAliasesCommand,
87
ListVersionsByFunctionCommand,
@@ -25,15 +24,6 @@ afterEach(() => lambda.reset());
2524

2625
describe('prune', () => {
2726
it('deletes versions from one function', async () => {
28-
lambda.on(GetFunctionCommand).resolves({
29-
Configuration: {
30-
FunctionName: 'mock-name',
31-
},
32-
Tags: {
33-
service: 'test-service',
34-
},
35-
});
36-
3727
lambda
3828
.on(ListVersionsByFunctionCommand, { FunctionName: 'mock-name' })
3929
.resolves({
@@ -62,15 +52,6 @@ describe('prune', () => {
6252
});
6353

6454
it('deletes versions from multiple functions', async () => {
65-
lambda.on(GetFunctionCommand).resolves({
66-
Configuration: {
67-
FunctionName: 'mock-name',
68-
},
69-
Tags: {
70-
service: 'test-service',
71-
},
72-
});
73-
7455
lambda
7556
.on(ListVersionsByFunctionCommand, { FunctionName: 'mock-name-1' })
7657
.resolves({
@@ -119,15 +100,6 @@ describe('prune', () => {
119100
});
120101

121102
it('paginates', async () => {
122-
lambda.on(GetFunctionCommand).resolves({
123-
Configuration: {
124-
FunctionName: 'mock-name',
125-
},
126-
Tags: {
127-
service: 'test-service',
128-
},
129-
});
130-
131103
lambda
132104
.on(ListVersionsByFunctionCommand, {
133105
FunctionName: 'mock-name',
@@ -178,15 +150,6 @@ describe('prune', () => {
178150
});
179151

180152
it('skips if nothing to delete', async () => {
181-
lambda.on(GetFunctionCommand).resolves({
182-
Configuration: {
183-
FunctionName: 'mock-name',
184-
},
185-
Tags: {
186-
service: 'test-service',
187-
},
188-
});
189-
190153
lambda.on(ListVersionsByFunctionCommand).resolves({
191154
Versions: ['1', '2', '3', '4', '$LATEST'].map((Version) => ({
192155
Version,
@@ -204,15 +167,6 @@ describe('prune', () => {
204167
});
205168

206169
it('handles empty responses', async () => {
207-
lambda.on(GetFunctionCommand).resolves({
208-
Configuration: {
209-
FunctionName: 'mock-name',
210-
},
211-
Tags: {
212-
service: 'test-service',
213-
},
214-
});
215-
216170
lambda.on(ListVersionsByFunctionCommand).resolves({});
217171
lambda
218172
.on(ListAliasesCommand)

packages/infra/src/handlers/process/lambda/prune.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ import {
22
type AliasConfiguration,
33
DeleteFunctionCommand,
44
type FunctionConfiguration,
5-
GetFunctionCommand,
65
ListAliasesCommand,
76
ListVersionsByFunctionCommand,
87
} from '@aws-sdk/client-lambda';
98
import { Env } from 'skuba-dive';
109

1110
import { lambdaClient } from '../../framework/aws.js';
12-
import {
13-
getContext,
14-
updateTargetLambdaMetadata,
15-
} from '../../framework/context.js';
11+
import { getContext } from '../../framework/context.js';
1612
import { logger } from '../../framework/logging.js';
1713

1814
import type { LambdaFunction } from './types.js';
@@ -29,18 +25,11 @@ export const pruneFunction = async ({ name }: Args): Promise<void> => {
2925
const versionsToKeep = Env.nonNegativeInteger('VERSIONS_TO_KEEP');
3026
const { abortSignal } = getContext();
3127

32-
const getFunctionCommand = new GetFunctionCommand({
33-
FunctionName: name,
34-
});
35-
36-
const [aliases, versions, targetLambdaMetadata] = await Promise.all([
28+
const [aliases, versions] = await Promise.all([
3729
listAliases(name, abortSignal),
3830
listLambdaVersions(name, abortSignal),
39-
lambdaClient.send(getFunctionCommand),
4031
]);
4132

42-
updateTargetLambdaMetadata(targetLambdaMetadata);
43-
4433
const aliasMap = new Map(
4534
aliases.flatMap((alias) =>
4635
alias.FunctionVersion ? [[alias.FunctionVersion, alias]] : [],

0 commit comments

Comments
 (0)