-
Notifications
You must be signed in to change notification settings - Fork 119
Add missing feature switch #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,6 +141,10 @@ private async Task<bool> IsEnabledAsync<TContext>(string feature, TContext appCo | |
| } | ||
| } | ||
| } | ||
| else if (!_options.IgnoreMissingFeatures) | ||
| { | ||
| throw new FeatureManagementException(FeatureManagementError.MissingFeature, $"The feature declaration for specified feature '{feature}' was not found."); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should log a warning even if else
{
string errorMessage = $"The feature declaration for specified feature '{feature}' was not found.";
if (!_options.IgnoreMissingFeatures)
{
throw new FeatureManagementException(FeatureManagementError.MissingFeature, errorMessage);
}
else
{
_logger.LogWarning(errorMessage);
}
} |
||
|
|
||
| foreach (ISessionManager sessionManager in _sessionManagers) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| using System.Linq; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Reflection; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I may miss it as it's not very easy to tell. What we are using in the reflection namespace? |
||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
|
|
@@ -25,6 +26,7 @@ public class FeatureManagement | |
| private const string OffFeature = "OffFeature"; | ||
| private const string ConditionalFeature = "ConditionalFeature"; | ||
| private const string ContextualFeature = "ContextualFeature"; | ||
| private const string MissingFeature = "MissingFeature"; | ||
|
|
||
| [Fact] | ||
| public async Task ReadsConfiguration() | ||
|
|
@@ -33,6 +35,12 @@ public async Task ReadsConfiguration() | |
|
|
||
| var services = new ServiceCollection(); | ||
|
|
||
| services | ||
| .Configure<FeatureManagementOptions>(options => | ||
| { | ||
| options.IgnoreMissingFeatures = true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this change needed? |
||
| }); | ||
|
|
||
| services | ||
| .AddSingleton(config) | ||
| .AddFeatureManagement() | ||
|
|
@@ -483,5 +491,59 @@ public async Task SwallowsExceptionForMissingFeatureFilter() | |
|
|
||
| Assert.False(isEnabled); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ThrowsOnMissingFeature() | ||
| { | ||
| IConfiguration config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); | ||
|
|
||
| var services = new ServiceCollection(); | ||
|
|
||
| services | ||
| .Configure<FeatureManagementOptions>(options => | ||
| { | ||
| options.IgnoreMissingFeatures = false; | ||
| }); | ||
|
|
||
| services | ||
| .AddSingleton(config) | ||
| .AddFeatureManagement() | ||
| .AddFeatureFilter<TestFilter>(); | ||
|
|
||
| ServiceProvider serviceProvider = services.BuildServiceProvider(); | ||
|
|
||
| IFeatureManager featureManager = serviceProvider.GetRequiredService<IFeatureManager>(); | ||
|
|
||
| FeatureManagementException e = await Assert.ThrowsAsync<FeatureManagementException>(async () => await featureManager.IsEnabledAsync(MissingFeature)); | ||
|
|
||
| Assert.Equal(FeatureManagementError.MissingFeature, e.Error); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SwallowsOnMissingFeature() | ||
| { | ||
| IConfiguration config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); | ||
|
|
||
| var services = new ServiceCollection(); | ||
|
|
||
| services | ||
| .Configure<FeatureManagementOptions>(options => | ||
| { | ||
| options.IgnoreMissingFeatures = true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove this so we can test the default behavior and ensure no regressions. |
||
| }); | ||
|
|
||
| services | ||
| .AddSingleton(config) | ||
| .AddFeatureManagement() | ||
| .AddFeatureFilter<TestFilter>(); | ||
|
|
||
| ServiceProvider serviceProvider = services.BuildServiceProvider(); | ||
|
|
||
| IFeatureManager featureManager = serviceProvider.GetRequiredService<IFeatureManager>(); | ||
|
|
||
| var isEnabled = await featureManager.IsEnabledAsync(ConditionalFeature); | ||
|
|
||
| Assert.False(isEnabled); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want this defaults to
true.