From 0ab670a14327aa2d2ee1930173186d786d760f0f Mon Sep 17 00:00:00 2001 From: Tom Pallister Date: Sat, 17 Mar 2018 18:07:27 +0000 Subject: [PATCH] Feature/#52 (#283) * #52 test circle ci * #52 nicked some lads cake script * #52 put the mac build script back * #52 trying another lads circle CI thing doesnt use cake * #52 added test steps * #52 ports for linux build * #52 try travis mac build * #52 dont use build script * #52 dont use build script * #52 acceptance and int tests dont really work on mac...v strange? * #52 unique port for linux tests * #52 increase code coverage * #52 try using cake on linux for travis * #52 try using cake for mac and linux on travis * #52 dont run the acceptance and int tests on mac * #52 build.sh has lf line endings * #52 turns out crlf is OK for cake file..sigh * #52 not sure what return does in cake so wrapped in if just to see * #52 try use travis to work not run on mac * #52 dont need these references * #52 wrong property * #52 remove circle ci for linux and just use travis for all --- .circleci/config.yml | 17 ++++++ .travis.yml | 31 +++++++++++ README.md | 3 +- build.cake | 36 +++++++++++++ build.sh | 2 +- .../LoadBalancerTests.cs | 4 +- test/Ocelot.AcceptanceTests/QoSTests.cs | 4 +- .../OcelotPipelineExtensionsTests.cs | 53 +++++++++++++++++++ 8 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 .travis.yml create mode 100644 test/Ocelot.UnitTests/Middleware/OcelotPipelineExtensionsTests.cs diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..8abd6ffd --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,17 @@ +version: 2 +jobs: + build: + working_directory: /temp + docker: + - image: microsoft/dotnet:sdk + environment: + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + steps: + - checkout + - run: dotnet restore + - run: dotnet build + - run: dotnet test ./test/Ocelot.UnitTests/Ocelot.UnitTests.csproj + - run: dotnet test ./test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj + - run: dotnet test ./test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj + diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..ef0701aa --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +language: csharp +os: + - osx + - linux + +# Ubuntu 14.04 +sudo: required +dist: trusty + +# OS X 10.12 +osx_image: xcode9.2 + +mono: + - 4.4.2 + +dotnet: 2.1.4 + +before_install: + - git fetch --unshallow # Travis always does a shallow clone, but GitVersion needs the full history including branches and tags + - git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" + - git fetch origin + +script: + - ./build.sh + +cache: + directories: + - .packages + - tools/Addins + - tools/gitreleasemanager + - tools/GitVersion.CommandLine \ No newline at end of file diff --git a/README.md b/README.md index 6bbc77e0..ab3d89a5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ [](http://threemammals.com/ocelot) -[![Build status](https://ci.appveyor.com/api/projects/status/r6sv51qx36sis1je?svg=true)](https://ci.appveyor.com/project/TomPallister/ocelot-fcfpb) +[![Build status](https://ci.appveyor.com/api/projects/status/r6sv51qx36sis1je?branch=develop&svg=true)](https://ci.appveyor.com/project/TomPallister/ocelot-fcfpb) Windows (AppVeyor) +[![Build Status](https://travis-ci.org/ThreeMammals/Ocelot.svg?branch=develop)](https://travis-ci.org/ThreeMammals/Ocelot) Linux & OSX (Travis) [![Windows Build history](https://buildstats.info/appveyor/chart/TomPallister/ocelot-fcfpb?branch=develop&includeBuildsFromPullRequest=false)](https://ci.appveyor.com/project/TomPallister/ocelot-fcfpb/history?branch=develop) diff --git a/build.cake b/build.cake index c732864b..f757228c 100644 --- a/build.cake +++ b/build.cake @@ -189,6 +189,24 @@ Task("RunAcceptanceTests") .IsDependentOn("Compile") .Does(() => { + if(TravisCI.IsRunningOnTravisCI) + { + Information( + @"Job: + JobId: {0} + JobNumber: {1} + OSName: {2}", + BuildSystem.TravisCI.Environment.Job.JobId, + BuildSystem.TravisCI.Environment.Job.JobNumber, + BuildSystem.TravisCI.Environment.Job.OSName + ); + + if(TravisCI.Environment.Job.OSName.ToLower() == "osx") + { + return; + } + } + var settings = new DotNetCoreTestSettings { Configuration = compileConfig, @@ -205,6 +223,24 @@ Task("RunIntegrationTests") .IsDependentOn("Compile") .Does(() => { + if(TravisCI.IsRunningOnTravisCI) + { + Information( + @"Job: + JobId: {0} + JobNumber: {1} + OSName: {2}", + BuildSystem.TravisCI.Environment.Job.JobId, + BuildSystem.TravisCI.Environment.Job.JobNumber, + BuildSystem.TravisCI.Environment.Job.OSName + ); + + if(TravisCI.Environment.Job.OSName.ToLower() == "osx") + { + return; + } + } + var settings = new DotNetCoreTestSettings { Configuration = compileConfig, diff --git a/build.sh b/build.sh index 04731adf..5b3d6020 100755 --- a/build.sh +++ b/build.sh @@ -98,4 +98,4 @@ if $SHOW_VERSION; then exec mono "$CAKE_EXE" -version else exec mono "$CAKE_EXE" $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}" -fi \ No newline at end of file +fi diff --git a/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs b/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs index d67e7e41..f60008bd 100644 --- a/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs +++ b/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs @@ -31,7 +31,7 @@ namespace Ocelot.AcceptanceTests public void should_use_service_discovery_and_load_balance_request() { var downstreamServiceOneUrl = "http://localhost:50881"; - var downstreamServiceTwoUrl = "http://localhost:50882"; + var downstreamServiceTwoUrl = "http://localhost:50892"; var configuration = new FileConfiguration { @@ -54,7 +54,7 @@ namespace Ocelot.AcceptanceTests new FileHostAndPort { Host = "localhost", - Port = 50882 + Port = 50892 } } } diff --git a/test/Ocelot.AcceptanceTests/QoSTests.cs b/test/Ocelot.AcceptanceTests/QoSTests.cs index d11721b8..5e82ba3d 100644 --- a/test/Ocelot.AcceptanceTests/QoSTests.cs +++ b/test/Ocelot.AcceptanceTests/QoSTests.cs @@ -41,7 +41,7 @@ namespace Ocelot.AcceptanceTests new FileHostAndPort { Host = "localhost", - Port = 51872, + Port = 51892, } }, UpstreamPathTemplate = "/", @@ -56,7 +56,7 @@ namespace Ocelot.AcceptanceTests } }; - this.Given(x => x.GivenThereIsAPossiblyBrokenServiceRunningOn("http://localhost:51872", "Hello from Laura")) + this.Given(x => x.GivenThereIsAPossiblyBrokenServiceRunningOn("http://localhost:51892", "Hello from Laura")) .Given(x => _steps.GivenThereIsAConfiguration(configuration)) .Given(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) diff --git a/test/Ocelot.UnitTests/Middleware/OcelotPipelineExtensionsTests.cs b/test/Ocelot.UnitTests/Middleware/OcelotPipelineExtensionsTests.cs new file mode 100644 index 00000000..d61124ba --- /dev/null +++ b/test/Ocelot.UnitTests/Middleware/OcelotPipelineExtensionsTests.cs @@ -0,0 +1,53 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Moq; +using Ocelot.Configuration; +using Ocelot.Configuration.Builder; +using Ocelot.DependencyInjection; +using Ocelot.Middleware; +using Ocelot.Middleware.Multiplexer; +using Ocelot.Middleware.Pipeline; +using Shouldly; +using TestStack.BDDfy; +using Xunit; + +namespace Ocelot.UnitTests.Middleware +{ + public class OcelotPipelineExtensionsTests + { + private OcelotPipelineBuilder _builder; + private OcelotRequestDelegate _handlers; + + [Fact] + public void should_set_up_pipeline() + { + this.Given(_ => GivenTheDepedenciesAreSetUp()) + .When(_ => WhenIBuild()) + .Then(_ => ThenThePipelineIsBuilt()) + .BDDfy(); + } + + private void ThenThePipelineIsBuilt() + { + _handlers.ShouldNotBeNull(); + } + + private void WhenIBuild() + { + _handlers = _builder.BuildOcelotPipeline(new OcelotPipelineConfiguration()); + } + + private void GivenTheDepedenciesAreSetUp() + { + IConfigurationBuilder test = new ConfigurationBuilder(); + var root = test.Build(); + var services = new ServiceCollection(); + services.AddSingleton(root); + services.AddOcelot(); + var provider = services.BuildServiceProvider(); + _builder = new OcelotPipelineBuilder(provider); + } + } +} \ No newline at end of file