Skip to content

Commit

Permalink
Add support for sqflite (#1306)
Browse files Browse the repository at this point in the history
Co-authored-by: Manoel Aranda Neto <[email protected]>
  • Loading branch information
marandaneto and Manoel Aranda Neto authored Mar 20, 2023
1 parent 934b4d9 commit 40680d3
Show file tree
Hide file tree
Showing 58 changed files with 4,363 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ targets:
logging:
dio:
file:
sqflite:
- name: github
- name: registry
sdks:
Expand All @@ -18,3 +19,4 @@ targets:
pub:sentry_logging:
pub:sentry_dio:
pub:sentry_file:
pub:sentry_sqflite:
2 changes: 2 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
paths-ignore:
- 'logging/**'
- 'dio/**'
- 'file/**'
- 'sqflite/**'

jobs:
cancel-previous-workflow:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/dio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
paths-ignore:
- 'logging/**'
- 'flutter/**'
- 'file/**'
- 'sqflite/**'

jobs:
cancel-previous-workflow:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/e2e_dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- 'logging/**'
- 'dio/**'
- 'flutter/**'
- 'file/**'
- 'sqflite/**'

env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- 'logging/**'
- 'flutter/**'
- 'dio/**'
- 'sqflite/**'

jobs:
cancel-previous-workflow:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
paths-ignore:
- 'logging/**'
- 'dio/**'
- 'file/**'
- 'sqflite/**'

jobs:
cancel-previous-workflow:
Expand Down Expand Up @@ -62,9 +64,10 @@ jobs:
- uses: actions/checkout@v3

- uses: actions/setup-java@v3
if: ${{ matrix.target == 'android' }}
with:
java-version: '11'
distribution: 'adopt'
java-version: '8'

# Install required dependencies for Flutter on Linux on Ubuntu
- name: 'Setup Linux'
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/flutter_integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ on:
push:
branches:
- main
- release/**
pull_request:
paths-ignore:
- 'file/**'

jobs:
cancel-previous-workflow:
Expand All @@ -29,7 +32,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '8'
java-version: '11'

- uses: subosito/flutter-action@1e6ee87cb840500837bcd50a667fb28815d8e310 # pin@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/logging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
paths-ignore:
- 'dio/**'
- 'flutter/**'
- 'file/**'
- 'sqflite/**'

jobs:
cancel-previous-workflow:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/min_version_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
- main
- release/**
pull_request:
paths-ignore:
- 'file/**'
- 'sqflite/**'

jobs:
cancel-previous-workflow:
Expand Down
114 changes: 114 additions & 0 deletions .github/workflows/sqflite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: sentry-sqflite
on:
push:
branches:
- main
- release/**
pull_request:
paths-ignore:
- 'logging/**'
- 'flutter/**'
- 'dio/**'
- 'file/**'

jobs:
cancel-previous-workflow:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # [email protected]
with:
access_token: ${{ github.token }}

build:
name: ${{ matrix.target }} | ${{ matrix.os }} | ${{ matrix.sdk }}
runs-on: ${{ matrix.os }}
timeout-minutes: 30
defaults:
run:
shell: bash
strategy:
fail-fast: false
# max-parallel: 4
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
target: ['ios', 'android', 'macos', 'linux', 'windows']
sdk: ['stable', 'beta']
exclude:
- os: ubuntu-latest
target: ios
- os: ubuntu-latest
target: macos
- os: ubuntu-latest
target: windows
- os: windows-latest
target: ios
- os: windows-latest
target: macos
- os: windows-latest
target: linux
# macos-latest is taking hours due to limited resources
- os: macos-latest
target: android
- os: macos-latest
target: web
- os: macos-latest
target: linux
- os: macos-latest
target: windows
# Bad CPU type in executable
- os: macos-latest
sdk: beta

steps:
- uses: actions/checkout@v3

- uses: actions/setup-java@v3
if: ${{ matrix.target == 'android' }}
with:
java-version: '11'
distribution: 'adopt'

# Install required dependencies for Flutter on Linux on Ubuntu
- name: 'Setup Linux'
run: |
sudo apt update
sudo apt install -y cmake dbus libblkid-dev libgtk-3-dev liblzma-dev ninja-build pkg-config xvfb
sudo apt install -y network-manager upower
if: matrix.os == 'ubuntu-latest'

- uses: subosito/flutter-action@dbf1fa04f4d2e52c33185153d06cdb5443aa189d # pin@v2
with:
channel: ${{ matrix.sdk }}

- run: flutter upgrade

- name: Pub Get
run: |
cd sqflite
flutter pub get
- name: Test VM with coverage
if: runner.os != 'macOS'
run: |
cd sqflite
flutter test --coverage --test-randomize-ordering-seed=random
- uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # pin@v3
if: runner.os == 'Linux' && matrix.sdk == 'stable' && matrix.target == 'linux'
with:
name: sentry_sqflite
file: ./sqflite/coverage/lcov.info
functionalities: 'search' # remove after https://github.com/codecov/codecov-action/issues/600

- uses: VeryGoodOpenSource/very_good_coverage@84e5b54ab888644554e5573dca87d7f76dec9fb3 # [email protected]
if: runner.os == 'Linux' && matrix.sdk == 'stable' && matrix.target == 'linux'
with:
path: './sqflite/coverage/lcov.info'
min_coverage: 80

analyze:
uses: ./.github/workflows/analyze.yml
with:
package: sqflite
sdk: flutter
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ dart/coverage/*
logging/coverage/*
dio/coverage/*
file/coverage/*
flutter/coverage/*
sqflite/coverage/*

pubspec.lock
Podfile.lock
flutter/coverage/*

.gradle
flutter/.gradle
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- sqflite Support for Flutter ([#1306](https://github.com/getsentry/sentry-dart/pull/1306))

### Fixes

- LoadImageListIntegration won't throw bad state if there is no exceptions in the event ([#1347](https://github.com/getsentry/sentry-dart/pull/1347))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Sentry SDK for Dart and Flutter
| sentry_logging | [![build](https://github.com/getsentry/sentry-dart/workflows/sentry-logging/badge.svg?branch=main)](https://github.com/getsentry/sentry-dart/actions?query=workflow%3Alogging) | [![pub package](https://img.shields.io/pub/v/sentry_logging.svg)](https://pub.dev/packages/sentry_logging) | [![likes](https://img.shields.io/pub/likes/sentry_logging?logo=dart)](https://pub.dev/packages/sentry_logging/score) | [![popularity](https://img.shields.io/pub/popularity/sentry_logging?logo=dart)](https://pub.dev/packages/sentry_logging/score) | [![pub points](https://img.shields.io/pub/points/sentry_logging?logo=dart)](https://pub.dev/packages/sentry_logging/score)
| sentry_dio | [![build](https://github.com/getsentry/sentry-dart/workflows/sentry-dio/badge.svg?branch=main)](https://github.com/getsentry/sentry-dart/actions?query=workflow%3Asentry-dio) | [![pub package](https://img.shields.io/pub/v/sentry_dio.svg)](https://pub.dev/packages/sentry_dio) | [![likes](https://img.shields.io/pub/likes/sentry_dio?logo=dart)](https://pub.dev/packages/sentry_dio/score) | [![popularity](https://img.shields.io/pub/popularity/sentry_dio?logo=dart)](https://pub.dev/packages/sentry_dio/score) | [![pub points](https://img.shields.io/pub/points/sentry_dio?logo=dart)](https://pub.dev/packages/sentry_dio/score)
| sentry_file | [![build](https://github.com/getsentry/sentry-dart/workflows/sentry-file/badge.svg?branch=main)](https://github.com/getsentry/sentry-dart/actions?query=workflow%3Asentry-file) | [![pub package](https://img.shields.io/pub/v/sentry_file.svg)](https://pub.dev/packages/sentry_file) | [![likes](https://img.shields.io/pub/likes/sentry_file?logo=dart)](https://pub.dev/packages/sentry_file/score) | [![popularity](https://img.shields.io/pub/popularity/sentry_file?logo=dart)](https://pub.dev/packages/sentry_file/score) | [![pub points](https://img.shields.io/pub/points/sentry_file?logo=dart)](https://pub.dev/packages/sentry_file/score)
| sentry_sqflite | [![build](https://github.com/getsentry/sentry-dart/workflows/sentry-sqflite/badge.svg?branch=main)](https://github.com/getsentry/sentry-dart/actions?query=workflow%3Asentry-sqflite) | [![pub package](https://img.shields.io/pub/v/sentry_sqflite.svg)](https://pub.dev/packages/sentry_sqflite) | [![likes](https://img.shields.io/pub/likes/sentry_sqflite)](https://pub.dev/packages/sentry_sqflite/score) | [![popularity](https://img.shields.io/pub/popularity/sentry_sqflite)](https://pub.dev/packages/sentry_sqflite/score) | [![pub points](https://img.shields.io/pub/points/sentry_sqflite)](https://pub.dev/packages/sentry_sqflite/score)

##### Usage

Expand Down
6 changes: 6 additions & 0 deletions dart/lib/src/protocol/sdk_version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ class SdkVersion {

/// Adds a package
void addPackage(String name, String version) {
for (final item in _packages) {
if (item.name == name && item.version == version) {
return;
}
}

final package = SentryPackage(name, version);
_packages.add(package);
}
Expand Down
81 changes: 53 additions & 28 deletions dart/test/protocol/sdk_version_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,46 @@ import 'package:sentry/sentry.dart';
import 'package:test/test.dart';

void main() {
final sdkVersion = SdkVersion(
name: 'name',
version: 'version',
integrations: ['test'],
packages: [SentryPackage('name', 'version')],
);

final sdkVersionJson = <String, dynamic>{
'name': 'name',
'version': 'version',
'integrations': ['test'],
'packages': [
{
'name': 'name',
'version': 'version',
}
],
};

group('json', () {
final fixture = Fixture();

test('toJson', () {
final json = sdkVersion.toJson();
final json = fixture.getSut().toJson();

expect(
DeepCollectionEquality().equals(sdkVersionJson, json),
DeepCollectionEquality().equals(fixture.sdkVersionJson, json),
true,
);
});
test('fromJson', () {
final sdkVersion = SdkVersion.fromJson(sdkVersionJson);
final sdkVersion = SdkVersion.fromJson(fixture.sdkVersionJson);
final json = sdkVersion.toJson();

expect(
DeepCollectionEquality().equals(sdkVersionJson, json),
DeepCollectionEquality().equals(fixture.sdkVersionJson, json),
true,
);
});
});

group('copyWith', () {
final fixture = Fixture();

test('copyWith keeps unchanged', () {
final data = sdkVersion;
final sut = fixture.getSut();

final copy = data.copyWith();
final copy = sut.copyWith();

expect(data.toJson(), copy.toJson());
expect(sut.toJson(), copy.toJson());
});

test('copyWith takes new values', () {
final data = sdkVersion;
final sut = fixture.getSut();

final packages = [SentryPackage('name1', 'version1')];
final integrations = ['test1'];

final copy = data.copyWith(
final copy = sut.copyWith(
name: 'name1',
version: 'version1',
integrations: integrations,
Expand All @@ -76,4 +61,44 @@ void main() {
expect('version1', copy.version);
});
});

group('addPackage', () {
final fixture = Fixture();

test('add package if not same name and version', () {
final sut = fixture.getSut();
sut.addPackage('name1', 'version1');

final last = sut.packages.last;
expect('name1', last.name);
expect('version1', last.version);
});
test('does not add package if the same name and version', () {
final sut = fixture.getSut();
sut.addPackage('name', 'version');

expect(1, sut.packages.length);
});
});
}

class Fixture {
final sdkVersionJson = <String, dynamic>{
'name': 'name',
'version': 'version',
'integrations': ['test'],
'packages': [
{
'name': 'name',
'version': 'version',
}
],
};

SdkVersion getSut() => SdkVersion(
name: 'name',
version: 'version',
integrations: ['test'],
packages: [SentryPackage('name', 'version')],
);
}
2 changes: 1 addition & 1 deletion dart/test/scope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ void main() {
updatedEvent?.contexts[SentryOperatingSystem.type].name, 'event-os');
});

test('should apply the scope.contexts values ', () async {
test('should apply the scope.contexts values', () async {
final event = SentryEvent();
final scope = Scope(SentryOptions(dsn: fakeDsn));
await scope.setContexts(
Expand Down
Loading

0 comments on commit 40680d3

Please sign in to comment.