|
| 1 | +/** |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance |
| 5 | + * with the License. A copy of the License is located at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES |
| 10 | + * OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions |
| 11 | + * and limitations under the License. |
| 12 | + */ |
| 13 | +import * as cdk from 'aws-cdk-lib'; |
| 14 | +import { Template } from 'aws-cdk-lib/assertions'; |
| 15 | +import * as lambda from 'aws-cdk-lib/aws-lambda'; |
| 16 | +import { |
| 17 | + LangchainCommonLayer, |
| 18 | + LangchainCommonDepsLayer, |
| 19 | +} from '../../../../src/patterns/gen-ai/aws-langchain-common-layer'; |
| 20 | + |
| 21 | +describe('LangchainCommonLayer construct', () => { |
| 22 | + |
| 23 | + let LangchainCommonLayerTestTemplate: Template; |
| 24 | + let LangchainCommonLayerTestConstruct: LangchainCommonLayer; |
| 25 | + |
| 26 | + afterAll(() => { |
| 27 | + console.log('Test completed'); |
| 28 | + console.log(LangchainCommonLayerTestTemplate.toJSON()); |
| 29 | + }); |
| 30 | + |
| 31 | + beforeAll(() => { |
| 32 | + |
| 33 | + const LangchainCommonLayerTestStack = new cdk.Stack(undefined, undefined, { |
| 34 | + env: { account: cdk.Aws.ACCOUNT_ID, region: 'us-east-1' }, |
| 35 | + }); |
| 36 | + |
| 37 | + // Lambda layer |
| 38 | + const lambdaArchitecture = lambda.Architecture.ARM_64; |
| 39 | + const lambdaRuntime = lambda.Runtime.PYTHON_3_10; |
| 40 | + |
| 41 | + LangchainCommonLayerTestConstruct = new LangchainCommonLayer(LangchainCommonLayerTestStack, 'lambdagenaicommonlayer', { |
| 42 | + compatibleRuntimes: [lambdaRuntime], |
| 43 | + compatibleArchitectures: [lambdaArchitecture], |
| 44 | + }); |
| 45 | + LangchainCommonLayerTestTemplate = Template.fromStack(LangchainCommonLayerTestStack); |
| 46 | + |
| 47 | + }); |
| 48 | + |
| 49 | + test('LayerVersion count', () => { |
| 50 | + LangchainCommonLayerTestTemplate.resourceCountIs('AWS::Lambda::LayerVersion', 1); |
| 51 | + expect(LangchainCommonLayerTestConstruct.layer).not.toBeNull; |
| 52 | + }); |
| 53 | +}); |
| 54 | + |
| 55 | +describe('LangchainCommonDepsLayer construct', () => { |
| 56 | + |
| 57 | + let LangchainCommonLayerDepsTestTemplate: Template; |
| 58 | + let LangchainCommonLayerDepsTestConstruct: LangchainCommonDepsLayer; |
| 59 | + |
| 60 | + afterAll(() => { |
| 61 | + console.log('Test completed'); |
| 62 | + console.log(LangchainCommonLayerDepsTestTemplate.toJSON()); |
| 63 | + }); |
| 64 | + |
| 65 | + beforeAll(() => { |
| 66 | + |
| 67 | + const LangchainCommonLayerDepsTestStack = new cdk.Stack(undefined, undefined, { |
| 68 | + env: { account: cdk.Aws.ACCOUNT_ID, region: 'us-east-1' }, |
| 69 | + }); |
| 70 | + |
| 71 | + // Lambda layer |
| 72 | + const lambdaArchitecture = lambda.Architecture.ARM_64; |
| 73 | + const lambdaRuntime = lambda.Runtime.PYTHON_3_10; |
| 74 | + |
| 75 | + LangchainCommonLayerDepsTestConstruct = new LangchainCommonDepsLayer(LangchainCommonLayerDepsTestStack, 'lambdagenaidepslayer', { |
| 76 | + runtime: lambdaRuntime, |
| 77 | + architecture: lambdaArchitecture, |
| 78 | + autoUpgrade: true, |
| 79 | + }); |
| 80 | + LangchainCommonLayerDepsTestTemplate = Template.fromStack(LangchainCommonLayerDepsTestStack); |
| 81 | + |
| 82 | + }); |
| 83 | + |
| 84 | + test('LayerVersionDeps count', () => { |
| 85 | + LangchainCommonLayerDepsTestTemplate.resourceCountIs('AWS::Lambda::LayerVersion', 1); |
| 86 | + expect(LangchainCommonLayerDepsTestConstruct.layer).not.toBeNull; |
| 87 | + }); |
| 88 | +}); |
| 89 | + |
0 commit comments