Skip to content

Commit c93763a

Browse files
committed
Fixes #787
1 parent 6c83dca commit c93763a

File tree

5 files changed

+87
-1
lines changed

5 files changed

+87
-1
lines changed

src/WebJobs.Script/Binding/FunctionBinding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ internal static async Task BindStreamAsync(BindingContext context, FileAccess ac
213213
else
214214
{
215215
// Read the value into the context Value converting based on data type
216-
object converted = null;
216+
object converted = context.Value ?? new MemoryStream();
217217
ConvertStreamToValue(stream, context.DataType, ref converted);
218218
context.Value = converted;
219219
}

test/WebJobs.Script.Tests/PhpEndToEndTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4+
using System;
5+
using System.Threading.Tasks;
6+
using Microsoft.WindowsAzure.Storage.Blob;
7+
using Xunit;
8+
49
namespace Microsoft.Azure.WebJobs.Script.Tests
510
{
611
public class PhpEndToEndTests : EndToEndTestsBase<PhpEndToEndTests.TestFixture>
@@ -10,11 +15,51 @@ public PhpEndToEndTests(TestFixture fixture)
1015
{
1116
}
1217

18+
[Fact]
19+
public async Task BlobTriggerToBlobTest()
20+
{
21+
// the trigger blob was written by the fixture init code
22+
// here we just wait for the output blob
23+
CloudBlobContainer outputContainer = Fixture.BlobClient.GetContainerReference("test-output-php");
24+
var resultBlob = outputContainer.GetBlockBlobReference(Fixture.TestBlobName);
25+
await TestHelpers.WaitForBlobAsync(resultBlob);
26+
27+
string resultContents = resultBlob.DownloadText();
28+
Assert.Equal(Fixture.TestBlobTriggerContents + "_" + Fixture.TestBlobContents, resultContents.Trim());
29+
}
30+
1331
public class TestFixture : EndToEndTestFixture
1432
{
1533
public TestFixture() : base(@"TestScripts\Php", "php")
1634
{
1735
}
36+
37+
public string TestBlobTriggerContents { get; private set; }
38+
39+
public string TestBlobContents { get; private set; }
40+
41+
public string TestBlobName { get; private set; }
42+
43+
public string TestBlobTriggerName { get; private set; }
44+
45+
protected override void CreateTestStorageEntities()
46+
{
47+
// This will ensure the input container is created.
48+
base.CreateTestStorageEntities();
49+
50+
TestBlobTriggerContents = "My Test Blob Trigger";
51+
TestBlobContents = "My Test Blob";
52+
TestBlobTriggerName = "testBlobTrigger";
53+
TestBlobName = "testBlob";
54+
55+
// write the test blob before the host starts, so it gets picked
56+
// up relatively quickly by the blob trigger test
57+
CloudBlockBlob inputBlobTrigger = TestInputContainer.GetBlockBlobReference(TestBlobTriggerName);
58+
inputBlobTrigger.UploadText(TestBlobTriggerContents);
59+
60+
CloudBlockBlob inputBlob = TestInputContainer.GetBlockBlobReference(TestBlobName);
61+
inputBlob.UploadText(TestBlobContents);
62+
}
1863
}
1964
}
2065
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"bindings": [
3+
{
4+
"type": "blobTrigger",
5+
"name": "inputBlobTrigger",
6+
"direction": "in",
7+
"path": "test-input-php/testBlobTrigger"
8+
},
9+
{
10+
"type": "blob",
11+
"name": "inputBlob",
12+
"direction": "in",
13+
"path": "test-input-php/testBlob"
14+
},
15+
{
16+
"type": "blob",
17+
"name": "outputBlob",
18+
"direction": "out",
19+
"path": "test-output-php/testBlob"
20+
}
21+
]
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
$inputBlobTrigger = file_get_contents(getenv('inputBlobTrigger'));
3+
$inputBlobTrigger = rtrim($inputBlobTrigger, "\n\r");
4+
fwrite(STDOUT, sprintf("PHP script processed blobTrigger '$inputBlobTrigger'", $string));
5+
6+
$inputBlob = file_get_contents(getenv('inputBlob'));
7+
$inputBlob = rtrim($inputBlob, "\n\r");
8+
fwrite(STDOUT, sprintf("PHP script processed blob '$inputBlob'", $string));
9+
10+
$outputBlob = fopen(getenv('outputBlob'), "w");
11+
fwrite($outputBlob, $inputBlobTrigger."_".$inputBlob);
12+
fclose($outputBlob);
13+
?>

test/WebJobs.Script.Tests/WebJobs.Script.Tests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,9 @@
995995
<None Include="TestScripts\Node\WebHookTrigger\function.json">
996996
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
997997
</None>
998+
<None Include="TestScripts\Php\BlobTriggerToBlob\function.json">
999+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
1000+
</None>
9981001
<None Include="TestScripts\Php\host.json">
9991002
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
10001003
</None>
@@ -1073,6 +1076,9 @@
10731076
<None Include="TestScripts\Python\TimeoutSync\function.json">
10741077
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
10751078
</None>
1079+
<Content Include="TestScripts\Php\BlobTriggerToBlob\run.php">
1080+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
1081+
</Content>
10761082
<Content Include="TestScripts\Python\TimeoutSync\run.py">
10771083
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
10781084
</Content>

0 commit comments

Comments
 (0)