Skip to content

Commit

Permalink
Add test for shared output bug (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejizba authored Nov 13, 2023
1 parent bd876fe commit e922a76
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
31 changes: 31 additions & 0 deletions app/v4/src/functions/storageBlobTriggerSharedOutputBug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.

import { app, InvocationContext, output } from '@azure/functions';

// Test for bug https://github.com/Azure/azure-functions-nodejs-library/issues/179

const queueOutput = output.storageQueue({
queueName: 'e2e-test-queue-trigger',
connection: 'e2eTest_storage',
});

app.storageBlob('storageBlobTriggerReturnOutput', {
path: 'e2e-test-container/e2e-test-blob-trigger-shared-output-bug',
connection: 'e2eTest_storage',
return: queueOutput,
handler: (blob: Buffer, context: InvocationContext) => {
context.log(`storageBlobTriggerReturnOutput was triggered`);
return `${blob.toString()}-returnOutput`;
},
});

app.storageBlob('storageBlobTriggerExtraOutput', {
path: 'e2e-test-container/e2e-test-blob-trigger-shared-output-bug',
connection: 'e2eTest_storage',
extraOutputs: [queueOutput],
handler: (blob: Buffer, context: InvocationContext) => {
context.log(`storageBlobTriggerExtraOutput was triggered`);
context.extraOutputs.set(queueOutput, `${blob.toString()}-extraOutput`);
},
});
23 changes: 22 additions & 1 deletion src/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { QueueClient } from '@azure/storage-queue';
import { expect } from 'chai';
import { default as fetch } from 'node-fetch';
import { getFuncUrl } from './constants';
import { waitForOutput } from './global.test';
import { model, waitForOutput } from './global.test';
import { storageConnectionString } from './resources/connectionStrings';
import { getRandomTestData } from './utils/getRandomTestData';

Expand Down Expand Up @@ -83,4 +83,25 @@ describe('storage', () => {
expect(result).to.deep.equal(items);
await waitForOutput(`httpTriggerTableInput was triggered`);
});

// Test for bug https://github.com/Azure/azure-functions-nodejs-library/issues/179
it('Shared output bug', async function (this: Mocha.Context) {
if (model === 'v3') {
this.skip();
}

const containerName = 'e2e-test-container';
const client = new ContainerClient(storageConnectionString, containerName);
await client.createIfNotExists();

const message = getRandomTestData();
const messageBuffer = Buffer.from(message);
const blobName = 'e2e-test-blob-trigger-shared-output-bug';
await client.uploadBlockBlob(blobName, messageBuffer, messageBuffer.byteLength);

await waitForOutput(`storageBlobTriggerReturnOutput was triggered`);
await waitForOutput(`storageBlobTriggerExtraOutput was triggered`);
await waitForOutput(`storageQueueTrigger was triggered by "${message}-returnOutput"`);
await waitForOutput(`storageQueueTrigger was triggered by "${message}-extraOutput"`);
});
});

0 comments on commit e922a76

Please sign in to comment.