Skip to content

Commit

Permalink
Fix code style issues
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Poignant <[email protected]>
  • Loading branch information
thomaspoignant committed Nov 28, 2022
1 parent dbfc801 commit 68f86ce
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
namespace OpenFeature.Contrib.Providers.GOFeatureFlag
{
/// <summary>
/// GOFeatureFlagRequest is the object formatting the request to the relay proxy.
/// </summary>
/// <typeparam name="T">Type of the default value.</typeparam>
public class GOFeatureFlagRequest<T>
{
/// <summary>
/// GoFeatureFlagUser is the representation of the user.
/// </summary>
public GoFeatureFlagUser User { get; set; }

/// <summary>
/// default value if we have an error.
/// </summary>
public T DefaultValue { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public class GoFeatureFlagProviderOptions
/// (optional) If you want to provide your own HttpMessageHandler.
/// Default: null
/// </Summary>
public HttpMessageHandler HttpMessageHandler { get; set; } = null;
public HttpMessageHandler HttpMessageHandler { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,39 @@ namespace OpenFeature.Contrib.Providers.GOFeatureFlag
/// </summary>
public class GoFeatureFlagResponse
{
/// <summary>
/// trackEvent is true when this call was tracked in GO Feature Flag.
/// </summary>
public bool trackEvents { get; set; }

/// <summary>
/// variationType contains the name of the variation used for this flag.
/// </summary>
public string variationType { get; set; }

/// <summary>
/// failed is true if GO Feature Flag had an issue.
/// </summary>
public bool failed { get; set; }

/// <summary>
/// version of the flag used (optional)
/// </summary>
public string version { get; set; }

/// <summary>
/// reason used to choose this variation.
/// </summary>
public string reason { get; set; }

/// <summary>
/// errorCode is empty if everything went ok.
/// </summary>
public string errorCode { get; set; }

/// <summary>
/// value contains the result of the flag.
/// </summary>
public object value { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace OpenFeature.Contrib.Providers.GOFeatureFlag.exception
{
/// <summary>
/// Exception thrown when a flag is disabled
/// </summary>
public class FlagDisabled : GoFeatureFlagException
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@

namespace OpenFeature.Contrib.Providers.GOFeatureFlag.exception
{
/// <summary>
/// Exception thrown when the flag is not found by GO Feature Flag relay proxy.
/// </summary>
public class FlagNotFoundError : FeatureProviderException
{
/// <summary>
/// Constructor of the exception
/// </summary>
/// <param name="message">Message to display</param>
/// <param name="innerException">Original exception</param>
public FlagNotFoundError(string message, Exception innerException = null) : base(ErrorType.FlagNotFound,
message, innerException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@

namespace OpenFeature.Contrib.Providers.GOFeatureFlag.exception
{
/// <summary>
/// Exception throw when we don't have a specific case.
/// </summary>
public class GeneralError : FeatureProviderException
{
/// <summary>
/// Constructor of the exception
/// </summary>
/// <param name="message">Message to display</param>
/// <param name="innerException">Original exception</param>
public GeneralError(string message, Exception innerException = null) : base(ErrorType.General, message,
innerException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@

namespace OpenFeature.Contrib.Providers.GOFeatureFlag.exception
{
/// <summary>
/// GoFeatureFlagException is the root exception of GO Feature Flag provider.
/// </summary>
public abstract class GoFeatureFlagException : Exception
{
/// <summary>
/// Constructor
/// </summary>
public GoFeatureFlagException()
{
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="message">Message of your exception</param>
public GoFeatureFlagException(string message)
: base(message)
{
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="message">Message of your exception</param>
/// <param name="inner">Root exception.</param>
public GoFeatureFlagException(string message, Exception inner)
: base(message, inner)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@

namespace OpenFeature.Contrib.Providers.GOFeatureFlag.exception
{
/// <summary>
/// Exception throw when the Evaluation Context is invalid.
/// </summary>
public class InvalidEvaluationContext : FeatureProviderException
{
/// <summary>
/// Constructor of the exception
/// </summary>
/// <param name="message">Message to display</param>
/// <param name="innerException">Original exception</param>
public InvalidEvaluationContext(string message, Exception innerException = null) : base(
ErrorType.InvalidContext, message, innerException)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
namespace OpenFeature.Contrib.Providers.GOFeatureFlag.exception
{
/// <summary>
/// Exception throw when the options of the provider are invalid.
/// </summary>
public class InvalidOption : GoFeatureFlagException
{
/// <summary>
/// Constructor of the exception
/// </summary>
/// <param name="message">Message to display</param>
public InvalidOption(string message) : base(message)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@

namespace OpenFeature.Contrib.Providers.GOFeatureFlag.exception
{
/// <summary>
/// Exception throw when The Evaluation Context does not contains a targetingKey field.
/// </summary>
public class InvalidTargetingKey : FeatureProviderException
{
/// <summary>
/// Constructor of the exception
/// </summary>
/// <param name="message">Message to display</param>
/// <param name="innerException">Original exception</param>
public InvalidTargetingKey(string message, Exception innerException = null) : base(ErrorType.InvalidContext,
message, innerException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@

namespace OpenFeature.Contrib.Providers.GOFeatureFlag.exception
{
/// <summary>
/// Exception throw when the type we received from GO Feature Flag is different than the one expected.
/// </summary>
public class TypeMismatchError : FeatureProviderException
{
/// <summary>
/// Constructor of the exception
/// </summary>
/// <param name="message">Message to display</param>
/// <param name="innerException">Original exception</param>
public TypeMismatchError(string message, Exception innerException = null) : base(ErrorType.TypeMismatch,
message, innerException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ private void constructor_options_empty_endpoint()
[Fact]
private void constructor_options_only_timeout()
{
Assert.Throws<InvalidOption>(() => new GoFeatureFlagProvider(new GoFeatureFlagProviderOptions
{ Timeout = new TimeSpan(1000 * TimeSpan.TicksPerMillisecond) }));
Assert.Throws<InvalidOption>(
() => new GoFeatureFlagProvider(
new GoFeatureFlagProviderOptions { Timeout = new TimeSpan(1000 * TimeSpan.TicksPerMillisecond) }
)
);
}

[Fact]
Expand Down Expand Up @@ -362,7 +365,10 @@ private void should_resolve_a_valid_value_flag_with_TARGETING_MATCH_reason()
var res = g.ResolveStructureValue("object_key", null, _defaultEvaluationCtx);
Assert.NotNull(res.Result);
var want = JsonConvert.SerializeObject(new Value(new Structure(new Dictionary<string, Value>
{ { "test", new Value("test1") }, { "test2", new Value(false) }, { "test3", new Value(123.3) }, {"test4", new Value(1)}})));
{
{ "test", new Value("test1") }, { "test2", new Value(false) }, { "test3", new Value(123.3) },
{ "test4", new Value(1) }
})));
Assert.Equal(want, JsonConvert.SerializeObject(res.Result.Value));
Assert.Equal(ErrorType.None, res.Result.ErrorType);
Assert.Equal(Reason.TargetingMatch, res.Result.Reason);
Expand Down Expand Up @@ -427,7 +433,8 @@ private void should_resolve_a_valid_value_flag_with_a_list()

var res = g.ResolveStructureValue("list_key", null, _defaultEvaluationCtx);
Assert.NotNull(res.Result);
var want = JsonConvert.SerializeObject(new Value(new List<Value> { new("test"), new("test1"), new("test2"), new("false"), new("test3") }));
var want = JsonConvert.SerializeObject(new Value(new List<Value>
{ new("test"), new("test1"), new("test2"), new("false"), new("test3") }));
Assert.Equal(want, JsonConvert.SerializeObject(res.Result.Value));
Assert.Equal(ErrorType.None, res.Result.ErrorType);
Assert.Equal(Reason.TargetingMatch, res.Result.Reason);
Expand Down

0 comments on commit 68f86ce

Please sign in to comment.