-
-
Notifications
You must be signed in to change notification settings - Fork 203
/
SentryOptionsTests.cs
272 lines (222 loc) · 6.52 KB
/
SentryOptionsTests.cs
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
namespace Sentry.Tests;
public class SentryOptionsTests
{
[Fact]
public void DecompressionMethods_ByDefault_AllBitsSet()
{
var sut = new SentryOptions();
Assert.Equal(~DecompressionMethods.None, sut.DecompressionMethods);
}
[Fact]
public void RequestBodyCompressionLevel_ByDefault_Optimal()
{
var sut = new SentryOptions();
Assert.Equal(CompressionLevel.Optimal, sut.RequestBodyCompressionLevel);
}
[Fact]
public void Transport_ByDefault_IsNull()
{
var sut = new SentryOptions();
Assert.Null(sut.Transport);
}
[Fact]
public void AttachStackTrace_ByDefault_True()
{
var sut = new SentryOptions();
Assert.True(sut.AttachStacktrace);
}
[Fact]
public void EnableTracing_Default_Null()
{
var sut = new SentryOptions();
Assert.Null(sut.EnableTracing);
}
[Fact]
public void TracesSampleRate_Default_Null()
{
var sut = new SentryOptions();
Assert.Null(sut.TracesSampleRate);
}
[Fact]
public void TracesSampler_Default_Null()
{
var sut = new SentryOptions();
Assert.Null(sut.TracesSampler);
}
[Fact]
public void IsPerformanceMonitoringEnabled_Default_False()
{
var sut = new SentryOptions();
Assert.False(sut.IsPerformanceMonitoringEnabled);
}
[Fact]
public void IsPerformanceMonitoringEnabled_EnableTracing_True()
{
var sut = new SentryOptions
{
EnableTracing = true
};
Assert.True(sut.IsPerformanceMonitoringEnabled);
}
[Fact]
public void IsPerformanceMonitoringEnabled_EnableTracing_False()
{
var sut = new SentryOptions
{
EnableTracing = false
};
Assert.False(sut.IsPerformanceMonitoringEnabled);
}
[Fact]
public void IsPerformanceMonitoringEnabled_TracesSampleRate_Zero()
{
var sut = new SentryOptions
{
TracesSampleRate = 0.0
};
Assert.False(sut.IsPerformanceMonitoringEnabled);
}
[Fact]
public void IsPerformanceMonitoringEnabled_TracesSampleRate_GreaterThanZero()
{
var sut = new SentryOptions
{
TracesSampleRate = double.Epsilon
};
Assert.True(sut.IsPerformanceMonitoringEnabled);
}
[Fact]
public void IsPerformanceMonitoringEnabled_TracesSampleRate_LessThanZero()
{
var sut = new SentryOptions();
Assert.Throws<ArgumentOutOfRangeException>(() =>
sut.TracesSampleRate = -double.Epsilon);
}
[Fact]
public void IsPerformanceMonitoringEnabled_TracesSampleRate_GreaterThanOne()
{
var sut = new SentryOptions();
Assert.Throws<ArgumentOutOfRangeException>(() =>
sut.TracesSampleRate = 1.0000000000000002);
}
[Fact]
public void IsPerformanceMonitoringEnabled_TracesSampler_Provided()
{
var sut = new SentryOptions
{
TracesSampler = _ => null
};
Assert.True(sut.IsPerformanceMonitoringEnabled);
}
[Fact]
public void IsPerformanceMonitoringEnabled_EnableTracing_True_TracesSampleRate_Zero()
{
// Edge Case:
// Tracing enabled, but sample rate set to zero, and no sampler function, should be treated as disabled.
var sut = new SentryOptions
{
EnableTracing = true,
TracesSampleRate = 0.0
};
Assert.False(sut.IsPerformanceMonitoringEnabled);
}
[Fact]
public void IsPerformanceMonitoringEnabled_EnableTracing_False_TracesSampleRate_One()
{
// Edge Case:
// Tracing disabled should be treated as disabled regardless of sample rate set.
var sut = new SentryOptions
{
EnableTracing = false,
TracesSampleRate = 1.0
};
Assert.False(sut.IsPerformanceMonitoringEnabled);
}
[Fact]
public void IsPerformanceMonitoringEnabled_EnableTracing_False_TracesSampler_Provided()
{
// Edge Case:
// Tracing disabled should be treated as disabled regardless of sampler function set.
var sut = new SentryOptions
{
EnableTracing = false,
TracesSampler = _ => null
};
Assert.False(sut.IsPerformanceMonitoringEnabled);
}
[Fact]
public void CaptureFailedRequests_ByDefault_IsTrue()
{
var sut = new SentryOptions();
Assert.True(sut.CaptureFailedRequests);
}
[Fact]
public void FailedRequestStatusCodes_ByDefault_ShouldIncludeServerErrors()
{
var sut = new SentryOptions();
Assert.Contains((500, 599), sut.FailedRequestStatusCodes);
}
[Fact]
public void FailedRequestTargets_ByDefault_MatchesAnyUrl()
{
var sut = new SentryOptions();
Assert.Contains(".*", sut.FailedRequestTargets);
}
[Fact]
public void IsSentryRequest_WithNullUri_ReturnsFalse()
{
var sut = new SentryOptions();
var actual = sut.IsSentryRequest((Uri)null);
Assert.False(actual);
}
[Fact]
public void IsSentryRequest_WithEmptyUri_ReturnsFalse()
{
var sut = new SentryOptions();
var actual = sut.IsSentryRequest(string.Empty);
Assert.False(actual);
}
[Fact]
public void IsSentryRequest_WithInvalidUri_ReturnsFalse()
{
var sut = new SentryOptions
{
Dsn = "https://foo.com"
};
var actual = sut.IsSentryRequest(new Uri("https://bar.com"));
Assert.False(actual);
}
[Fact]
public void IsSentryRequest_WithValidUri_ReturnsTrue()
{
var sut = new SentryOptions
{
Dsn = "https://123@456.ingest.sentry.io/789"
};
var actual = sut.IsSentryRequest(new Uri("https://456.ingest.sentry.io/api/789/envelope/"));
Assert.True(actual);
}
[Fact]
public void ParseDsn_ReturnsParsedDsn()
{
var sut = new SentryOptions
{
Dsn = "https://123@456.ingest.sentry.io/789"
};
var expected = Dsn.Parse(sut.Dsn);
var actual = sut.ParsedDsn;
Assert.Equal(expected.Source, actual.Source);
}
[Fact]
public void ParseDsn_DsnIsSetAgain_Resets()
{
var sut = new SentryOptions
{
Dsn = "https://123@456.ingest.sentry.io/789"
};
_ = sut.ParsedDsn;
Assert.NotNull(sut._parsedDsn); // Sanity check
sut.Dsn = "some-other-dsn";
Assert.Null(sut._parsedDsn);
}
}