Skip to content

Commit b2b140e

Browse files
committed
More refactoring and added integration tests for different auth types
1 parent c2bb55e commit b2b140e

23 files changed

+312
-150
lines changed

.github/workflows/test_azure_devtest_labs_integration.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on:
1818
jobs:
1919
# This workflow contains a single job called "build"
2020
build-and-integration-test:
21+
name: Build and run tests on Azure DevTest Labs
2122
# The type of runner that the job will run on
2223
runs-on: ubuntu-latest
2324

@@ -53,7 +54,7 @@ jobs:
5354
# ls -ltAR ./${{ env.FUNCTIONS_PROJECT_NAME }}/bin/${{ env.BUILD_CONFIGURATION }}
5455

5556
- name: Run Unit Tests
56-
run: dotnet test --no-build --configuration ${{ env.BUILD_CONFIGURATION }} --filter TestCategory=UnitTest --output ./output --verbosity normal
57+
run: dotnet test --no-build --configuration ${{ env.BUILD_CONFIGURATION }} --filter TestCategory=UnitTest --output ./output --results-directory ./test-results --verbosity normal --logger "trx;LogFileName=unit-test-results.trx"
5758

5859

5960
# Login to Azure
@@ -134,8 +135,16 @@ jobs:
134135

135136

136137
- name: Run Integration Tests
137-
run: dotnet test --no-build --configuration ${{ env.BUILD_CONFIGURATION }} --filter TestCategory=IntegrationTest --output ./output --verbosity normal --settings ${{ env.RUN_SETTINGS_FILENAME }}
138+
run: dotnet test --no-build --configuration ${{ env.BUILD_CONFIGURATION }} --filter TestCategory=IntegrationTest --output ./output --results-directory ./test-results --verbosity normal --logger "trx;LogFileName=integration-test-results.trx" --settings ${{ env.RUN_SETTINGS_FILENAME }}
138139

139140

140141

142+
- name: Publish Test Report
143+
uses: dorny/test-reporter@v1
144+
if: success() || failure() # run this step even if previous step failed
145+
with:
146+
name: Tests # Name of the check run which will be created
147+
path: ./test-results/*.trx # Path to test results
148+
reporter: dotnet-trx # Format of test results
149+
141150

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
using System;
2-
using System.Net;
3-
using System.Net.Http;
4-
using System.Threading.Tasks;
5-
using System.Web;
61
using DataPipelineTools.Tests.Common;
72
using Microsoft.Extensions.Logging;
83
using NUnit.Framework;
4+
using SqlCollaborative.Azure.DataPipelineTools.Functions.DataLake;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Net;
8+
using System.Threading.Tasks;
9+
using SqlCollaborative.Azure.DataPipelineTools.DataLake.Model;
910

1011
namespace DataPipelineTools.Functions.Tests.DataLake.DataLakeFunctions.Integration
1112
{
1213
[TestFixture]
1314
[Category(nameof(TestType.IntegrationTest))]
15+
[Parallelizable(ParallelScope.Children)]
1416
public class DataLakeGetItemsIntegrationTests: IntegrationTestBase
1517
{
1618
protected override string FunctionUri => $"{FunctionsAppUrl}/api/DataLakeGetItems";
@@ -25,33 +27,60 @@ public void Setup()
2527
}
2628

2729
[Test]
28-
public async Task Test_FunctionIsRunnable()
30+
public async Task Test_FunctionIsRunnable_With_FunctionsServicePrincipalAuth()
2931
{
30-
using (var client = new HttpClient())
32+
var parameters = new Dictionary<string, string>
3133
{
32-
var queryParams = HttpUtility.ParseQueryString(string.Empty);
33-
queryParams["account"] = this.StorageAccountName;
34-
queryParams["container"] = this.StorageContainerName;
34+
{DataLakeConfigFactory.AccountParam, StorageAccountName},
35+
{DataLakeConfigFactory.ContainerParam, StorageContainerName}
36+
};
37+
var response = await RunQueryFromParameters(parameters);
38+
LogContent(response);
39+
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
3540

36-
if (!IsEmulatorRunning)
37-
queryParams["code"] = this.FunctionsAppKey;
41+
// Check response details. Its important to cast the actual or we test against JToken from the dynamic results
42+
dynamic results = GetResultsObject(response);
43+
Assert.AreEqual(AuthType.FunctionsServicePrincipal, (AuthType)results.authType);
44+
}
3845

39-
var urlBuilder = new UriBuilder(FunctionUri)
40-
{
41-
Query = queryParams.ToString() ?? string.Empty
42-
};
43-
var queryUrl = urlBuilder.ToString();
46+
[Test]
47+
public async Task Test_FunctionIsRunnable_With_UserServicePrincipalAuthAndPlainTextKey()
48+
{
49+
var parameters = new Dictionary<string, string>
50+
{
51+
{DataLakeConfigFactory.AccountParam, StorageAccountName},
52+
{DataLakeConfigFactory.ContainerParam, StorageContainerName},
53+
{DataLakeConfigFactory.ServicePrincipalClientIdParam, ServicePrincipalName},
54+
{DataLakeConfigFactory.ServicePrincipalClientSecretParam, ServicePrincipalSecretKey},
55+
};
56+
var response = await RunQueryFromParameters(parameters);
57+
LogContent(response);
58+
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
4459

45-
if (!IsRunningOnCIServer)
46-
Logger.LogInformation($"Query URL: {queryUrl}");
47-
48-
var result = await client.GetAsync(queryUrl);
49-
var content = result.Content.ReadAsStringAsync().Result;
60+
// Check response details. Its important to cast the actual or we test against JToken from the dynamic results
61+
dynamic results = GetResultsObject(response);
62+
Assert.AreEqual(AuthType.UserServicePrincipal, (AuthType)results.authType);
63+
}
5064

51-
Logger.LogInformation($"Content: {content}");
65+
[Test]
66+
public async Task Test_FunctionIsRunnable_With_UserServicePrincipalAuthAndKeyVaultKeyName()
67+
{
68+
var parameters = new Dictionary<string, string>
69+
{
70+
{DataLakeConfigFactory.AccountParam, StorageAccountName},
71+
{DataLakeConfigFactory.ContainerParam, StorageContainerName},
72+
{DataLakeConfigFactory.ServicePrincipalClientIdParam, ServicePrincipalName},
73+
{DataLakeConfigFactory.ServicePrincipalClientSecretParam, ServicePrincipalSecretKeyName},
74+
{DataLakeConfigFactory.KeyVaultParam, KeyVaultName}
75+
};
76+
var response = await RunQueryFromParameters(parameters);
77+
LogContent(response);
78+
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
5279

53-
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
54-
}
80+
// Check response details. Its important to cast the actual or we test against JToken from the dynamic results
81+
dynamic results = GetResultsObject(response);
82+
Assert.AreEqual(AuthType.UserServicePrincipal, (AuthType)results.authType);
5583
}
84+
5685
}
5786
}

DataPipelineTools.Functions.Tests/DataPipelineTools.Functions.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.2.0" />
1716
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
17+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
1818
<PackageReference Include="NUnit" Version="3.13.1" />
1919
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
2020
<PackageReference Include="coverlet.collector" Version="3.0.2" />

0 commit comments

Comments
 (0)