Skip to content

Commit

Permalink
Support publishing to a hosted-url with a /path
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasfj committed Nov 30, 2021
1 parent 96404e0 commit b9edfa5
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/src/command/lish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class LishCommand extends PubCommand {

try {
await log.progress('Uploading', () async {
var newUri = server.resolve('/api/packages/versions/new');
var newUri = server.resolve('api/packages/versions/new');
var response = await client.get(newUri, headers: pubApiHeaders);
var parameters = parseJsonResponse(response);

Expand Down
30 changes: 30 additions & 0 deletions test/lish/archives_and_uploads_a_package_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ void main() {
await pub.shouldExit(exit_codes.SUCCESS);
});

test('publishes to hosted-url with path', () async {
await servePackages();
await d.tokensFile({
'version': 1,
'hosted': [
{'url': globalPackageServer.url + '/sub/folder', 'env': 'TOKEN'},
]
}).create();
var pub = await startPublish(
globalPackageServer,
path: '/sub/folder',
authMethod: 'token',
environment: {'TOKEN': 'access token'},
);

await confirmPublish(pub);
handleUploadForm(globalPackageServer, path: '/sub/folder');
handleUpload(globalPackageServer);

globalPackageServer.expect('GET', '/create', (request) {
return shelf.Response.ok(jsonEncode({
'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
}));
});

expect(pub.stdout, emits(startsWith('Uploading...')));
expect(pub.stdout, emits('Package test_pkg 1.0.0 uploaded!'));
await pub.shouldExit(exit_codes.SUCCESS);
});

// This is a regression test for #1679. We create a submodule that's not
// checked out to ensure that file listing doesn't choke on the empty
// directory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
'url': 'http://example.com/upload',
'fields': {'field': 12}
};
handleUploadForm(globalPackageServer, body);
handleUploadForm(globalPackageServer, body: body);
expect(pub.stderr, emits('Invalid server response:'));
expect(pub.stderr, emits(jsonEncode(body)));
await pub.shouldExit(1);
Expand Down
2 changes: 1 addition & 1 deletion test/lish/upload_form_fields_is_not_a_map_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {
await confirmPublish(pub);

var body = {'url': 'http://example.com/upload', 'fields': 12};
handleUploadForm(globalPackageServer, body);
handleUploadForm(globalPackageServer, body: body);
expect(pub.stderr, emits('Invalid server response:'));
expect(pub.stderr, emits(jsonEncode(body)));
await pub.shouldExit(1);
Expand Down
2 changes: 1 addition & 1 deletion test/lish/upload_form_is_missing_fields_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {
await confirmPublish(pub);

var body = {'url': 'http://example.com/upload'};
handleUploadForm(globalPackageServer, body);
handleUploadForm(globalPackageServer, body: body);
expect(pub.stderr, emits('Invalid server response:'));
expect(pub.stderr, emits(jsonEncode(body)));
await pub.shouldExit(1);
Expand Down
2 changes: 1 addition & 1 deletion test/lish/upload_form_is_missing_url_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
'fields': {'field1': 'value1', 'field2': 'value2'}
};

handleUploadForm(globalPackageServer, body);
handleUploadForm(globalPackageServer, body: body);
expect(pub.stderr, emits('Invalid server response:'));
expect(pub.stderr, emits(jsonEncode(body)));
await pub.shouldExit(1);
Expand Down
2 changes: 1 addition & 1 deletion test/lish/upload_form_url_is_not_a_string_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main() {
'fields': {'field1': 'value1', 'field2': 'value2'}
};

handleUploadForm(globalPackageServer, body);
handleUploadForm(globalPackageServer, body: body);
expect(pub.stderr, emits('Invalid server response:'));
expect(pub.stderr, emits(jsonEncode(body)));
await pub.shouldExit(1);
Expand Down
4 changes: 2 additions & 2 deletions test/lish/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import 'package:test/test.dart';

import '../test_pub.dart';

void handleUploadForm(PackageServer server, [Map body]) {
server.expect('GET', '/api/packages/versions/new', (request) {
void handleUploadForm(PackageServer server, {Map body, String path = ''}) {
server.expect('GET', '$path/api/packages/versions/new', (request) {
expect(
request.headers, containsPair('authorization', 'Bearer access token'));

Expand Down
3 changes: 2 additions & 1 deletion test/test_pub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,12 @@ Future<PubProcess> startPublish(
List<String> args,
String authMethod = 'oauth2',
Map<String, String> environment,
String path = '',
}) async {
var tokenEndpoint = Uri.parse(server.url).resolve('/token').toString();
args = ['lish', ...?args];
return await startPub(args: args, tokenEndpoint: tokenEndpoint, environment: {
'PUB_HOSTED_URL': server.url,
'PUB_HOSTED_URL': server.url + path,
'_PUB_TEST_AUTH_METHOD': authMethod,
if (environment != null) ...environment,
});
Expand Down

0 comments on commit b9edfa5

Please sign in to comment.