Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add missing tests
  • Loading branch information
marandaneto committed Dec 5, 2022
commit 05ea2c9bbbe7786ac2dd8b713746dd622ed6281b
4 changes: 2 additions & 2 deletions file/lib/src/sentry_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class SentryFile implements File {
T data;
try {
// workaround for having the length when the file does not exist
// exists or its being deleted.
// or its being deleted.
int? length;
var hasLength = false;
try {
Expand Down Expand Up @@ -254,7 +254,7 @@ class SentryFile implements File {
T data;
try {
// workaround for having the length when the file does not exist
// exists or its being deleted.
// or its being deleted.
int? length;
var hasLength = false;
try {
Expand Down
Empty file removed file/new.txt
Empty file.
123 changes: 123 additions & 0 deletions file/test/sentry_file_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,129 @@ void main() {
_assertSpan('testfile.txt', false, size: 7);
});
});

group('$SentryFile rename', () {
late Fixture fixture;

setUp(() {
fixture = Fixture();
});

void _assertSpan(bool async, String name) {
final call = fixture.client.captureTransactionCalls.first;
final span = call.transaction.spans.first;

expect(span.context.operation, 'file.rename');
expect(span.data['file.size'], 0);
expect(span.data['file.async'], async);
expect(span.context.description, name);
expect(
(span.data['file.path'] as String).endsWith('test_resources/$name'),
true);
}

test('async', () async {
final file = File('test_resources/old_name.txt');
await file.create();

final sut = fixture.getSut(
file,
sendDefaultPii: true,
tracesSampleRate: 1.0,
);

final tr = fixture.hub.startTransaction('name', 'op', bindToScope: true);

final newFile = await sut.rename('test_resources/new_name.txt');

await tr.finish();

expect(await file.exists(), false);
expect(await newFile.exists(), true);

expect(sut.uri.toFilePath(), isNot(newFile.uri.toFilePath()));

_assertSpan(true, 'old_name.txt');

await newFile.delete();
});

test('sync', () async {
final file = File('test_resources/old_name.txt');
file.createSync();

final sut = fixture.getSut(
file,
sendDefaultPii: true,
tracesSampleRate: 1.0,
);

final tr = fixture.hub.startTransaction('name', 'op', bindToScope: true);

final newFile = sut.renameSync('test_resources/testfile_copy.txt');

await tr.finish();

expect(file.existsSync(), false);
expect(newFile.existsSync(), true);

expect(sut.uri.toFilePath(), isNot(newFile.uri.toFilePath()));

_assertSpan(false, 'old_name.txt');

newFile.deleteSync();
});
});

group('$SentryOptions sendDefaultPii', () {
late Fixture fixture;

setUp(() {
fixture = Fixture();
});

void _assertSpan(bool async) {
final call = fixture.client.captureTransactionCalls.first;
final span = call.transaction.spans.first;

expect(span.data['file.async'], async);
expect(span.data['file.path'], null);
}

test('does not add file path async', () async {
final file = File('test_resources/testfile.txt');

final sut = fixture.getSut(
file,
tracesSampleRate: 1.0,
);

final tr = fixture.hub.startTransaction('name', 'op', bindToScope: true);

await sut.readAsBytes();

await tr.finish();

_assertSpan(true);
});

test('sync', () async {
final file = File('test_resources/testfile.txt');

final sut = fixture.getSut(
file,
tracesSampleRate: 1.0,
);

final tr = fixture.hub.startTransaction('name', 'op', bindToScope: true);

sut.readAsBytesSync();

await tr.finish();

_assertSpan(false);
});
});
}

class Fixture {
Expand Down
2 changes: 1 addition & 1 deletion scripts/bump-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NEW_VERSION="${2}"
echo "Current version: ${OLD_VERSION}"
echo "Bumping version: ${NEW_VERSION}"

for pkg in {dart,flutter,logging,dio}; do
for pkg in {dart,flutter,logging,dio,file}; do
# Bump version in pubspec.yaml
perl -pi -e "s/^version: .*/version: $NEW_VERSION/" $pkg/pubspec.yaml
# Bump sentry dependency version in pubspec.yaml
Expand Down