Skip to content

Commit

Permalink
AT-10925: Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rddimon committed Dec 5, 2023
1 parent 4f35960 commit 3a5f6cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-vpc-discovery",
"version": "4.1.0",
"version": "5.0.0",
"engines": {
"node": ">=14"
},
Expand Down
35 changes: 7 additions & 28 deletions test/unit-tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ chai.use(spies);
const emptyData = require("./empty-data.json");
const testData = require("./test-data.json");

// Used for changing what to test
const testCreds = {
accessKeyId: "test_key",
secretAccessKey: "test_secret",
sessionToken: "test_session"
};
const vpc = "test";
const subnets = [
{
Expand Down Expand Up @@ -71,7 +65,8 @@ const constructPlugin = (vpcConfig) => {
},
providers: {
aws: {
getRegion: () => "us-moon-1"
getRegion: () => "us-moon-1",
getCredentials: () => new Object()
}
},
configSchemaHandler: {
Expand All @@ -89,18 +84,6 @@ const initFuncMessage = `[Info] Getting VPC config for the function: '${testFunc
const foundFuncMessage = `[Info] Found VPC with id '${vpcId}'`;

describe("serverless-vpc-plugin", () => {
it("check aws config", () => {
const plugin = constructPlugin({
vpcName: vpc,
subnets: subnets,
securityGroups: securityGroups
});
plugin.initResources();

expect(plugin.awsCredentials.accessKeyId).to.equal(testCreds.accessKeyId);
expect(plugin.awsCredentials.sessionToken).to.equal(testCreds.sessionToken);
});

it("registers hooks", () => {
const plugin = constructPlugin({});
expect(plugin.hooks["before:package:initialize"]).to.be.a("function");
Expand Down Expand Up @@ -203,14 +186,6 @@ describe("Given valid inputs for Subnets and Security Groups ", () => {
});

describe("Given invalid input for ", () => {
let plugin;
beforeEach(() => {
plugin = constructPlugin({});

const EC2ClientMock = mockClient(EC2Client);
EC2ClientMock.on(DescribeVpcsCommand).resolves(testData);
});

const funcVPCDiscovery: FuncVPCDiscovery = {
vpcName: "test",
subnets: [{tagKey: "Name", tagValues: ["test_subnet_1"]}],
Expand All @@ -219,9 +194,11 @@ describe("Given invalid input for ", () => {

it("Subnets", async () => {
const EC2ClientMock = mockClient(EC2Client);
EC2ClientMock.on(DescribeSubnetsCommand).resolves(testData);
EC2ClientMock.on(DescribeVpcsCommand).resolves(testData);
EC2ClientMock.on(DescribeSubnetsCommand).resolves(emptyData);
EC2ClientMock.on(DescribeSecurityGroupsCommand).resolves(testData);

const plugin = constructPlugin({});
plugin.initResources();

await plugin.lambdaFunction.getFuncVPC("test", funcVPCDiscovery).then(() => {
Expand All @@ -234,9 +211,11 @@ describe("Given invalid input for ", () => {

it("Security Groups", async () => {
const EC2ClientMock = mockClient(EC2Client);
EC2ClientMock.on(DescribeVpcsCommand).resolves(testData);
EC2ClientMock.on(DescribeSubnetsCommand).resolves(testData);
EC2ClientMock.on(DescribeSecurityGroupsCommand).resolves(emptyData);

const plugin = constructPlugin({});
plugin.initResources();

await plugin.lambdaFunction.getFuncVPC("test", funcVPCDiscovery).then(() => {
Expand Down

0 comments on commit 3a5f6cf

Please sign in to comment.