Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add clarifying comments, clean up tests #1370

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion lib/src/packagekit/packagekit_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class PackageKitService {
bool get isAvailable => _isAvailable;
bool _isAvailable = false;

// Keep track of active transactions.
// TODO: Implement `GetTransactionList` in packagekit.dart instead.
int _nextId = 0;
final Map<int, PackageKitTransaction> _transactions = {};

Expand Down Expand Up @@ -49,7 +51,9 @@ class PackageKitService {
try {
await _client.connect();
_isAvailable = true;
} on DBusServiceUnknownException catch (_) {}
} on DBusServiceUnknownException catch (_) {
// Service isn't available
}
}

/// Creates a new `PackageKitTransaction` and invokes `action` on it, if
Expand Down
37 changes: 21 additions & 16 deletions test/packagekit_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import 'package:packagekit/packagekit.dart';
import 'packagekit_service_test.mocks.dart';
import 'test_utils.dart';

const _dBusName = 'org.freedesktop.DBus';
const _dBusInterface = 'org.freedesktop.DBus';
const _dBusObjectPath = '/org/freedesktop/DBus';
const _packageKitDBusName = 'org.freedesktop.PackageKit';

void main() {
group('activate service', () {
test('service available', () async {
Expand All @@ -19,21 +24,21 @@ void main() {
expect(packageKit.isAvailable, isFalse);
await packageKit.activateService();
verify(dbus.callMethod(
path: DBusObjectPath('/org/freedesktop/DBus'),
destination: 'org.freedesktop.DBus',
path: DBusObjectPath(_dBusObjectPath),
destination: _dBusName,
name: 'StartServiceByName',
interface: 'org.freedesktop.DBus',
values: const [DBusString('org.freedesktop.PackageKit'), DBusUint32(0)],
interface: _dBusInterface,
values: const [DBusString(_packageKitDBusName), DBusUint32(0)],
)).called(1);
expect(packageKit.isAvailable, isTrue);

await packageKit.activateService();
verifyNever(dbus.callMethod(
path: DBusObjectPath('/org/freedesktop/DBus'),
destination: 'org.freedesktop.DBus',
path: DBusObjectPath(_dBusObjectPath),
destination: _dBusName,
name: 'StartServiceByName',
interface: 'org.freedesktop.DBus',
values: const [DBusString('org.freedesktop.PackageKit'), DBusUint32(0)],
interface: _dBusInterface,
values: const [DBusString(_packageKitDBusName), DBusUint32(0)],
));
});

Expand All @@ -49,11 +54,11 @@ void main() {
expect(packageKit.isAvailable, isFalse);
await packageKit.activateService();
verify(dbus.callMethod(
path: DBusObjectPath('/org/freedesktop/DBus'),
destination: 'org.freedesktop.DBus',
path: DBusObjectPath(_dBusObjectPath),
destination: _dBusName,
name: 'StartServiceByName',
interface: 'org.freedesktop.DBus',
values: const [DBusString('org.freedesktop.PackageKit'), DBusUint32(0)],
interface: _dBusInterface,
values: const [DBusString(_packageKitDBusName), DBusUint32(0)],
)).called(1);
expect(packageKit.isAvailable, isFalse);
});
Expand Down Expand Up @@ -122,11 +127,11 @@ void main() {
MockDBusClient createMockDbusClient() {
final dbus = MockDBusClient();
when(dbus.callMethod(
path: DBusObjectPath('/org/freedesktop/DBus'),
destination: 'org.freedesktop.DBus',
path: DBusObjectPath(_dBusObjectPath),
destination: _dBusName,
name: 'StartServiceByName',
interface: 'org.freedesktop.DBus',
values: const [DBusString('org.freedesktop.PackageKit'), DBusUint32(0)],
interface: _dBusInterface,
values: const [DBusString(_packageKitDBusName), DBusUint32(0)],
)).thenAnswer((_) async => DBusMethodSuccessResponse());
return dbus;
}