Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
fix: issue fixed to generate the correct function.json for event hub …
Browse files Browse the repository at this point in the history
…and service bus queue and topic triggers (#228)

* fixed: issue fixed to create the right function.json for event hub trigger

* fix: wrong bindings issue for servicebus topic and queue added

* Test cases added

* Test cases added

* eventhubame to eventHubName
  • Loading branch information
neerajmandal authored Aug 7, 2019
1 parent c3f0805 commit 4e46a03
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 15 deletions.
55 changes: 44 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions src/services/packageService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe("Package Service", () => {
sls.config.servicePath = process.cwd();
sls.service["functions"] = {
hello: MockFactory.createTestAzureFunctionConfig(functionRoute),
eventhubHandler: MockFactory.createTestEventHubFunctionConfig(),
}
packageService = new PackageService(sls, MockFactory.createTestServerlessOptions());
});
Expand Down Expand Up @@ -119,6 +120,46 @@ describe("Package Service", () => {
writeFileSpy.mockRestore();
});

it("Creates Event Hub Handler bindings and function.json ", async () => {
const functionName = "eventhubHandler";
const functionMetadata: FunctionMetadata = {
entryPoint: "handler",
handlerPath: "src/handlers/eventhubHandler",
params: {
functionsJson: {
bindings: [
MockFactory.createTestEventHubBinding("in"),
]
}
},
};

const expectedFolderPath = path.join(sls.config.servicePath, functionName);
const expectedFilePath = path.join(expectedFolderPath, "function.json");
const expectedFunctionJson = {
entryPoint: "handler",
scriptFile: "src/handlers/eventhubHandler",
bindings: [
MockFactory.createTestEventHubBinding("in"),
]
}

mockFs({});

const mkdirSpy = jest.spyOn(fs, "mkdirSync");
const writeFileSpy = jest.spyOn(fs, "writeFileSync");

await packageService.createBinding(functionName, functionMetadata);

expect(mkdirSpy).toBeCalledWith(expectedFolderPath);
const call = writeFileSpy.mock.calls[0];
expect(call[0]).toEqual(expectedFilePath);
expect(JSON.parse(call[1])).toEqual(expectedFunctionJson);

mkdirSpy.mockRestore();
writeFileSpy.mockRestore();
});

it("createBinding does not need to create directory if function folder already exists", async () => {
const functionName = "hello";
const functionMetadata: FunctionMetadata = {
Expand Down
8 changes: 4 additions & 4 deletions src/shared/bindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
]
},
{
"name": "path",
"name": "eventHubName",
"value": "string",
"defaultValue": "myeventhub",
"required": true,
Expand Down Expand Up @@ -900,7 +900,7 @@
"name": "queueName",
"value": "string",
"defaultValue": "mysbqueue",
"required": true,
"required": false,
"label": "$serviceBusTrigger_queueName_label",
"help": "$serviceBusTrigger_queueName_help",
"validators": [
Expand All @@ -914,7 +914,7 @@
"name": "topicName",
"value": "string",
"defaultValue": "mysbtopic",
"required": true,
"required": false,
"label": "$serviceBusTrigger_topicName_label",
"help": "$serviceBusTrigger_topicName_help",
"validators": [
Expand All @@ -928,7 +928,7 @@
"name": "subscriptionName",
"value": "string",
"defaultValue": "mysubscription",
"required": true,
"required": false,
"label": "$serviceBusTrigger_subscriptionName_label",
"help": "$serviceBusTrigger_subscriptionName_help",
"validators": [
Expand Down
Loading

0 comments on commit 4e46a03

Please sign in to comment.