Skip to content

Commit a2a11fb

Browse files
authored
Additional storage e2e coverage (#5434)
- Test for csx #r storage v9 with no nuget reference (back compat) - Test for storage rich type scenario
1 parent 9bda97e commit a2a11fb

File tree

5 files changed

+174
-0
lines changed

5 files changed

+174
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using Microsoft.Azure.WebJobs.Script.Models;
5+
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.WindowsAzure.Storage.Queue;
8+
using Xunit;
9+
10+
namespace Microsoft.Azure.WebJobs.Script.Tests.Integration.Storage
11+
{
12+
public class StorageEndToEndTests : IClassFixture<StorageEndToEndTests.StorageTestFixture>
13+
{
14+
private StorageTestFixture _fixture;
15+
16+
public StorageEndToEndTests(StorageTestFixture fixture)
17+
{
18+
_fixture = fixture;
19+
}
20+
21+
[Fact]
22+
public async Task QueueTriggerToBlobRich()
23+
{
24+
var logs = _fixture.Host.GetScriptHostLogMessages();
25+
26+
string id = Guid.NewGuid().ToString();
27+
string messageContent = string.Format("{{ \"id\": \"{0}\" }}", id);
28+
CloudQueueMessage message = new CloudQueueMessage(messageContent);
29+
30+
await _fixture.TestQueue.AddMessageAsync(message);
31+
32+
var resultBlob = _fixture.TestOutputContainer.GetBlockBlobReference(id);
33+
string result = await TestHelpers.WaitForBlobAndGetStringAsync(resultBlob);
34+
Assert.Equal(TestHelpers.RemoveByteOrderMarkAndWhitespace(messageContent), TestHelpers.RemoveByteOrderMarkAndWhitespace(result));
35+
}
36+
37+
public class StorageTestFixture : EndToEndTestFixture
38+
{
39+
public StorageTestFixture() : base(@"TestScripts\CSharp", "csharp", RpcWorkerConstants.DotNetLanguageWorkerName)
40+
{
41+
}
42+
43+
protected override ExtensionPackageReference[] GetExtensionsToInstall()
44+
{
45+
// This test fixture should use the most recent major version of the storage extension, so update this as required.
46+
return new ExtensionPackageReference[]
47+
{
48+
new ExtensionPackageReference
49+
{
50+
Id = "Microsoft.Azure.WebJobs.Extensions.Storage",
51+
Version = "3.0.10"
52+
}
53+
};
54+
}
55+
56+
public override void ConfigureScriptHost(IWebJobsBuilder webJobsBuilder)
57+
{
58+
webJobsBuilder.Services.Configure<ScriptJobHostOptions>(o =>
59+
{
60+
o.Functions = new[]
61+
{
62+
"QueueTriggerToBlobRichTypes",
63+
};
64+
});
65+
}
66+
}
67+
}
68+
69+
70+
public class StorageV9EndToEndTests : IClassFixture<StorageV9EndToEndTests.StorageReferenceTestFixture>
71+
{
72+
private EndToEndTestFixture _fixture;
73+
74+
public StorageV9EndToEndTests(StorageReferenceTestFixture fixture)
75+
{
76+
_fixture = fixture;
77+
}
78+
79+
[Fact]
80+
public async Task CanUseStorageV9Types()
81+
{
82+
// The point of this test is to verify back compat behavior that a user can still #r and use storage v9 types in CSX,
83+
// regardless of whether the storage extension installed (and of what version)
84+
85+
string testData = Guid.NewGuid().ToString();
86+
87+
await _fixture.Host.BeginFunctionAsync("StorageReferenceV9", testData);
88+
89+
await TestHelpers.Await(() =>
90+
{
91+
// make sure the function executed successfully
92+
var logs = _fixture.Host.GetScriptHostLogMessages();
93+
return logs.Any(p => p.FormattedMessage != null && p.FormattedMessage.Contains(testData));
94+
}, userMessageCallback: _fixture.Host.GetLog);
95+
}
96+
97+
public class StorageReferenceTestFixture : EndToEndTestFixture
98+
{
99+
public StorageReferenceTestFixture() : base(@"TestScripts\CSharp", "csharp", RpcWorkerConstants.DotNetLanguageWorkerName)
100+
{
101+
}
102+
103+
protected override ExtensionPackageReference[] GetExtensionsToInstall()
104+
{
105+
// It is explicitly intended that this scenario has no package references
106+
return new ExtensionPackageReference[]
107+
{
108+
};
109+
}
110+
111+
public override void ConfigureScriptHost(IWebJobsBuilder webJobsBuilder)
112+
{
113+
webJobsBuilder.Services.Configure<ScriptJobHostOptions>(o =>
114+
{
115+
o.Functions = new[]
116+
{
117+
"StorageReferenceV9",
118+
};
119+
});
120+
}
121+
}
122+
}
123+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"bindings": [
3+
{
4+
"type": "queueTrigger",
5+
"name": "input",
6+
"queueName": "test-input-csharp",
7+
"direction": "in"
8+
},
9+
{
10+
"type": "blob",
11+
"name": "output",
12+
"direction": "inout",
13+
"path": "test-output-csharp/{id}"
14+
}
15+
]
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#r "Microsoft.WindowsAzure.Storage"
2+
using Microsoft.WindowsAzure.Storage.Blob;
3+
4+
public static async Task Run(WorkItem input, CloudBlockBlob output, TraceWriter log)
5+
{
6+
string json = string.Format("{{ \"id\": \"{0}\" }}", input.Id);
7+
8+
log.Info($"C# script processed queue message. Item={json}");
9+
10+
await output.UploadTextAsync(json);
11+
}
12+
13+
public class WorkItem
14+
{
15+
public string Id { get; set; }
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"bindings": [
3+
{
4+
"type": "manualTrigger",
5+
"name": "input",
6+
"direction": "in"
7+
}
8+
]
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Use storage v9
2+
#r "Microsoft.WindowsAzure.Storage"
3+
using Microsoft.WindowsAzure.Storage.Blob;
4+
5+
public static void Run(string input, TraceWriter log)
6+
{
7+
// it is enough to just reference the type - as long as compilation is successful, we're good
8+
CloudBlockBlob blob;
9+
log.Info(input);
10+
}

0 commit comments

Comments
 (0)