-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathOpenFeatureActivitySourceTests.cs
More file actions
62 lines (53 loc) · 2.24 KB
/
OpenFeatureActivitySourceTests.cs
File metadata and controls
62 lines (53 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Diagnostics;
using OpenFeature.Constant;
namespace OpenFeature.Tests;
public class OpenFeatureActivitySourceTests
{
[Fact]
public void StartActivity_ReturnsActivityWithCorrectName()
{
using var activityListener = new ActivityListener()
{
ShouldListenTo = source => true,
Sample = (ref _) => ActivitySamplingResult.AllDataAndRecorded
};
ActivitySource.AddActivityListener(activityListener);
var activity = OpenFeatureActivitySource.StartActivity("test_activity");
Assert.NotNull(activity);
Assert.Equal("test_activity", activity.OperationName);
Assert.Equal("OpenFeature", activity.Source.Name);
Assert.NotNull(activity.Source.Version);
Assert.NotEmpty(activity.Source.Version);
Assert.Equal(ActivityKind.Internal, activity.Kind);
}
[Theory]
[InlineData(ErrorType.ProviderNotReady, "provider_not_ready")]
[InlineData(ErrorType.FlagNotFound, "flag_not_found")]
[InlineData(ErrorType.ParseError, "parse_error")]
[InlineData(ErrorType.TypeMismatch, "type_mismatch")]
[InlineData(ErrorType.General, "general")]
[InlineData(ErrorType.InvalidContext, "invalid_context")]
[InlineData(ErrorType.TargetingKeyMissing, "targeting_key_missing")]
[InlineData(ErrorType.ProviderFatal, "provider_fatal")]
[InlineData((ErrorType)999, "_OTHER")]
public void GetFlagEvaluationErrorDescription_ReturnsCorrectDescription(ErrorType errorType, string expectedDescription)
{
var actual = errorType.GetFlagEvaluationErrorDescription();
Assert.Equal(expectedDescription, actual);
}
[Theory]
[InlineData("TARGETING_MATCH", "targeting_match")]
[InlineData("SPLIT", "split")]
[InlineData("DISABLED", "disabled")]
[InlineData("DEFAULT", "default")]
[InlineData("STATIC", "static")]
[InlineData("CACHED", "cached")]
[InlineData("UNKNOWN", "unknown")]
[InlineData("ERROR", "error")]
[InlineData("OTHER", "OTHER")]
public void GetFlagEvaluationReasonDescription(string? reason, string expectedDescription)
{
var actual = OpenFeatureActivitySource.GetFlagEvaluationReasonDescription(reason);
Assert.Equal(expectedDescription, actual);
}
}