Skip to content

Commit

Permalink
Merge branch 'jlukawska-feature/1115-find-available-port-in-acceptanc…
Browse files Browse the repository at this point in the history
…e-tests'
  • Loading branch information
TomPallister committed Mar 11, 2020
2 parents 08512ec + 36064b1 commit b280b1c
Show file tree
Hide file tree
Showing 39 changed files with 673 additions and 392 deletions.
90 changes: 52 additions & 38 deletions test/Ocelot.AcceptanceTests/AggregateTests.cs

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions test/Ocelot.AcceptanceTests/AuthenticationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class AuthenticationTests : IDisposable
{
private readonly Steps _steps;
private IWebHost _identityServerBuilder;
private string _identityServerRootUrl = "http://localhost:51888";
private string _identityServerRootUrl;
private string _downstreamServicePath = "/";
private string _downstreamServiceHost = "localhost";
private string _downstreamServiceScheme = "http";
Expand All @@ -31,7 +31,9 @@ public class AuthenticationTests : IDisposable
public AuthenticationTests()
{
_serviceHandler = new ServiceHandler();
_steps = new Steps();
_steps = new Steps();
var identityServerPort = RandomPortFinder.GetRandomPort();
_identityServerRootUrl = $"http://localhost:{identityServerPort}";
_options = o =>
{
o.Authority = _identityServerRootUrl;
Expand All @@ -45,7 +47,7 @@ public AuthenticationTests()
[Fact]
public void should_return_401_using_identity_server_access_token()
{
int port = 54329;
int port = RandomPortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -86,7 +88,7 @@ public void should_return_401_using_identity_server_access_token()
[Fact]
public void should_return_response_200_using_identity_server()
{
int port = 54099;
int port = RandomPortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -129,7 +131,7 @@ public void should_return_response_200_using_identity_server()
[Fact]
public void should_return_response_401_using_identity_server_with_token_requested_for_other_api()
{
int port = 54196;
int port = RandomPortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -171,7 +173,7 @@ public void should_return_response_401_using_identity_server_with_token_requeste
[Fact]
public void should_return_201_using_identity_server_access_token()
{
int port = 52226;
int port = RandomPortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -214,7 +216,7 @@ public void should_return_201_using_identity_server_access_token()
[Fact]
public void should_return_201_using_identity_server_reference_token()
{
int port = 52222;
int port = RandomPortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down
36 changes: 19 additions & 17 deletions test/Ocelot.AcceptanceTests/AuthorisationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ public class AuthorisationTests : IDisposable
private IWebHost _identityServerBuilder;
private readonly Steps _steps;
private readonly Action<IdentityServerAuthenticationOptions> _options;
private string _identityServerRootUrl = "http://localhost:51888";
private string _identityServerRootUrl;
private readonly ServiceHandler _serviceHandler;

public AuthorisationTests()
{
_serviceHandler = new ServiceHandler();
_steps = new Steps();
_steps = new Steps();
var identityServerPort = RandomPortFinder.GetRandomPort();
_identityServerRootUrl = $"http://localhost:{identityServerPort}";
_options = o =>
{
o.Authority = _identityServerRootUrl;
Expand All @@ -41,7 +43,7 @@ public AuthorisationTests()
[Fact]
public void should_return_response_200_authorising_route()
{
int port = 52875;
int port = RandomPortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -86,9 +88,9 @@ public void should_return_response_200_authorising_route()
}
};

this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
.And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
.And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
.And(x => _steps.GivenIHaveAddedATokenToMyRequest())
Expand All @@ -101,7 +103,7 @@ public void should_return_response_200_authorising_route()
[Fact]
public void should_return_response_403_authorising_route()
{
int port = 59471;
int port = RandomPortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -145,9 +147,9 @@ public void should_return_response_403_authorising_route()
}
};

this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
.And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
.And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
.And(x => _steps.GivenIHaveAddedATokenToMyRequest())
Expand All @@ -159,7 +161,7 @@ public void should_return_response_403_authorising_route()
[Fact]
public void should_return_response_200_using_identity_server_with_allowed_scope()
{
int port = 63471;
int port = RandomPortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -188,9 +190,9 @@ public void should_return_response_200_using_identity_server_with_allowed_scope(
}
};

this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
.And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
.And(x => _steps.GivenIHaveATokenForApiReadOnlyScope("http://localhost:51888"))
.And(x => _steps.GivenIHaveATokenForApiReadOnlyScope(_identityServerRootUrl))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
.And(x => _steps.GivenIHaveAddedATokenToMyRequest())
Expand All @@ -202,7 +204,7 @@ public void should_return_response_200_using_identity_server_with_allowed_scope(
[Fact]
public void should_return_response_403_using_identity_server_with_scope_not_allowed()
{
int port = 60571;
int port = RandomPortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -231,9 +233,9 @@ public void should_return_response_403_using_identity_server_with_scope_not_allo
}
};

this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
.And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
.And(x => _steps.GivenIHaveATokenForApiReadOnlyScope("http://localhost:51888"))
.And(x => _steps.GivenIHaveATokenForApiReadOnlyScope(_identityServerRootUrl))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
.And(x => _steps.GivenIHaveAddedATokenToMyRequest())
Expand All @@ -245,7 +247,7 @@ public void should_return_response_403_using_identity_server_with_scope_not_allo
[Fact]
public void should_fix_issue_240()
{
int port = 61071;
int port = RandomPortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -292,9 +294,9 @@ public void should_fix_issue_240()
}
};

this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt, users))
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt, users))
.And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
.And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
.And(x => _steps.GivenIHaveAddedATokenToMyRequest())
Expand Down
23 changes: 14 additions & 9 deletions test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public ButterflyTracingTests(ITestOutputHelper output)
[Fact]
public void should_forward_tracing_information_from_ocelot_and_downstream_services()
{
int port1 = RandomPortFinder.GetRandomPort();
int port2 = RandomPortFinder.GetRandomPort();
var configuration = new FileConfiguration
{
ReRoutes = new List<FileReRoute>
Expand All @@ -48,7 +50,7 @@ public void should_forward_tracing_information_from_ocelot_and_downstream_servic
new FileHostAndPort
{
Host = "localhost",
Port = 51887,
Port = port1,
}
},
UpstreamPathTemplate = "/api001/values",
Expand All @@ -67,7 +69,7 @@ public void should_forward_tracing_information_from_ocelot_and_downstream_servic
new FileHostAndPort
{
Host = "localhost",
Port = 51388,
Port = port2,
}
},
UpstreamPathTemplate = "/api002/values",
Expand All @@ -79,12 +81,13 @@ public void should_forward_tracing_information_from_ocelot_and_downstream_servic
}
}
};

var butterflyUrl = "http://localhost:9618";

var butterflyPort = RandomPortFinder.GetRandomPort();
var butterflyUrl = $"http://localhost:{butterflyPort}";

this.Given(x => GivenFakeButterfly(butterflyUrl))
.And(x => GivenServiceOneIsRunning("http://localhost:51887", "/api/values", 200, "Hello from Laura", butterflyUrl))
.And(x => GivenServiceTwoIsRunning("http://localhost:51388", "/api/values", 200, "Hello from Tom", butterflyUrl))
.And(x => GivenServiceOneIsRunning($"http://localhost:{port1}", "/api/values", 200, "Hello from Laura", butterflyUrl))
.And(x => GivenServiceTwoIsRunning($"http://localhost:{port2}", "/api/values", 200, "Hello from Tom", butterflyUrl))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunningUsingButterfly(butterflyUrl))
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/api001/values"))
Expand All @@ -105,6 +108,7 @@ public void should_forward_tracing_information_from_ocelot_and_downstream_servic
[Fact]
public void should_return_tracing_header()
{
int port = RandomPortFinder.GetRandomPort();
var configuration = new FileConfiguration
{
ReRoutes = new List<FileReRoute>
Expand All @@ -118,7 +122,7 @@ public void should_return_tracing_header()
new FileHostAndPort
{
Host = "localhost",
Port = 51387,
Port = port,
}
},
UpstreamPathTemplate = "/api001/values",
Expand All @@ -136,10 +140,11 @@ public void should_return_tracing_header()
}
};

var butterflyUrl = "http://localhost:9618";
var butterflyPort = RandomPortFinder.GetRandomPort();
var butterflyUrl = $"http://localhost:{butterflyPort}";

this.Given(x => GivenFakeButterfly(butterflyUrl))
.And(x => GivenServiceOneIsRunning("http://localhost:51387", "/api/values", 200, "Hello from Laura", butterflyUrl))
.And(x => GivenServiceOneIsRunning($"http://localhost:{port}", "/api/values", 200, "Hello from Laura", butterflyUrl))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunningUsingButterfly(butterflyUrl))
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/api001/values"))
Expand Down
Loading

0 comments on commit b280b1c

Please sign in to comment.