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

fix(hosted-url): activation of package on self-hosted url #46

Merged
merged 6 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/src/pub_updater.dart
Expand Up @@ -13,7 +13,10 @@ class PackageInfoRequestFailure implements Exception {}
class PackageInfoNotFoundFailure implements Exception {}

/// The pub.dev base url for querying package versions
const _defaultBaseUrl = 'https://pub.dev/api/packages/';
const _defaultBaseUrl = 'https://pub.dev';

/// The pub.dev api query path for querying packages
const _pubPackagesPath = '/api/packages/';

/// {@template pub_update}
/// A Dart package which enables checking whether a package is up to date.
Expand Down Expand Up @@ -69,12 +72,13 @@ class PubUpdater {
'activate',
packageName,
if (versionConstraint != null) versionConstraint,
if (_baseUrl != _defaultBaseUrl) ...['-u', _baseUrl]
zoocityboy marked this conversation as resolved.
Show resolved Hide resolved
],
);
}

Future<PackageInfo> _getPackageInfo(String packageName) async {
final uri = Uri.parse('$_baseUrl$packageName');
final uri = Uri.parse('$_baseUrl$_pubPackagesPath$packageName');
final response = await _get(uri);

if (response.statusCode != HttpStatus.ok) throw PackageInfoRequestFailure();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Expand Up @@ -4,7 +4,7 @@ version: 0.3.0
homepage: https://github.com/VeryGoodOpenSource/pub_updater

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.12.0 <4.0.0"

dependencies:
http: ^0.13.3
Expand Down
45 changes: 42 additions & 3 deletions test/pub_update_test.dart
Expand Up @@ -26,6 +26,15 @@ const command = [
'activate',
'very_good_cli',
];
const commandWithCustomBaseUrl = [
'dart',
'pub',
'global',
'activate',
'very_good_cli',
'-u',
customBaseUrl,
];
const commandWithConstraint = [
'dart',
'pub',
Expand All @@ -34,8 +43,18 @@ const commandWithConstraint = [
'very_good_cli',
'>=0.4.0',
];
const commandWithConstraintAndCustomBaseUrl = [
'dart',
'pub',
'global',
'activate',
'very_good_cli',
'>=0.4.0',
'-u',
customBaseUrl,
];

const customBaseUrl = 'https://custom-domain.com/api/packages/';
const customBaseUrl = 'https://custom-domain.com';

void main() {
group('PubUpdater', () {
Expand Down Expand Up @@ -104,7 +123,7 @@ void main() {

verify(
() => client.get(
Uri.parse('${customBaseUrl}very_good_cli'),
Uri.parse('$customBaseUrl/api/packages/very_good_cli'),
),
).called(1);
});
Expand Down Expand Up @@ -231,7 +250,7 @@ void main() {

verify(
() => client.get(
Uri.parse('${customBaseUrl}very_good_cli'),
Uri.parse('$customBaseUrl/api/packages/very_good_cli'),
),
).called(1);
});
Expand Down Expand Up @@ -270,6 +289,14 @@ void main() {
);
verify(() => processManager.run(command)).called(1);
});
test('makes correct call to process.run with customBaseUrl', () async {
pubUpdater = PubUpdater(client, customBaseUrl);
await pubUpdater.update(
packageName: 'very_good_cli',
processManager: processManager,
);
verify(() => processManager.run(commandWithCustomBaseUrl)).called(1);
});

test('makes correct call to process.run with version constraint',
() async {
Expand All @@ -280,6 +307,18 @@ void main() {
);
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);
});
});
});
}