From e2806e66d550ed88ba77d3ca46560c71aa89aeb8 Mon Sep 17 00:00:00 2001 From: Phill Morton Date: Thu, 28 Sep 2023 12:27:17 +0100 Subject: [PATCH] add test for Dapr --- test/E2ETest/TyeRunTests.cs | 8 ++- .../.idea.dapr-function-app/.idea/.gitignore | 13 +++++ .../.idea.dapr-function-app/.idea/GitLink.xml | 6 +++ .../.idea/codestream.xml | 6 +++ .../.idea/encodings.xml | 4 ++ .../.idea/indexLayout.xml | 8 +++ .../.idea.dapr-function-app/.idea/vcs.xml | 6 +++ .../dapr-function-app/dapr-function-app.sln | 6 +++ .../dapr-function-app/dapr/Program.cs | 26 ++++++++++ .../dapr/Properties/launchSettings.json | 27 ++++++++++ .../dapr-function-app/dapr/Startup.cs | 51 +++++++++++++++++++ .../dapr/appsettings.Development.json | 9 ++++ .../dapr-function-app/dapr/appsettings.json | 10 ++++ .../dapr-function-app/dapr/dapr.csproj | 11 ++++ .../projects/dapr-function-app/tye.yaml | 4 +- 15 files changed, 193 insertions(+), 2 deletions(-) create mode 100644 test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/.gitignore create mode 100644 test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/GitLink.xml create mode 100644 test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/codestream.xml create mode 100644 test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/encodings.xml create mode 100644 test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/indexLayout.xml create mode 100644 test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/vcs.xml create mode 100644 test/E2ETest/testassets/projects/dapr-function-app/dapr/Program.cs create mode 100644 test/E2ETest/testassets/projects/dapr-function-app/dapr/Properties/launchSettings.json create mode 100644 test/E2ETest/testassets/projects/dapr-function-app/dapr/Startup.cs create mode 100644 test/E2ETest/testassets/projects/dapr-function-app/dapr/appsettings.Development.json create mode 100644 test/E2ETest/testassets/projects/dapr-function-app/dapr/appsettings.json create mode 100644 test/E2ETest/testassets/projects/dapr-function-app/dapr/dapr.csproj diff --git a/test/E2ETest/TyeRunTests.cs b/test/E2ETest/TyeRunTests.cs index 642d6c31..927c1330 100644 --- a/test/E2ETest/TyeRunTests.cs +++ b/test/E2ETest/TyeRunTests.cs @@ -148,9 +148,15 @@ services: { var backendUri = await GetServiceUrl(client, uri, "dapr-test-project"); + await Task.Delay(10000); + var backendResponse = await client.GetAsync(backendUri); - + Assert.True(backendResponse.IsSuccessStatusCode); + + //The backend calls the Function app via Dapr InvokeMethod. So test that that func has a sidecar, and being proxied. + var responseContent = await backendResponse.Content.ReadAsStringAsync(); + Assert.Contains("Welcome to Azure Functions!", responseContent); }); } diff --git a/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/.gitignore b/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/.gitignore new file mode 100644 index 00000000..c122df2c --- /dev/null +++ b/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/modules.xml +/contentModel.xml +/.idea.dapr-function-app.iml +/projectSettingsUpdater.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/GitLink.xml b/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/GitLink.xml new file mode 100644 index 00000000..009597cc --- /dev/null +++ b/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/GitLink.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/codestream.xml b/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/codestream.xml new file mode 100644 index 00000000..bb40c10a --- /dev/null +++ b/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/codestream.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/encodings.xml b/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/encodings.xml new file mode 100644 index 00000000..df87cf95 --- /dev/null +++ b/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/indexLayout.xml b/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/indexLayout.xml new file mode 100644 index 00000000..7b08163c --- /dev/null +++ b/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/vcs.xml b/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/vcs.xml new file mode 100644 index 00000000..bc599707 --- /dev/null +++ b/test/E2ETest/testassets/projects/dapr-function-app/.idea/.idea.dapr-function-app/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/test/E2ETest/testassets/projects/dapr-function-app/dapr-function-app.sln b/test/E2ETest/testassets/projects/dapr-function-app/dapr-function-app.sln index 5957fe31..9dbc4f09 100644 --- a/test/E2ETest/testassets/projects/dapr-function-app/dapr-function-app.sln +++ b/test/E2ETest/testassets/projects/dapr-function-app/dapr-function-app.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 25.0.1706.3 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dapr-function-app", "function/dapr-function-app.csproj", "{0979B3EB-D56F-4402-A858-AB19B6D9B902}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dapr", "dapr\dapr.csproj", "{8336F6C8-57F3-4D80-B4AF-CFE0A9DA446E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {0979B3EB-D56F-4402-A858-AB19B6D9B902}.Debug|Any CPU.Build.0 = Debug|Any CPU {0979B3EB-D56F-4402-A858-AB19B6D9B902}.Release|Any CPU.ActiveCfg = Release|Any CPU {0979B3EB-D56F-4402-A858-AB19B6D9B902}.Release|Any CPU.Build.0 = Release|Any CPU + {8336F6C8-57F3-4D80-B4AF-CFE0A9DA446E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8336F6C8-57F3-4D80-B4AF-CFE0A9DA446E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8336F6C8-57F3-4D80-B4AF-CFE0A9DA446E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8336F6C8-57F3-4D80-B4AF-CFE0A9DA446E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/E2ETest/testassets/projects/dapr-function-app/dapr/Program.cs b/test/E2ETest/testassets/projects/dapr-function-app/dapr/Program.cs new file mode 100644 index 00000000..7a886b79 --- /dev/null +++ b/test/E2ETest/testassets/projects/dapr-function-app/dapr/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace dapr +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/test/E2ETest/testassets/projects/dapr-function-app/dapr/Properties/launchSettings.json b/test/E2ETest/testassets/projects/dapr-function-app/dapr/Properties/launchSettings.json new file mode 100644 index 00000000..58c01218 --- /dev/null +++ b/test/E2ETest/testassets/projects/dapr-function-app/dapr/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:64181", + "sslPort": 44315 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "dapr": { + "commandName": "Project", + "launchBrowser": true, + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/test/E2ETest/testassets/projects/dapr-function-app/dapr/Startup.cs b/test/E2ETest/testassets/projects/dapr-function-app/dapr/Startup.cs new file mode 100644 index 00000000..91d45e26 --- /dev/null +++ b/test/E2ETest/testassets/projects/dapr-function-app/dapr/Startup.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Dapr.Client; + +namespace dapr +{ + public class Startup + { + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseEndpoints(endpoints => + { + endpoints.MapGet("/", async context => + { + var functionAppId = "dapr-function-app"; + var methodName = "api/HttpTrigger1"; + + + var daprClient = new DaprClientBuilder().Build(); + var daprRequest = daprClient.CreateInvokeMethodRequest(HttpMethod.Post, functionAppId, methodName); + + var response = await daprClient.InvokeMethodWithResponseAsync(daprRequest); + + await context.Response.WriteAsync(await response.Content.ReadAsStringAsync()); + }); + }); + } + } +} diff --git a/test/E2ETest/testassets/projects/dapr-function-app/dapr/appsettings.Development.json b/test/E2ETest/testassets/projects/dapr-function-app/dapr/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/test/E2ETest/testassets/projects/dapr-function-app/dapr/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/test/E2ETest/testassets/projects/dapr-function-app/dapr/appsettings.json b/test/E2ETest/testassets/projects/dapr-function-app/dapr/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/test/E2ETest/testassets/projects/dapr-function-app/dapr/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/test/E2ETest/testassets/projects/dapr-function-app/dapr/dapr.csproj b/test/E2ETest/testassets/projects/dapr-function-app/dapr/dapr.csproj new file mode 100644 index 00000000..891c0a14 --- /dev/null +++ b/test/E2ETest/testassets/projects/dapr-function-app/dapr/dapr.csproj @@ -0,0 +1,11 @@ + + + + net6.0 + + + + + + + diff --git a/test/E2ETest/testassets/projects/dapr-function-app/tye.yaml b/test/E2ETest/testassets/projects/dapr-function-app/tye.yaml index 1ccba26c..bdc065eb 100644 --- a/test/E2ETest/testassets/projects/dapr-function-app/tye.yaml +++ b/test/E2ETest/testassets/projects/dapr-function-app/tye.yaml @@ -4,5 +4,7 @@ extensions: config: tracing log-level: debug services: +- name: dapr-function-app + azureFunction: function/ - name: dapr-test-project - azureFunction: function/ \ No newline at end of file + project: dapr/dapr.csproj \ No newline at end of file