Skip to content
Open
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
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:very_good_analysis/analysis_options.7.0.0.yaml
include: package:very_good_analysis/analysis_options.yaml
25 changes: 13 additions & 12 deletions lib/src/models/package_info.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/src/pub_updater.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const _pubPackagesPath = '/api/packages/';
class PubUpdater {
/// {@macro pub_update}
PubUpdater([http.Client? client, String baseUrl = _defaultBaseUrl])
: _client = client,
_baseUrl = baseUrl;
: _client = client,
_baseUrl = baseUrl;

final http.Client? _client;
final String _baseUrl;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ issue_tracker: https://github.com/VeryGoodOpenSource/pub_updater/issues
topics: [cli, pub, version]

environment:
sdk: ^3.5.0
sdk: ^3.8.1

dependencies:
http: ^1.2.2
Expand All @@ -19,4 +19,4 @@ dev_dependencies:
json_serializable: ^6.8.0
mocktail: ^1.0.4
test: ^1.25.8
very_good_analysis: ^7.0.0
very_good_analysis: ^9.0.0
6 changes: 3 additions & 3 deletions test/fixtures/pre_release_package_info_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import 'dart:convert';

final preReleasePackageInfoResponseBody = json.encode(
final String preReleasePackageInfoResponseBody = json.encode(
preReleasePackageInfoResponse,
);

const preReleasePackageInfoResponse = {
const Map<String, Object> preReleasePackageInfoResponse = {
"name": "mason",
"latest": {
"version": "0.1.0-dev.48",
Expand Down Expand Up @@ -424,6 +424,6 @@ const preReleasePackageInfoResponse = {
"archive_sha256":
"d122e582f4c332b33d95289aafdea475ff5446e9939338b4b6330e2e488ed4e1",
"published": "2023-03-24T04:15:07.809166Z",
}
},
],
};
8 changes: 5 additions & 3 deletions test/fixtures/valid_package_info_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

import 'dart:convert';

final validPackageInfoResponseBody = json.encode(validPackageInfoResponse);
final String validPackageInfoResponseBody = json.encode(
validPackageInfoResponse,
);

const validPackageInfoResponse = {
const Map<String, Object> validPackageInfoResponse = {
"name": "very_good_cli",
"latest": {
"version": "0.4.6",
Expand Down Expand Up @@ -876,6 +878,6 @@ const validPackageInfoResponse = {
"archive_url":
"https://pub.dartlang.org/packages/very_good_cli/versions/0.4.6.tar.gz",
"published": "2021-10-07T21:23:42.789542Z",
}
},
],
};
106 changes: 59 additions & 47 deletions test/pub_update_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const command = [
'activate',
'very_good_cli',
];
const commandWithCustomBaseUrl = [
const List<String> commandWithCustomBaseUrl = [
'dart',
'pub',
'global',
Expand All @@ -44,7 +44,7 @@ const commandWithConstraint = [
'very_good_cli',
'>=0.4.0',
];
const commandWithConstraintAndCustomBaseUrl = [
const List<String> commandWithConstraintAndCustomBaseUrl = [
'dart',
'pub',
'global',
Expand Down Expand Up @@ -80,8 +80,9 @@ void main() {
when(() => response.statusCode).thenReturn(HttpStatus.ok);
when(() => response.body).thenReturn(validPackageInfoResponseBody);

when(() => processManager.run(any()))
.thenAnswer((_) => Future.value(ProcessResult(42, 0, '', '')));
when(
() => processManager.run(any()),
).thenAnswer((_) => Future.value(ProcessResult(42, 0, '', '')));
});

test('can be instantiated without an explicit http client', () {
Expand Down Expand Up @@ -173,11 +174,13 @@ void main() {

when(() => client.get(any())).thenAnswer((_) async => response);
when(() => response.statusCode).thenReturn(HttpStatus.ok);
when(() => response.body)
.thenReturn(preReleasePackageInfoResponseBody);
when(
() => response.body,
).thenReturn(preReleasePackageInfoResponseBody);

when(() => processManager.run(any()))
.thenAnswer((_) => Future.value(ProcessResult(42, 0, '', '')));
when(
() => processManager.run(any()),
).thenAnswer((_) => Future.value(ProcessResult(42, 0, '', '')));
});

test('returns false when currentVersion < latestVersion', () async {
Expand Down Expand Up @@ -212,17 +215,19 @@ void main() {
);
});

test('throws PackageInfoNotFoundFailure when response body is empty',
() async {
when(() => response.body).thenReturn(emptyResponseBody);
await expectLater(
pubUpdater.isUpToDate(
packageName: 'very_good_cli',
currentVersion: '3.0.0',
),
throwsA(isA<PackageInfoNotFoundFailure>()),
);
});
test(
'throws PackageInfoNotFoundFailure when response body is empty',
() async {
when(() => response.body).thenReturn(emptyResponseBody);
await expectLater(
pubUpdater.isUpToDate(
packageName: 'very_good_cli',
currentVersion: '3.0.0',
),
throwsA(isA<PackageInfoNotFoundFailure>()),
);
},
);
});

group('getLatestVersion', () {
Expand Down Expand Up @@ -274,14 +279,16 @@ void main() {
);
});

test('throws PackageInfoNotFoundFailure when response body is empty',
() async {
when(() => response.body).thenReturn(emptyResponseBody);
await expectLater(
pubUpdater.getLatestVersion('very_good_cli'),
throwsA(isA<PackageInfoNotFoundFailure>()),
);
});
test(
'throws PackageInfoNotFoundFailure when response body is empty',
() async {
when(() => response.body).thenReturn(emptyResponseBody);
await expectLater(
pubUpdater.getLatestVersion('very_good_cli'),
throwsA(isA<PackageInfoNotFoundFailure>()),
);
},
);
});

group('update', () {
Expand All @@ -301,27 +308,32 @@ void main() {
verify(() => processManager.run(commandWithCustomBaseUrl)).called(1);
});

test('makes correct call to process.run with version constraint',
() async {
await pubUpdater.update(
packageName: 'very_good_cli',
processManager: processManager,
versionConstraint: '>=0.4.0',
);
verify(() => processManager.run(commandWithConstraint)).called(1);
});
test(
'makes correct call to process.run with version constraint',
() async {
await pubUpdater.update(
packageName: 'very_good_cli',
processManager: processManager,
versionConstraint: '>=0.4.0',
);
verify(() => processManager.run(commandWithConstraint)).called(1);
},
);

test('makes correct call to process.run with version constraint',
() async {
pubUpdater = PubUpdater(client, customBaseUrl);
await pubUpdater.update(
packageName: 'very_good_cli',
processManager: processManager,
versionConstraint: '>=0.4.0',
);
verify(() => processManager.run(commandWithConstraintAndCustomBaseUrl))
.called(1);
});
test(
'makes correct call to process.run with version constraint',
() async {
pubUpdater = PubUpdater(client, customBaseUrl);
await pubUpdater.update(
packageName: 'very_good_cli',
processManager: processManager,
versionConstraint: '>=0.4.0',
);
verify(
() => processManager.run(commandWithConstraintAndCustomBaseUrl),
).called(1);
},
);
});
});
}