Skip to content

Commit 9ebf44f

Browse files
E2e test suite from Nodejs worker (#139)
* Add e2e test suite from java worker * add to appveyor for CI * remove Invoke-Test for e2e * move test csproj * fix path in module tests * change to capital T * uppercase another T * delete extensions.csproj * add silentlyContinue to Remove-Item * props file is one directory up
1 parent a998cbc commit 9ebf44f

File tree

48 files changed

+828
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+828
-403
lines changed

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ build_script:
2626
2727
test_script:
2828
- pwsh: ./build.ps1 -NoBuild -Test
29+
- pwsh: ./test/E2E/Start-E2ETest.ps1
2930

3031
on_finish:
3132
- pwsh: dir *.PowerShellWorker.*.nupkg -Recurse | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }

azure-functions-powershell-worker.sln

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.Functions.P
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{12092936-4F2A-4B40-9AF2-56C840D44FEA}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.Functions.PowerShellWorker.Test", "test\Microsoft.Azure.Functions.PowerShellWorker.Test.csproj", "{535C8DA3-479D-42BF-B1AF-5B03ECAF67A4}"
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test\Unit", "test\Unit", "{84b1665e-f5a8-4044-81da-611f1e40508f}"
13+
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.Functions.PowerShellWorker.Test", "test\Unit\Microsoft.Azure.Functions.PowerShellWorker.Test.csproj", "{535C8DA3-479D-42BF-B1AF-5B03ECAF67A4}"
1315
EndProject
1416
Global
1517
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -51,6 +53,7 @@ Global
5153
EndGlobalSection
5254
GlobalSection(NestedProjects) = preSolution
5355
{939262BA-4823-405E-81CD-436C0B77D524} = {8C758288-3909-4CE1-972D-1BE966628D6C}
54-
{535C8DA3-479D-42BF-B1AF-5B03ECAF67A4} = {12092936-4F2A-4B40-9AF2-56C840D44FEA}
56+
{84b1665e-f5a8-4044-81da-611f1e40508f} = {12092936-4F2A-4B40-9AF2-56C840D44FEA}
57+
{535C8DA3-479D-42BF-B1AF-5B03ECAF67A4} = {84b1665e-f5a8-4044-81da-611f1e40508f}
5558
EndGlobalSection
5659
EndGlobal

build.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ if($Test.IsPresent) {
8787
throw "Cannot find the 'Pester' module. Please specify '-Bootstrap' to install build dependencies."
8888
}
8989

90-
dotnet test "$PSScriptRoot/test"
90+
dotnet test "$PSScriptRoot/test/Unit"
9191
if ($LASTEXITCODE -ne 0) { throw "xunit tests failed." }
9292

9393
Invoke-Tests -Path "$PSScriptRoot/test/Unit/Modules" -OutputFile UnitTestsResults.xml
94-
Invoke-Tests -Path "$PSScriptRoot/test/E2E" -OutputFile E2ETestsResults.xml
9594
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27703.2026
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Functions.PowerShellWorker.E2E", "Azure.Functions.PowerShellWorker.E2E\Azure.Functions.PowerShellWorker.E2E.csproj", "{E7229DBA-DCF2-44B9-ACB8-D6E8AE906AB3}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E7229DBA-DCF2-44B9-ACB8-D6E8AE906AB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E7229DBA-DCF2-44B9-ACB8-D6E8AE906AB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E7229DBA-DCF2-44B9-ACB8-D6E8AE906AB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E7229DBA-DCF2-44B9-ACB8-D6E8AE906AB3}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {96355275-963C-4A13-92EB-5F7CB415269F}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.1.1" />
11+
<PackageReference Include="Microsoft.Azure.EventHubs" Version="2.2.1" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
13+
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
14+
<PackageReference Include="WindowsAzure.Storage" Version="9.3.2" />
15+
<PackageReference Include="xunit" Version="2.3.1" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
6+
namespace Azure.Functions.PowerShell.Tests.E2E
7+
{
8+
public static class Constants
9+
{
10+
public static string FunctionsHostUrl = "http://localhost:7071";
11+
//Queue tests
12+
public static class Queue {
13+
public static string StorageConnectionStringSetting = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
14+
public static string OutputBindingName = "test-output-ps";
15+
public static string InputBindingName = "test-input-ps";
16+
}
17+
18+
// CosmosDB tests
19+
public static class CosmosDB {
20+
public static string CosmosDBConnectionStringSetting = Environment.GetEnvironmentVariable("AzureWebJobsCosmosDBConnectionString");
21+
public static string DbName = "ItemDb";
22+
public static string InputCollectionName = "ItemCollectionIn";
23+
public static string OutputCollectionName = "ItemCollectionOut";
24+
public static string LeaseCollectionName = "leases";
25+
}
26+
27+
// EventHubs
28+
public static class EventHubs {
29+
public static string EventHubsConnectionStringSetting = Environment.GetEnvironmentVariable("AzureWebJobsEventHubSender");
30+
31+
public static class Json_Test {
32+
public static string OutputName = "test-output-object-ps";
33+
public static string InputName = "test-input-object-ps";
34+
}
35+
36+
public static class String_Test {
37+
public static string OutputName = "test-output-string-ps";
38+
public static string InputName = "test-input-string-ps";
39+
}
40+
41+
public static class Cardinality_One_Test {
42+
public static string InputName = "test-input-one-ps";
43+
public static string OutputName = "test-output-one-ps";
44+
}
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
8+
namespace Azure.Functions.PowerShell.Tests.E2E
9+
{
10+
public class CosmosDBEndToEndTests
11+
{
12+
[Fact]
13+
public async Task CosmosDBTriggerAndOutput_Succeeds()
14+
{
15+
string expectedDocId = Guid.NewGuid().ToString();
16+
try
17+
{
18+
//Setup
19+
await CosmosDBHelpers.CreateDocumentCollections();
20+
21+
//Trigger
22+
await CosmosDBHelpers.CreateDocument(expectedDocId);
23+
24+
//Read
25+
var documentId = await CosmosDBHelpers.ReadDocument(expectedDocId);
26+
Assert.Equal(expectedDocId, documentId);
27+
}
28+
finally
29+
{
30+
//Clean up
31+
await CosmosDBHelpers.DeleteTestDocuments(expectedDocId);
32+
}
33+
}
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using Newtonsoft.Json.Linq;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
using Xunit;
10+
11+
namespace Azure.Functions.PowerShell.Tests.E2E
12+
{
13+
public class EventHubsEndToEndTests
14+
{
15+
[Fact]
16+
public async Task EventHubTriggerAndOutputJSON_Succeeds()
17+
{
18+
string expectedEventId = Guid.NewGuid().ToString();
19+
try
20+
{
21+
await SetupQueue(Constants.EventHubs.Json_Test.OutputName);
22+
23+
// Need to setup EventHubs: test-inputjson-powershell and test-outputjson-powershell
24+
await EventHubsHelpers.SendJSONMessagesAsync(expectedEventId, Constants.EventHubs.Json_Test.InputName);
25+
26+
//Verify
27+
var queueMessage = await StorageHelpers.ReadFromQueue(Constants.EventHubs.Json_Test.OutputName);
28+
JObject json = JObject.Parse(queueMessage);
29+
Assert.Contains(expectedEventId, json["value"].ToString());
30+
}
31+
finally
32+
{
33+
//Clear queue
34+
await StorageHelpers.ClearQueue(Constants.EventHubs.Json_Test.OutputName);
35+
}
36+
}
37+
38+
[Fact]
39+
public async Task EventHubTriggerAndOutputString_Succeeds()
40+
{
41+
string expectedEventId = Guid.NewGuid().ToString();
42+
try
43+
{
44+
await SetupQueue(Constants.EventHubs.String_Test.OutputName);
45+
46+
// Need to setup EventHubs: test-input-one-ps
47+
await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.EventHubs.String_Test.InputName);
48+
49+
//Verify
50+
var queueMessage = await StorageHelpers.ReadFromQueue(Constants.EventHubs.String_Test.OutputName);
51+
Assert.Contains(expectedEventId, queueMessage);
52+
}
53+
finally
54+
{
55+
//Clear queue
56+
await StorageHelpers.ClearQueue(Constants.EventHubs.String_Test.OutputName);
57+
}
58+
}
59+
60+
[Fact]
61+
public async Task EventHubTriggerCardinalityOne_Succeeds()
62+
{
63+
string expectedEventId = Guid.NewGuid().ToString();
64+
try
65+
{
66+
await SetupQueue(Constants.EventHubs.Cardinality_One_Test.OutputName);
67+
68+
// Need to setup EventHubs: test-inputOne-powershell and test-outputone-powershell
69+
await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.EventHubs.Cardinality_One_Test.InputName);
70+
71+
//Verify
72+
IEnumerable<string> queueMessages = await StorageHelpers.ReadMessagesFromQueue(Constants.EventHubs.Cardinality_One_Test.OutputName);
73+
Assert.True(queueMessages.All(msg => msg.Contains(expectedEventId)));
74+
}
75+
finally
76+
{
77+
//Clear queue
78+
await StorageHelpers.ClearQueue(Constants.EventHubs.Cardinality_One_Test.OutputName);
79+
}
80+
}
81+
82+
private static async Task SetupQueue(string queueName)
83+
{
84+
//Clear queue
85+
await StorageHelpers.ClearQueue(queueName);
86+
87+
//Set up and trigger
88+
await StorageHelpers.CreateQueue(queueName);
89+
}
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.Documents;
7+
using Microsoft.Azure.Documents.Client;
8+
9+
namespace Azure.Functions.PowerShell.Tests.E2E
10+
{
11+
public class TestDocument
12+
{
13+
public string id { get; set; }
14+
public string name { get; set; }
15+
}
16+
17+
public static class CosmosDBHelpers
18+
{
19+
private static DocumentClient _docDbClient;
20+
private static Uri inputCollectionsUri = UriFactory.CreateDocumentCollectionUri(Constants.CosmosDB.DbName, Constants.CosmosDB.InputCollectionName);
21+
private static Uri outputCollectionsUri = UriFactory.CreateDocumentCollectionUri(Constants.CosmosDB.DbName, Constants.CosmosDB.OutputCollectionName);
22+
private static Uri leasesCollectionsUri = UriFactory.CreateDocumentCollectionUri(Constants.CosmosDB.DbName, Constants.CosmosDB.LeaseCollectionName);
23+
24+
static CosmosDBHelpers()
25+
{
26+
var builder = new System.Data.Common.DbConnectionStringBuilder();
27+
builder.ConnectionString = Constants.CosmosDB.CosmosDBConnectionStringSetting;
28+
var serviceUri = new Uri(builder["AccountEndpoint"].ToString());
29+
_docDbClient = new DocumentClient(serviceUri, builder["AccountKey"].ToString());
30+
}
31+
32+
// keep
33+
public async static Task CreateDocument(string docId)
34+
{
35+
Document documentToTest = new Document()
36+
{
37+
Id = docId
38+
};
39+
40+
Document insertedDoc = await _docDbClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(Constants.CosmosDB.DbName, Constants.CosmosDB.InputCollectionName), documentToTest);
41+
}
42+
43+
public async static Task CreateDocument(TestDocument testDocument)
44+
{
45+
Document insertedDoc = await _docDbClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(Constants.CosmosDB.DbName, Constants.CosmosDB.InputCollectionName), testDocument);
46+
}
47+
48+
// keep
49+
public async static Task<string> ReadDocument(string docId)
50+
{
51+
var docUri = UriFactory.CreateDocumentUri(Constants.CosmosDB.DbName, Constants.CosmosDB.OutputCollectionName, docId);
52+
Document retrievedDocument = null;
53+
await Utilities.RetryAsync(async () =>
54+
{
55+
try
56+
{
57+
retrievedDocument = await _docDbClient.ReadDocumentAsync(docUri);
58+
return true;
59+
}
60+
catch (DocumentClientException ex) when (ex.Error.Code == "NotFound")
61+
{
62+
return false;
63+
}
64+
}, 120000, 4000);
65+
return retrievedDocument.Id;
66+
}
67+
68+
// keep
69+
public async static Task DeleteTestDocuments(string docId)
70+
{
71+
var inputDocUri = UriFactory.CreateDocumentUri(Constants.CosmosDB.DbName, Constants.CosmosDB.InputCollectionName, docId);
72+
await DeleteDocument(inputDocUri);
73+
var outputDocUri = UriFactory.CreateDocumentUri(Constants.CosmosDB.DbName, Constants.CosmosDB.OutputCollectionName, docId);
74+
await DeleteDocument(outputDocUri);
75+
}
76+
77+
private async static Task DeleteDocument(Uri docUri)
78+
{
79+
try
80+
{
81+
await _docDbClient.DeleteDocumentAsync(docUri);
82+
}
83+
catch (Exception)
84+
{
85+
//ignore
86+
}
87+
}
88+
89+
// keep
90+
public async static Task CreateDocumentCollections()
91+
{
92+
Database db = await _docDbClient.CreateDatabaseIfNotExistsAsync(new Database { Id = Constants.CosmosDB.DbName });
93+
Uri dbUri = UriFactory.CreateDatabaseUri(db.Id);
94+
95+
await CreateCollection(dbUri, Constants.CosmosDB.InputCollectionName);
96+
await CreateCollection(dbUri, Constants.CosmosDB.OutputCollectionName);
97+
await CreateCollection(dbUri, Constants.CosmosDB.LeaseCollectionName);
98+
99+
}
100+
public async static Task DeleteDocumentCollections()
101+
{
102+
await DeleteCollection(inputCollectionsUri);
103+
await DeleteCollection(outputCollectionsUri);
104+
await DeleteCollection(leasesCollectionsUri);
105+
}
106+
107+
private async static Task DeleteCollection(Uri collectionUri)
108+
{
109+
try
110+
{
111+
await _docDbClient.DeleteDocumentCollectionAsync(collectionUri);
112+
}
113+
catch (Exception)
114+
{
115+
//Ignore
116+
}
117+
}
118+
119+
private async static Task CreateCollection(Uri dbUri, string collectioName)
120+
{
121+
DocumentCollection collection = new DocumentCollection() { Id = collectioName };
122+
await _docDbClient.CreateDocumentCollectionIfNotExistsAsync(dbUri, collection,
123+
new RequestOptions()
124+
{
125+
OfferThroughput = 400
126+
});
127+
}
128+
}
129+
}

0 commit comments

Comments
 (0)