This repository has been archived by the owner on Oct 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from christriddle/master
Supports multi feature toggles. Removed etcetera dependency.
- Loading branch information
Showing
38 changed files
with
336 additions
and
938 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,3 +178,5 @@ FakesAssemblies/ | |
|
||
!Build/nunit/bin/ | ||
!Build/nunit/bin/* | ||
|
||
*.userprefs |
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,84 @@ | ||
using System; | ||
using System.Net; | ||
using System.Text; | ||
|
||
namespace HobknobClientNet.Tests | ||
{ | ||
internal class EtcdClientForTests : EtcdClient | ||
{ | ||
public EtcdClientForTests(Uri keysUri) : base(keysUri) | ||
{ | ||
} | ||
|
||
public void Set(Uri relativeKeyUri, string value) | ||
{ | ||
byte[] bytes = Encoding.UTF8.GetBytes("value=" + value); | ||
|
||
var webRequest = (HttpWebRequest)WebRequest.Create(GetFullUri(relativeKeyUri)); | ||
webRequest.ContentType = "application/x-www-form-urlencoded"; | ||
webRequest.Method = "PUT"; | ||
webRequest.ContentLength = bytes.Length; | ||
|
||
using (var dataStream = webRequest.GetRequestStream()) | ||
{ | ||
dataStream.Write(bytes, 0, bytes.Length); | ||
dataStream.Flush(); | ||
using (webRequest.GetResponse()) | ||
{ | ||
} | ||
} | ||
} | ||
|
||
public void DeleteDir(Uri relativeKeyUri) | ||
{ | ||
if (!relativeKeyUri.OriginalString.EndsWith("/")) | ||
{ | ||
throw new ArgumentException("Use Delete to delete a key, or end the key with a forward slash.to delete a directory."); | ||
} | ||
var fullKeyUriWithQuery = new UriBuilder(GetFullUri(relativeKeyUri)) { Query = "recursive=true" }; | ||
|
||
var webRequest = (HttpWebRequest)WebRequest.Create(fullKeyUriWithQuery.Uri); | ||
webRequest.Method = "DELETE"; | ||
|
||
try | ||
{ | ||
using (webRequest.GetResponse()) | ||
{ | ||
} | ||
} | ||
catch (WebException ex) | ||
{ | ||
if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound) | ||
{ | ||
return; | ||
} | ||
throw; | ||
} | ||
} | ||
|
||
public void Delete(Uri relativeKeyUri) | ||
{ | ||
if (relativeKeyUri.OriginalString.EndsWith("/")) | ||
{ | ||
throw new ArgumentException("Use DeleteDir to delete a directory, or don't end the key with a forward slash."); | ||
} | ||
|
||
var webRequest = (HttpWebRequest)WebRequest.Create(GetFullUri(relativeKeyUri)); | ||
webRequest.Method = "DELETE"; | ||
try | ||
{ | ||
using (webRequest.GetResponse()) | ||
{ | ||
} | ||
} | ||
catch (WebException ex) | ||
{ | ||
if (((HttpWebResponse) ex.Response).StatusCode == HttpStatusCode.NotFound) | ||
{ | ||
return; | ||
} | ||
throw; | ||
} | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
HobknobClientNet.Tests/Scenarios/GetOrDefault_MultiFeatureToggle.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,50 @@ | ||
using NUnit.Framework; | ||
|
||
namespace HobknobClientNet.Tests.Scenarios | ||
{ | ||
[TestFixture] | ||
internal class GetOrDefault_MultiFeatureToggle : TestBase | ||
{ | ||
bool? _toggleValue; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
Set_application_name("app1"); | ||
_toggleValue = null; | ||
} | ||
|
||
[Test] | ||
public void Default_not_used_when_fature_and_toggle_exists() | ||
{ | ||
Given_a_toggle("app1", "feature1", "toggle1", "true"); | ||
When_I_get_with_default("feature1", "toggle1", false, out _toggleValue); | ||
Assert.That(_toggleValue, Is.True); | ||
} | ||
|
||
[Test] | ||
public void Default_is_used_when_feature_does_not_exist() | ||
{ | ||
Given_a_toggle("app1", "feature1", "toggle1", "true"); | ||
When_I_get_with_default("feature3", "toggle1", true, out _toggleValue); | ||
Assert.That(_toggleValue, Is.True); | ||
} | ||
|
||
[Test] | ||
public void Default_is_used_when_toggle_does_not_exist() | ||
{ | ||
Given_a_toggle("app1", "feature1", "toggle1", "true"); | ||
When_I_get_with_default("feature1", "toggle3", true, out _toggleValue); | ||
Assert.That(_toggleValue, Is.True); | ||
} | ||
|
||
[Test] | ||
public void Applications_do_not_clash() | ||
{ | ||
Given_a_toggle("app1", "feature1", "toggle1", "true"); | ||
Given_a_toggle("app2", "feature1", "toggle1", "false"); | ||
When_I_get_with_default("feature1", "toggle1", false, out _toggleValue); | ||
Assert.That(_toggleValue, Is.True); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.