forked from ThreeMammals/Ocelot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add downstream service name finder (ThreeMammals#1188)
- Loading branch information
Showing
7 changed files
with
73 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Ocelot/DownstreamRouteFinder/Finder/DownstreamServiceFinder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Ocelot.Configuration; | ||
|
||
namespace Ocelot.DownstreamRouteFinder.Finder | ||
{ | ||
public class DownstreamServiceFinder: IDownstreamServiceFinder | ||
{ | ||
public string GetServiceName(string upstreamUrlPath, string upstreamQueryString, string upstreamHttpMethod, string upstreamHost, IInternalConfiguration configuration) | ||
{ | ||
if (upstreamUrlPath.IndexOf('/', 1) == -1) | ||
{ | ||
return upstreamUrlPath | ||
.Substring(1); | ||
} | ||
|
||
return upstreamUrlPath | ||
.Substring(1, upstreamUrlPath.IndexOf('/', 1)) | ||
.TrimEnd('/'); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Ocelot/DownstreamRouteFinder/Finder/IDownstreamServiceFinder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Ocelot.Configuration; | ||
|
||
namespace Ocelot.DownstreamRouteFinder.Finder | ||
{ | ||
public interface IDownstreamServiceFinder | ||
{ | ||
string GetServiceName(string upstreamUrlPath, string upstreamQueryString, string upstreamHttpMethod, string upstreamHost, IInternalConfiguration configuration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamServiceFinderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Ocelot.DownstreamRouteFinder.Finder; | ||
using Xunit; | ||
|
||
namespace Ocelot.UnitTests.DownstreamRouteFinder | ||
{ | ||
public class DownstreamServiceFinderTests | ||
{ | ||
private readonly DownstreamServiceFinder _serviceFinder; | ||
|
||
public DownstreamServiceFinderTests() | ||
{ | ||
_serviceFinder = new DownstreamServiceFinder(); | ||
} | ||
|
||
[Fact] | ||
public void should_return_empty_when_without_path() | ||
{ | ||
var serviceName = _serviceFinder.GetServiceName("/", null, null, null, null); | ||
Assert.Equal("", serviceName); | ||
} | ||
|
||
[Fact] | ||
public void should_return_node_name_when_single_node() | ||
{ | ||
var serviceName = _serviceFinder.GetServiceName("/service-name", null, null, null, null); | ||
Assert.Equal("service-name", serviceName); | ||
} | ||
|
||
[Fact] | ||
public void should_return_first_node_name_when_multiple_nodes() | ||
{ | ||
var serviceName = _serviceFinder.GetServiceName("/service-name/some/longer/path", null, null, null, null); | ||
Assert.Equal("service-name", serviceName); | ||
} | ||
} | ||
} |