Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed May 29, 2024
1 parent 9955ee5 commit bc157ab
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 20 deletions.
3 changes: 2 additions & 1 deletion dart/lib/src/sentry_trace_context_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class SentryTraceContextHeader {
transaction: json['transaction'],
sampleRate: json['sample_rate'],
sampled: json['sampled'],
replayId: json['replay_id'],
replayId:
json['replay_id'] == null ? null : SentryId.fromId(json['replay_id']),
);
}

Expand Down
19 changes: 12 additions & 7 deletions dart/test/scope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ void main() {
expect(sut.fingerprint, fingerprints);
});

test('sets replay ID', () {
final sut = fixture.getSut();

sut.replayId = SentryId.fromId('1');

expect(sut.replayId, SentryId.fromId('1'));
});

test('adds $Breadcrumb', () {
final sut = fixture.getSut();

Expand Down Expand Up @@ -305,6 +313,7 @@ void main() {
sut.level = SentryLevel.debug;
sut.transaction = 'test';
sut.span = null;
sut.replayId = SentryId.newId();

final user = SentryUser(id: 'test');
sut.setUser(user);
Expand All @@ -320,21 +329,15 @@ void main() {
sut.clear();

expect(sut.breadcrumbs.length, 0);

expect(sut.level, null);

expect(sut.transaction, null);
expect(sut.span, null);

expect(sut.user, null);

expect(sut.fingerprint.length, 0);

expect(sut.tags.length, 0);

expect(sut.extra.length, 0);

expect(sut.eventProcessors.length, 0);
expect(sut.replayId, isNull);
});

test('clones', () async {
Expand All @@ -347,6 +350,7 @@ void main() {
sut.addAttachment(SentryAttachment.fromIntList([0, 0, 0, 0], 'test.txt'));
sut.span = NoOpSentrySpan();
sut.level = SentryLevel.warning;
sut.replayId = SentryId.newId();
await sut.setUser(SentryUser(id: 'id'));
await sut.setTag('key', 'vakye');
await sut.setExtra('key', 'vakye');
Expand All @@ -367,6 +371,7 @@ void main() {
true,
);
expect(sut.span, clone.span);
expect(sut.replayId, clone.replayId);
});

test('clone does not additionally call observers', () async {
Expand Down
9 changes: 8 additions & 1 deletion dart/test/sentry_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,8 @@ void main() {
..fingerprint = fingerprint
..addBreadcrumb(crumb)
..setTag(scopeTagKey, scopeTagValue)
..setExtra(scopeExtraKey, scopeExtraValue);
..setExtra(scopeExtraKey, scopeExtraValue)
..replayId = SentryId.fromId('1');

scope.setUser(user);
});
Expand All @@ -835,6 +836,8 @@ void main() {
scopeExtraKey: scopeExtraValue,
eventExtraKey: eventExtraValue,
});
expect(
capturedEnvelope.header.traceContext?.replayId, SentryId.fromId('1'));
});
});

Expand Down Expand Up @@ -1321,13 +1324,15 @@ void main() {
final client = fixture.getSut();

final scope = Scope(fixture.options);
scope.replayId = SentryId.newId();
scope.span =
SentrySpan(fixture.tracer, fixture.tracer.context, MockHub());

await client.captureEvent(fakeEvent, scope: scope);

final envelope = fixture.transport.envelopes.first;
expect(envelope.header.traceContext, isNotNull);
expect(envelope.header.traceContext?.replayId, scope.replayId);
});

test('captureEvent adds attachments from hint', () async {
Expand Down Expand Up @@ -1384,12 +1389,14 @@ void main() {
final context = SentryTraceContextHeader.fromJson(<String, dynamic>{
'trace_id': '${tr.eventId}',
'public_key': '123',
'replay_id': '456',
});

await client.captureTransaction(tr, traceContext: context);

final envelope = fixture.transport.envelopes.first;
expect(envelope.header.traceContext, isNotNull);
expect(envelope.header.traceContext?.replayId, SentryId.fromId('456'));
});

test('captureUserFeedback calls flush', () async {
Expand Down
19 changes: 16 additions & 3 deletions dart/test/sentry_trace_context_header_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ void main() {
'user_segment': 'user_segment',
'transaction': 'transaction',
'sample_rate': '1.0',
'sampled': 'false'
'sampled': 'false',
'replay_id': '456',
};
final context = SentryTraceContextHeader.fromJson(mapJson);

Expand All @@ -28,6 +29,7 @@ void main() {
expect(context.transaction, 'transaction');
expect(context.sampleRate, '1.0');
expect(context.sampled, 'false');
expect(context.replayId, SentryId.fromId('456'));
});

test('toJson', () {
Expand All @@ -39,8 +41,19 @@ void main() {
test('to baggage', () {
final baggage = context.toBaggage();

expect(baggage.toHeaderString(),
'sentry-trace_id=${id.toString()},sentry-public_key=123,sentry-release=release,sentry-environment=environment,sentry-user_id=user_id,sentry-user_segment=user_segment,sentry-transaction=transaction,sentry-sample_rate=1.0,sentry-sampled=false');
expect(
baggage.toHeaderString(),
'sentry-trace_id=${id.toString()},'
'sentry-public_key=123,'
'sentry-release=release,'
'sentry-environment=environment,'
'sentry-user_id=user_id,'
'sentry-user_segment=user_segment,'
'sentry-transaction=transaction,'
'sentry-sample_rate=1.0,'
'sentry-sampled=false,'
'sentry-replay_id=456',
);
});
});
}
21 changes: 13 additions & 8 deletions dart/test/sentry_trace_context_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,31 @@ void main() {
expect(map['description'], 'desc');
expect(map['status'], 'aborted');
expect(map['origin'], 'auto.ui');
expect(map['replay_id'], isNotNull);
});

test('fromJson deserializes', () {
final map = {
'op': 'op',
'span_id': '0000000000000000',
'trace_id': '00000000000000000000000000000000',
'parent_span_id': '0000000000000000',
'span_id': '0000000000000001',
'trace_id': '00000000000000000000000000000002',
'parent_span_id': '0000000000000003',
'description': 'desc',
'status': 'aborted',
'origin': 'auto.ui'
'origin': 'auto.ui',
'replay_id': '00000000000000000000000000000004'
};
final traceContext = SentryTraceContext.fromJson(map);

expect(traceContext.description, 'desc');
expect(traceContext.operation, 'op');
expect(traceContext.spanId.toString(), '0000000000000000');
expect(traceContext.traceId.toString(), '00000000000000000000000000000000');
expect(traceContext.parentSpanId.toString(), '0000000000000000');
expect(traceContext.spanId.toString(), '0000000000000001');
expect(traceContext.traceId.toString(), '00000000000000000000000000000002');
expect(traceContext.parentSpanId.toString(), '0000000000000003');
expect(traceContext.status.toString(), 'aborted');
expect(traceContext.sampled, true);
expect(
traceContext.replayId.toString(), '00000000000000000000000000000004');
});
}

Expand All @@ -48,6 +52,7 @@ class Fixture {
description: 'desc',
sampled: true,
status: SpanStatus.aborted(),
origin: 'auto.ui');
origin: 'auto.ui',
replayId: SentryId.newId());
}
}

0 comments on commit bc157ab

Please sign in to comment.