-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d294a78
commit 2d3707a
Showing
8 changed files
with
246 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
jobs: | ||
- job: netstandard2_0 | ||
pool: | ||
vmImage: 'vs2017-win2016' | ||
steps: | ||
- task: PowerShell@2 | ||
displayName: 'Build' | ||
inputs: | ||
targetType: inline | ||
workingDirectory: $(System.DefaultWorkingDirectory) | ||
script: | | ||
dotnet --version | ||
dotnet restore | ||
dotnet build src/LaunchDarkly.Client -f netstandard2.0 | ||
- task: PowerShell@2 | ||
displayName: 'Test' | ||
inputs: | ||
targetType: inline | ||
workingDirectory: $(System.DefaultWorkingDirectory) | ||
script: | | ||
dotnet test test/LaunchDarkly.Tests/LaunchDarkly.Tests.csproj -f netcoreapp2.0 | ||
- job: net45 | ||
pool: | ||
vmImage: 'vs2017-win2016' | ||
steps: | ||
- task: PowerShell@2 | ||
displayName: 'Build' | ||
inputs: | ||
targetType: inline | ||
workingDirectory: $(System.DefaultWorkingDirectory) | ||
script: | | ||
dotnet --version | ||
dotnet restore | ||
dotnet build src/LaunchDarkly.Client -f net45 | ||
- task: PowerShell@2 | ||
displayName: 'Test' | ||
inputs: | ||
targetType: inline | ||
workingDirectory: $(System.DefaultWorkingDirectory) | ||
script: | | ||
dotnet test test/LaunchDarkly.Tests/LaunchDarkly.Tests.csproj -f net46 |
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
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
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,142 @@ | ||
using LaunchDarkly.Client; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using WireMock; | ||
using WireMock.Logging; | ||
using WireMock.RequestBuilders; | ||
using WireMock.ResponseBuilders; | ||
using WireMock.Server; | ||
using Xunit; | ||
|
||
namespace LaunchDarkly.Tests | ||
{ | ||
public class FeatureRequestorTest : IDisposable | ||
{ | ||
private const string AllDataJson = @"{""flags"":{""flag1"":{""key"":""flag1"",""version"":1}},""segments"":{""seg1"":{""key"":""seg1"",""version"":2}}}"; | ||
|
||
private FluentMockServer _server; | ||
private IFeatureRequestor _requestor; | ||
|
||
public FeatureRequestorTest() | ||
{ | ||
_server = FluentMockServer.Start(); | ||
var config = Configuration.Default("key").WithUri(_server.Urls[0]).WithHttpClientTimeout(TimeSpan.FromDays(1)); | ||
_requestor = new FeatureRequestor(config); | ||
} | ||
|
||
void IDisposable.Dispose() | ||
{ | ||
_server.Stop(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetAllUsesCorrectUriAndParsesResponseAsync() | ||
{ | ||
_server.Given(Request.Create().UsingGet()) | ||
.RespondWith(Response.Create().WithStatusCode(200).WithBody(AllDataJson)); | ||
var result = await _requestor.GetAllDataAsync(); | ||
|
||
var req = GetLastRequest(); | ||
Assert.Equal("/sdk/latest-all", req.Path); | ||
|
||
Assert.Equal(1, result.Flags.Count); | ||
Assert.Equal(1, result.Flags["flag1"].Version); | ||
Assert.Equal(1, result.Segments.Count); | ||
Assert.Equal(2, result.Segments["seg1"].Version); | ||
} | ||
|
||
[Fact] | ||
public async Task GetAllStoresAndSendsEtag() | ||
{ | ||
var etag = @"""abc123"""; // note that etag strings must be quoted | ||
_server.Given(Request.Create().UsingGet()) | ||
.RespondWith(Response.Create().WithStatusCode(200).WithHeader("Etag", etag).WithBody(AllDataJson)); | ||
await _requestor.GetAllDataAsync(); | ||
await _requestor.GetAllDataAsync(); | ||
|
||
var reqs = new List<LogEntry>(_server.LogEntries); | ||
Assert.Equal(2, reqs.Count); | ||
Assert.False(reqs[0].RequestMessage.Headers.ContainsKey("If-None-Match")); | ||
Assert.Equal(new List<string> { etag }, reqs[1].RequestMessage.Headers["If-None-Match"]); | ||
} | ||
|
||
[Fact] | ||
public async Task GetAllReturnsNullIfNotModified() | ||
{ | ||
var etag = @"""abc123"""; // note that etag strings must be quoted | ||
|
||
_server.Given(Request.Create().UsingGet()) | ||
.RespondWith(Response.Create().WithStatusCode(200).WithHeader("Etag", etag).WithBody(AllDataJson)); | ||
var result1 = await _requestor.GetAllDataAsync(); | ||
|
||
_server.Reset(); | ||
_server.Given(Request.Create().UsingGet().WithHeader("If-None-Match", etag)) | ||
.RespondWith(Response.Create().WithStatusCode(304)); | ||
var result2 = await _requestor.GetAllDataAsync(); | ||
|
||
Assert.NotNull(result1); | ||
Assert.Null(result2); | ||
} | ||
|
||
[Fact] | ||
public async Task GetAllDoesNotRetryFailedRequest() | ||
{ | ||
_server.Given(Request.Create().UsingGet()) | ||
.RespondWith(Response.Create().WithStatusCode(503)); | ||
try | ||
{ | ||
await _requestor.GetAllDataAsync(); | ||
} | ||
catch (UnsuccessfulResponseException e) | ||
{ | ||
Assert.Equal(503, e.StatusCode); | ||
} | ||
|
||
var reqs = new List<LogEntry>(_server.LogEntries); | ||
Assert.Equal(1, reqs.Count); | ||
} | ||
|
||
[Fact] | ||
public async Task GetFlagUsesCorrectUriAndParsesResponseAsync() | ||
{ | ||
var json = @"{""key"":""flag1"",""version"":1}"; | ||
_server.Given(Request.Create().UsingGet()) | ||
.RespondWith(Response.Create().WithStatusCode(200).WithBody(json)); | ||
var flag = await _requestor.GetFlagAsync("flag1"); | ||
|
||
var req = GetLastRequest(); | ||
Assert.Equal("/sdk/latest-flags/flag1", req.Path); | ||
|
||
Assert.NotNull(flag); | ||
Assert.Equal("flag1", flag.Key); | ||
Assert.Equal(1, flag.Version); | ||
} | ||
|
||
[Fact] | ||
public async Task GetSegmentUsesCorrectUriAndParsesResponseAsync() | ||
{ | ||
var json = @"{""key"":""seg1"",""version"":2}"; | ||
_server.Given(Request.Create().UsingGet()) | ||
.RespondWith(Response.Create().WithStatusCode(200).WithBody(json)); | ||
var segment = await _requestor.GetSegmentAsync("seg1"); | ||
|
||
var req = GetLastRequest(); | ||
Assert.Equal("/sdk/latest-segments/seg1", req.Path); | ||
|
||
Assert.NotNull(segment); | ||
Assert.Equal("seg1", segment.Key); | ||
Assert.Equal(2, segment.Version); | ||
} | ||
|
||
private RequestMessage GetLastRequest() | ||
{ | ||
foreach (LogEntry le in _server.LogEntries) | ||
{ | ||
return le.RequestMessage; | ||
} | ||
Assert.True(false, "Did not receive a request"); | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.