refactor(shorebird_cli): use scoped logger (#608)

This commit is contained in:
Felix Angelov
2023-06-08 09:27:35 -07:00
committed by GitHub
parent 24c966567a
commit fc58700d2d
83 changed files with 899 additions and 746 deletions
+8 -1
View File
@@ -1,9 +1,16 @@
import 'dart:io';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/command_runner.dart';
import 'package:shorebird_cli/src/logger.dart';
Future<void> main(List<String> args) async {
await _flushThenExit(await ShorebirdCliCommandRunner().run(args));
await _flushThenExit(
await runScoped(
() async => ShorebirdCliCommandRunner().run(args),
values: {loggerRef},
),
);
}
/// Flushes the stdout and stderr streams, then exits the program with the given
+4 -14
View File
@@ -4,11 +4,11 @@ import 'dart:io';
import 'package:cli_util/cli_util.dart';
import 'package:googleapis_auth/auth_io.dart' as oauth2;
import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/auth/jwt.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/command_runner.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
final _clientId = oauth2.ClientId(
@@ -47,18 +47,13 @@ typedef OnRefreshCredentials = void Function(
);
class LoggingClient extends http.BaseClient {
LoggingClient({
required http.Client httpClient,
required Logger logger,
}) : _baseClient = httpClient,
_logger = logger;
LoggingClient({required http.Client httpClient}) : _baseClient = httpClient;
final http.Client _baseClient;
final Logger _logger;
@override
Future<http.StreamedResponse> send(http.BaseRequest request) async {
_logger.detail('[HTTP] $request');
logger.detail('[HTTP] $request');
return _baseClient.send(request);
}
}
@@ -66,7 +61,6 @@ class LoggingClient extends http.BaseClient {
class AuthenticatedClient extends LoggingClient {
AuthenticatedClient({
required super.httpClient,
required super.logger,
required oauth2.AccessCredentials credentials,
required OnRefreshCredentials onRefreshCredentials,
RefreshCredentials refreshCredentials = oauth2.refreshCredentials,
@@ -96,13 +90,11 @@ class AuthenticatedClient extends LoggingClient {
class Auth {
Auth({
Logger? logger,
http.Client? httpClient,
String? credentialsDir,
ObtainAccessCredentials? obtainAccessCredentials,
CodePushClientBuilder? buildCodePushClient,
}) : logger = logger ?? Logger(),
_httpClient = httpClient ?? http.Client(),
}) : _httpClient = httpClient ?? http.Client(),
_credentialsDir =
credentialsDir ?? applicationConfigHome(executableName),
_obtainAccessCredentials = obtainAccessCredentials ??
@@ -115,7 +107,6 @@ class Auth {
final String _credentialsDir;
final ObtainAccessCredentials _obtainAccessCredentials;
final CodePushClientBuilder _buildCodePushClient;
final Logger logger;
String get credentialsFilePath {
return p.join(_credentialsDir, 'credentials.json');
@@ -128,7 +119,6 @@ class Auth {
credentials: credentials,
httpClient: _httpClient,
onRefreshCredentials: _flushCredentials,
logger: logger,
);
}
@@ -1,6 +1,7 @@
import 'package:collection/collection.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:meta/meta.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/third_party/flutter_tools/lib/flutter_tools.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
@@ -36,13 +37,9 @@ class PatchArtifactBundle {
/// {@endtemplate}
class CodePushClientWrapper {
/// {@macro code_push_client_wrapper}
CodePushClientWrapper({
required this.codePushClient,
required this.logger,
});
CodePushClientWrapper({required this.codePushClient});
final CodePushClient codePushClient;
final Logger logger;
Future<AppMetadata> getApp({required String appId}) async {
final app = await maybeGetApp(appId: appId);
+1 -5
View File
@@ -4,7 +4,6 @@ import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:checked_yaml/checked_yaml.dart';
import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:pubspec_parse/pubspec_parse.dart';
@@ -40,7 +39,6 @@ List<Validator> _defaultValidators() => [
abstract class ShorebirdCommand extends Command<int> {
ShorebirdCommand({
required this.logger,
Auth? auth,
Cache? cache,
CodePushClientBuilder? buildCodePushClient,
@@ -49,21 +47,19 @@ abstract class ShorebirdCommand extends Command<int> {
}) : cache = cache ?? Cache(),
buildCodePushClient = buildCodePushClient ?? CodePushClient.new,
validators = validators ?? _defaultValidators() {
this.auth = auth ?? Auth(logger: logger);
this.auth = auth ?? Auth();
this.codePushClientWrapper = codePushClientWrapper ??
CodePushClientWrapper(
codePushClient: CodePushClient(
httpClient: this.auth.client,
hostedUri: hostedUri,
),
logger: logger,
);
}
late final Auth auth;
final Cache cache;
final CodePushClientBuilder buildCodePushClient;
final Logger logger;
late final CodePushClientWrapper codePushClientWrapper;
// We don't currently have a test involving both a CommandRunner
@@ -1,8 +1,12 @@
import 'dart:async';
import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:cli_completion/cli_completion.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:shorebird_cli/src/version.dart';
@@ -20,10 +24,7 @@ const description = 'The shorebird command-line tool';
/// {@endtemplate}
class ShorebirdCliCommandRunner extends CompletionCommandRunner<int> {
/// {@macro shorebird_cli_command_runner}
ShorebirdCliCommandRunner({
Logger? logger,
}) : _logger = logger ?? Logger(),
super(executableName, description) {
ShorebirdCliCommandRunner() : super(executableName, description) {
argParser
..addFlag(
'version',
@@ -36,7 +37,7 @@ class ShorebirdCliCommandRunner extends CompletionCommandRunner<int> {
help: 'Noisy logging, including all shell commands executed.',
callback: (verbose) {
if (verbose) {
_logger.level = Level.verbose;
logger.level = Level.verbose;
}
},
)
@@ -53,27 +54,26 @@ class ShorebirdCliCommandRunner extends CompletionCommandRunner<int> {
'are building Flutter locally.',
);
addCommand(AccountCommand(logger: _logger));
addCommand(AppsCommand(logger: _logger));
addCommand(BuildCommand(logger: _logger));
addCommand(CacheCommand(logger: _logger));
addCommand(CollaboratorsCommand(logger: _logger));
addCommand(DoctorCommand(logger: _logger));
addCommand(InitCommand(logger: _logger));
addCommand(LoginCommand(logger: _logger));
addCommand(LogoutCommand(logger: _logger));
addCommand(PatchCommand(logger: _logger));
addCommand(ReleaseCommand(logger: _logger));
addCommand(ReleasesCommand(logger: _logger));
addCommand(RunCommand(logger: _logger));
addCommand(SubscriptionCommand(logger: _logger));
addCommand(UpgradeCommand(logger: _logger));
addCommand(AccountCommand());
addCommand(AppsCommand());
addCommand(BuildCommand());
addCommand(CacheCommand());
addCommand(CollaboratorsCommand());
addCommand(DoctorCommand());
addCommand(InitCommand());
addCommand(LoginCommand());
addCommand(LogoutCommand());
addCommand(PatchCommand());
addCommand(ReleaseCommand());
addCommand(ReleasesCommand());
addCommand(RunCommand());
addCommand(SubscriptionCommand());
addCommand(UpgradeCommand());
}
@override
void printUsage() => _logger.info(usage);
void printUsage() => logger.info(usage);
final Logger _logger;
// Currently using ShorebirdCliCommandRunner as our context object.
late final ShorebirdProcess process;
late final EngineConfig engineConfig;
@@ -90,14 +90,18 @@ class ShorebirdCliCommandRunner extends CompletionCommandRunner<int> {
);
process = ShorebirdProcess(
engineConfig: engineConfig,
logger: _logger,
logger: logger,
);
return await runCommand(topLevelResults) ?? ExitCode.success.code;
return await runScoped<Future<int?>>(
() => runCommand(topLevelResults),
values: {},
) ??
ExitCode.success.code;
} on FormatException catch (e, stackTrace) {
// On format errors, show the commands error message, root usage and
// exit with an error code
_logger
logger
..err(e.message)
..err('$stackTrace')
..info('')
@@ -106,7 +110,7 @@ class ShorebirdCliCommandRunner extends CompletionCommandRunner<int> {
} on UsageException catch (e) {
// On usage errors, show the commands usage message and
// exit with an error code
_logger
logger
..err(e.message)
..info('')
..info(e.usage);
@@ -125,7 +129,7 @@ class ShorebirdCliCommandRunner extends CompletionCommandRunner<int> {
// Run the command or show version
final int? exitCode;
if (topLevelResults['version'] == true) {
_logger.info(
logger.info(
'''
Shorebird $packageVersion
Shorebird Engine • revision ${ShorebirdEnvironment.shorebirdEngineRevision}''',
@@ -7,9 +7,9 @@ import 'package:shorebird_cli/src/commands/commands.dart';
/// {@endtemplate}
class AccountCommand extends ShorebirdCommand {
/// {@macro account_command}
AccountCommand({required super.logger, super.auth}) {
addSubcommand(CreateAccountCommand(logger: logger));
addSubcommand(SubscribeAccountCommand(logger: logger));
AccountCommand({super.auth}) {
addSubcommand(CreateAccountCommand());
addSubcommand(SubscribeAccountCommand());
}
@override
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
@@ -12,7 +13,7 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
/// {@endtemplate}
class CreateAccountCommand extends ShorebirdCommand with ShorebirdConfigMixin {
/// {@macro create_account_command}
CreateAccountCommand({required super.logger, super.auth});
CreateAccountCommand({super.auth});
@override
String get description => 'Create a new Shorebird account.';
@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
@@ -12,11 +13,7 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
class SubscribeAccountCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro subscribe_account_command}
SubscribeAccountCommand({
required super.logger,
super.auth,
super.buildCodePushClient,
});
SubscribeAccountCommand({super.auth, super.buildCodePushClient});
@override
String get name => 'subscribe';
@@ -8,10 +8,10 @@ import 'package:shorebird_cli/src/commands/commands.dart';
/// {@endtemplate}
class AppsCommand extends ShorebirdCommand {
/// {@macro apps_command}
AppsCommand({required super.logger}) {
addSubcommand(CreateAppCommand(logger: logger));
addSubcommand(DeleteAppCommand(logger: logger));
addSubcommand(ListAppsCommand(logger: logger));
AppsCommand() {
addSubcommand(CreateAppCommand());
addSubcommand(DeleteAppCommand());
addSubcommand(ListAppsCommand());
}
@override
@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_create_app_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
@@ -18,11 +19,7 @@ class CreateAppCommand extends ShorebirdCommand
ShorebirdValidationMixin,
ShorebirdCreateAppMixin {
/// {@macro create_app_command}
CreateAppCommand({
required super.logger,
super.buildCodePushClient,
super.auth,
}) {
CreateAppCommand({super.buildCodePushClient, super.auth}) {
argParser.addOption(
'app-name',
help: '''
@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
@@ -13,11 +14,7 @@ import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
class DeleteAppCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro delete_app_command}
DeleteAppCommand({
required super.logger,
super.buildCodePushClient,
super.auth,
}) {
DeleteAppCommand({super.buildCodePushClient, super.auth}) {
argParser.addOption(
'app-id',
help: '''
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:barbecue/barbecue.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
@@ -15,11 +16,7 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
class ListAppsCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro list_apps_command}
ListAppsCommand({
required super.logger,
super.buildCodePushClient,
super.auth,
});
ListAppsCommand({super.buildCodePushClient, super.auth});
@override
String get description => 'List all apps using Shorebird.';
@@ -4,6 +4,7 @@ import 'dart:io';
import 'package:mason_logger/mason_logger.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
@@ -15,11 +16,7 @@ import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
/// {@endtemplate}
class BuildAarCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin, ShorebirdBuildMixin {
BuildAarCommand({
required super.logger,
super.auth,
super.validators,
}) {
BuildAarCommand({super.auth, super.validators}) {
// We would have a "target" option here, similar to what [BuildApkCommand]
// and [BuildAabCommand] have, but target cannot currently be configured in
// `flutter build aar` and is always assumed to be lib/main.dart.
@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:mason_logger/mason_logger.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
@@ -15,11 +16,7 @@ import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
class BuildApkCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin, ShorebirdBuildMixin {
/// {@macro build_apk_command}
BuildApkCommand({
required super.logger,
super.auth,
super.validators,
}) {
BuildApkCommand({super.auth, super.validators}) {
argParser
..addOption(
'target',
@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:mason_logger/mason_logger.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
@@ -15,11 +16,7 @@ import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
class BuildAppBundleCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin, ShorebirdBuildMixin {
/// {@macro build_app_bundle_command}
BuildAppBundleCommand({
required super.logger,
super.auth,
super.validators,
}) {
BuildAppBundleCommand({super.auth, super.validators}) {
argParser
..addOption(
'target',
@@ -7,11 +7,11 @@ import 'package:shorebird_cli/src/commands/build/build.dart';
/// {@endtemplate}
class BuildCommand extends ShorebirdCommand {
/// {@macro build_command}
BuildCommand({required super.logger}) {
addSubcommand(BuildAarCommand(logger: logger));
addSubcommand(BuildApkCommand(logger: logger));
addSubcommand(BuildAppBundleCommand(logger: logger));
addSubcommand(BuildIpaCommand(logger: logger));
BuildCommand() {
addSubcommand(BuildAarCommand());
addSubcommand(BuildApkCommand());
addSubcommand(BuildAppBundleCommand());
addSubcommand(BuildIpaCommand());
}
@override
@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:mason_logger/mason_logger.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
@@ -15,7 +16,7 @@ import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
class BuildIpaCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin, ShorebirdBuildMixin {
/// {@macro build_ipa_command}
BuildIpaCommand({required super.logger, super.auth, super.validators}) {
BuildIpaCommand({super.auth, super.validators}) {
argParser
..addOption(
'target',
@@ -7,8 +7,8 @@ import 'package:shorebird_cli/src/commands/commands.dart';
/// {@endtemplate}
class CacheCommand extends ShorebirdCommand {
/// {@macro cache_command}
CacheCommand({required super.logger, super.cache}) {
addSubcommand(CleanCacheCommand(logger: logger, cache: cache));
CacheCommand({super.cache}) {
addSubcommand(CleanCacheCommand(cache: cache));
}
@override
@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
/// {@template clean_cache_command}
@@ -10,7 +11,7 @@ import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
/// {@endtemplate}
class CleanCacheCommand extends ShorebirdCommand with ShorebirdConfigMixin {
/// {@macro clean_cache_command}
CleanCacheCommand({required super.logger, required super.cache});
CleanCacheCommand({required super.cache});
@override
String get description => 'Clears the Shorebird cache directory.';
@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
@@ -12,11 +13,7 @@ import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
class AddCollaboratorsCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro add_collaborators_command}
AddCollaboratorsCommand({
required super.logger,
super.buildCodePushClient,
super.auth,
}) {
AddCollaboratorsCommand({super.buildCodePushClient, super.auth}) {
argParser
..addOption(
_appIdOption,
@@ -7,10 +7,10 @@ import 'package:shorebird_cli/src/commands/commands.dart';
/// {@endtemplate}
class CollaboratorsCommand extends ShorebirdCommand {
/// {@macro collaborators_command}
CollaboratorsCommand({required super.logger}) {
addSubcommand(AddCollaboratorsCommand(logger: logger));
addSubcommand(DeleteCollaboratorsCommand(logger: logger));
addSubcommand(ListCollaboratorsCommand(logger: logger));
CollaboratorsCommand() {
addSubcommand(AddCollaboratorsCommand());
addSubcommand(DeleteCollaboratorsCommand());
addSubcommand(ListCollaboratorsCommand());
}
@override
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:collection/collection.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
@@ -14,11 +15,7 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
class DeleteCollaboratorsCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro delete_collaborators_command}
DeleteCollaboratorsCommand({
required super.logger,
super.buildCodePushClient,
super.auth,
}) {
DeleteCollaboratorsCommand({super.buildCodePushClient, super.auth}) {
argParser
..addOption(
_appIdOption,
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:barbecue/barbecue.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
@@ -14,11 +15,7 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
class ListCollaboratorsCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro list_collaborators_command}
ListCollaboratorsCommand({
required super.logger,
super.buildCodePushClient,
super.auth,
}) {
ListCollaboratorsCommand({super.buildCodePushClient, super.auth}) {
argParser.addOption(
_appIdOption,
help: 'The app id to list collaborators for.',
@@ -1,6 +1,7 @@
import 'package:collection/collection.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_version_mixin.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
@@ -13,10 +14,7 @@ import 'package:shorebird_cli/src/version.dart';
/// {@endtemplate}
class DoctorCommand extends ShorebirdCommand with ShorebirdVersionMixin {
/// {@macro doctor_command}
DoctorCommand({
required super.logger,
super.validators,
}) {
DoctorCommand({super.validators}) {
validators = _allValidators(baseValidators: validators);
argParser.addFlag(
@@ -2,6 +2,7 @@ import 'dart:io';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_create_app_mixin.dart';
import 'package:shorebird_cli/src/shorebird_flavor_mixin.dart';
@@ -21,7 +22,7 @@ class InitCommand extends ShorebirdCommand
ShorebirdJavaMixin,
ShorebirdFlavorMixin {
/// {@macro init_command}
InitCommand({required super.logger, super.auth, super.buildCodePushClient}) {
InitCommand({super.auth, super.buildCodePushClient}) {
argParser.addFlag(
'force',
abbr: 'f',
@@ -1,6 +1,7 @@
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
/// {@template login_command}
/// `shorebird login`
@@ -8,7 +9,7 @@ import 'package:shorebird_cli/src/command.dart';
/// {@endtemplate}
class LoginCommand extends ShorebirdCommand {
/// {@macro login_command}
LoginCommand({required super.logger, super.auth});
LoginCommand({super.auth});
@override
String get description => 'Login as a new Shorebird user.';
@@ -1,5 +1,6 @@
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
/// {@template logout_command}
///
@@ -8,7 +9,7 @@ import 'package:shorebird_cli/src/command.dart';
/// {@endtemplate}
class LogoutCommand extends ShorebirdCommand {
/// {@macro logout_command}
LogoutCommand({required super.logger, super.auth});
LogoutCommand({super.auth});
@override
String get description => 'Logout of the current Shorebird user';
@@ -11,6 +11,7 @@ import 'package:shorebird_cli/src/code_push_client_wrapper.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/config/config.dart';
import 'package:shorebird_cli/src/formatters/file_size_formatter.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_artifact_mixin.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_code_push_client_mixin.dart';
@@ -34,7 +35,6 @@ class PatchAarCommand extends ShorebirdCommand
ShorebirdArtifactMixin {
/// {@macro patch_aar_command}
PatchAarCommand({
required super.logger,
super.auth,
super.buildCodePushClient,
super.cache,
@@ -9,6 +9,7 @@ import 'package:shorebird_cli/src/code_push_client_wrapper.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/config/shorebird_yaml.dart';
import 'package:shorebird_cli/src/formatters/formatters.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_create_app_mixin.dart';
@@ -32,7 +33,6 @@ class PatchAndroidCommand extends ShorebirdCommand
ShorebirdReleaseVersionMixin {
/// {@macro patch_android_command}
PatchAndroidCommand({
required super.logger,
super.auth,
super.cache,
super.validators,
@@ -7,10 +7,10 @@ import 'package:shorebird_cli/src/commands/commands.dart';
/// {@endtemplate}
class PatchCommand extends ShorebirdCommand {
/// {@macro patch_command}
PatchCommand({required super.logger}) {
addSubcommand(PatchAarCommand(logger: logger));
addSubcommand(PatchAndroidCommand(logger: logger));
addSubcommand(PatchIosCommand(logger: logger));
PatchCommand() {
addSubcommand(PatchAarCommand());
addSubcommand(PatchAndroidCommand());
addSubcommand(PatchIosCommand());
}
@override
@@ -8,6 +8,7 @@ import 'package:shorebird_cli/src/archive_analysis/archive_analysis.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/config/config.dart';
import 'package:shorebird_cli/src/formatters/file_size_formatter.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_artifact_mixin.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_code_push_client_mixin.dart';
@@ -28,7 +29,6 @@ class PatchIosCommand extends ShorebirdCommand
ShorebirdCodePushClientMixin {
/// {@macro patch_ios_command}
PatchIosCommand({
required super.logger,
super.auth,
super.buildCodePushClient,
super.validators,
@@ -8,6 +8,7 @@ import 'package:mason_logger/mason_logger.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/config/config.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_artifact_mixin.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
@@ -32,7 +33,6 @@ class ReleaseAarCommand extends ShorebirdCommand
ShorebirdArtifactMixin {
/// {@macro release_aar_command}
ReleaseAarCommand({
required super.logger,
super.auth,
super.buildCodePushClient,
super.validators,
@@ -6,6 +6,7 @@ import 'package:mason_logger/mason_logger.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/config/shorebird_yaml.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_create_app_mixin.dart';
@@ -28,7 +29,6 @@ class ReleaseAndroidCommand extends ShorebirdCommand
ShorebirdReleaseVersionMixin {
/// {@macro release_android_command}
ReleaseAndroidCommand({
required super.logger,
super.auth,
super.cache,
super.buildCodePushClient,
@@ -7,10 +7,10 @@ import 'package:shorebird_cli/src/commands/commands.dart';
/// {@endtemplate}
class ReleaseCommand extends ShorebirdCommand {
/// {@macro release_command}
ReleaseCommand({required super.logger}) {
addSubcommand(ReleaseAarCommand(logger: logger));
addSubcommand(ReleaseAndroidCommand(logger: logger));
addSubcommand(ReleaseIosCommand(logger: logger));
ReleaseCommand() {
addSubcommand(ReleaseAarCommand());
addSubcommand(ReleaseAndroidCommand());
addSubcommand(ReleaseIosCommand());
}
@override
@@ -5,6 +5,7 @@ import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/archive_analysis/archive_analysis.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/config/config.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_code_push_client_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
@@ -23,7 +24,6 @@ class ReleaseIosCommand extends ShorebirdCommand
ShorebirdCodePushClientMixin {
/// {@macro release_ios_command}
ReleaseIosCommand({
required super.logger,
super.auth,
super.buildCodePushClient,
super.cache,
@@ -4,6 +4,7 @@ import 'package:collection/collection.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/config/shorebird_yaml.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
@@ -16,11 +17,7 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
class DeleteReleasesCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro delete_releases_command}
DeleteReleasesCommand({
required super.logger,
super.auth,
super.buildCodePushClient,
}) {
DeleteReleasesCommand({super.auth, super.buildCodePushClient}) {
argParser
..addOption(
'version',
@@ -2,6 +2,7 @@ import 'package:barbecue/barbecue.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/config/shorebird_yaml.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
@@ -14,11 +15,7 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
class ListReleasesCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro list_releases_command}
ListReleasesCommand({
required super.logger,
super.auth,
super.buildCodePushClient,
}) {
ListReleasesCommand({super.auth, super.buildCodePushClient}) {
argParser.addOption(
'flavor',
help: 'The product flavor to use when listing releases.',
@@ -8,9 +8,9 @@ import 'package:shorebird_cli/src/commands/releases/releases.dart';
/// {@endtemplate}
class ReleasesCommand extends ShorebirdCommand {
/// {@macro releases_command}
ReleasesCommand({required super.logger}) {
addSubcommand(DeleteReleasesCommand(logger: logger));
addSubcommand(ListReleasesCommand(logger: logger));
ReleasesCommand() {
addSubcommand(DeleteReleasesCommand());
addSubcommand(ListReleasesCommand());
}
@override
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
@@ -11,12 +12,7 @@ import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
class RunCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro run_command}
RunCommand({
required super.logger,
super.auth,
super.buildCodePushClient,
super.validators,
}) {
RunCommand({super.auth, super.buildCodePushClient, super.validators}) {
argParser
..addOption(
'device-id',
@@ -3,17 +3,14 @@ import 'dart:async';
import 'package:intl/intl.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
class CancelSubscriptionCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin {
CancelSubscriptionCommand({
required super.logger,
super.auth,
super.buildCodePushClient,
});
CancelSubscriptionCommand({super.auth, super.buildCodePushClient});
@override
String get name => 'cancel';
@@ -8,8 +8,8 @@ import 'package:shorebird_cli/src/commands/subscription/subscription.dart';
/// {@endtemplate}
class SubscriptionCommand extends ShorebirdCommand {
/// {@macro subscription_command}
SubscriptionCommand({required super.logger}) {
addSubcommand(CancelSubscriptionCommand(logger: logger));
SubscriptionCommand() {
addSubcommand(CancelSubscriptionCommand());
}
@override
@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:mason_logger/mason_logger.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_version_mixin.dart';
@@ -12,7 +13,7 @@ import 'package:shorebird_cli/src/shorebird_version_mixin.dart';
/// {@endtemplate}
class UpgradeCommand extends ShorebirdCommand with ShorebirdVersionMixin {
/// {@macro upgrade_command}
UpgradeCommand({required super.logger});
UpgradeCommand();
@override
String get description => 'Upgrade your copy of Shorebird.';
@@ -0,0 +1,8 @@
import 'package:mason_logger/mason_logger.dart';
import 'package:scoped/scoped.dart';
// A reference to a [Logger] instance.
ScopedRef<Logger> loggerRef = create(Logger.new);
// The [Logger] instance available in the current zone.
Logger get logger => read(loggerRef);
@@ -2,6 +2,7 @@ import 'dart:io';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/logger.dart';
mixin ShorebirdArtifactMixin on ShorebirdCommand {
String aarArtifactDirectory({
@@ -1,4 +1,5 @@
import 'package:collection/collection.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
@@ -1,4 +1,5 @@
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
@@ -1,5 +1,6 @@
import 'package:collection/collection.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
+2
View File
@@ -27,6 +27,8 @@ dependencies:
platform: ^3.1.0
propertylistserialization: ^1.3.0
pubspec_parse: ^1.2.2
scoped:
path: ../scoped
shorebird_code_push_client:
path: ../shorebird_code_push_client
version: ^3.0.2
@@ -6,7 +6,9 @@ import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
import 'package:test/test.dart';
@@ -50,6 +52,10 @@ void main() {
registerFallbackValue(_FakeBaseRequest());
});
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
Auth buildAuth() {
return Auth(
credentialsDir: credentialsDir,
@@ -60,13 +66,13 @@ void main() {
obtainAccessCredentials: (clientId, scopes, client, userPrompt) async {
return accessCredentials;
},
logger: logger,
);
}
void writeCredentials() {
File(p.join(credentialsDir, 'credentials.json'))
.writeAsStringSync(jsonEncode(accessCredentials.toJson()));
File(
p.join(credentialsDir, 'credentials.json'),
).writeAsStringSync(jsonEncode(accessCredentials.toJson()));
}
setUp(() {
@@ -79,21 +85,6 @@ void main() {
when(() => codePushClient.getCurrentUser()).thenAnswer((_) async => user);
});
test('uses default logger if none is provided', () {
final auth = Auth(
credentialsDir: credentialsDir,
httpClient: httpClient,
buildCodePushClient: ({Uri? hostedUri, http.Client? httpClient}) {
return codePushClient;
},
obtainAccessCredentials: (clientId, scopes, client, userPrompt) async {
return accessCredentials;
},
);
expect(auth.logger, isA<Logger>());
});
group('AuthenticatedClient', () {
test('refreshes and uses new token when credentials are expired.',
() async {
@@ -122,10 +113,11 @@ void main() {
onRefreshCredentials: onRefreshCredentialsCalls.add,
refreshCredentials: (clientId, credentials, client) async =>
accessCredentials,
logger: logger,
);
await client.get(Uri.parse('https://example.com'));
await runWithOverrides(
() => client.get(Uri.parse('https://example.com')),
);
expect(
onRefreshCredentialsCalls,
@@ -151,10 +143,11 @@ void main() {
credentials: accessCredentials,
httpClient: httpClient,
onRefreshCredentials: onRefreshCredentialsCalls.add,
logger: logger,
);
await client.get(Uri.parse('https://example.com'));
await runWithOverrides(
() => client.get(Uri.parse('https://example.com')),
);
expect(onRefreshCredentialsCalls, isEmpty);
final captured = verify(() => httpClient.send(captureAny())).captured;
@@ -179,7 +172,9 @@ void main() {
expect(client, isA<http.Client>());
expect(client, isA<AuthenticatedClient>());
await client.get(Uri.parse('https://example.com'));
await runWithOverrides(
() => client.get(Uri.parse('https://example.com')),
);
final captured = verify(() => httpClient.send(captureAny())).captured;
expect(captured, hasLength(1));
@@ -1,6 +1,8 @@
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/code_push_client_wrapper.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/third_party/flutter_tools/lib/flutter_tools.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
@@ -68,9 +70,12 @@ void main() {
late CodePushClient codePushClient;
late Logger logger;
late Progress progress;
late CodePushClientWrapper codePushClientWrapper;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUpAll(setExitFunctionForTests);
tearDownAll(restoreExitFunction);
@@ -80,9 +85,8 @@ void main() {
logger = _MockLogger();
progress = _MockProgress();
codePushClientWrapper = CodePushClientWrapper(
codePushClient: codePushClient,
logger: logger,
codePushClientWrapper = runWithOverrides(
() => CodePushClientWrapper(codePushClient: codePushClient),
);
when(() => logger.progress(any())).thenReturn(progress);
@@ -95,7 +99,9 @@ void main() {
when(() => codePushClient.getApps()).thenThrow(error);
await expectLater(
() async => codePushClientWrapper.getApp(appId: appId),
() async => runWithOverrides(
() => codePushClientWrapper.getApp(appId: appId),
),
exitsWithCode(ExitCode.software),
);
verify(() => progress.fail(error)).called(1);
@@ -105,7 +111,9 @@ void main() {
when(() => codePushClient.getApps()).thenAnswer((_) async => []);
await expectLater(
() async => codePushClientWrapper.getApp(appId: appId),
() async => runWithOverrides(
() => codePushClientWrapper.getApp(appId: appId),
),
exitsWithCode(ExitCode.software),
);
@@ -120,7 +128,9 @@ void main() {
test('returns app when app exists', () async {
when(() => codePushClient.getApps()).thenAnswer((_) async => [app]);
final result = await codePushClientWrapper.getApp(appId: appId);
final result = await runWithOverrides(
() => codePushClientWrapper.getApp(appId: appId),
);
expect(result, app);
verify(() => progress.complete()).called(1);
@@ -133,7 +143,9 @@ void main() {
when(() => codePushClient.getApps()).thenThrow(error);
await expectLater(
() async => codePushClientWrapper.maybeGetApp(appId: appId),
() async => runWithOverrides(
() => codePushClientWrapper.maybeGetApp(appId: appId),
),
exitsWithCode(ExitCode.software),
);
verify(() => progress.fail(error)).called(1);
@@ -142,8 +154,8 @@ void main() {
test('succeeds if app does not exist', () async {
when(() => codePushClient.getApps()).thenAnswer((_) async => []);
final result = await codePushClientWrapper.maybeGetApp(
appId: appId,
final result = await runWithOverrides(
() => codePushClientWrapper.maybeGetApp(appId: appId),
);
expect(result, isNull);
@@ -154,7 +166,9 @@ void main() {
test('returns app when app exists', () async {
when(() => codePushClient.getApps()).thenAnswer((_) async => [app]);
final result = await codePushClientWrapper.maybeGetApp(appId: appId);
final result = await runWithOverrides(
() => codePushClientWrapper.maybeGetApp(appId: appId),
);
expect(result, app);
verify(() => progress.complete()).called(1);
@@ -166,13 +180,16 @@ void main() {
group('maybeGetChannel', () {
test('throws error when fetching channels fails', () async {
const error = 'something went wrong';
when(() => codePushClient.getChannels(appId: any(named: 'appId')))
.thenThrow(error);
when(
() => codePushClient.getChannels(appId: any(named: 'appId')),
).thenThrow(error);
await expectLater(
() async => codePushClientWrapper.maybeGetChannel(
appId: appId,
name: channelName,
() async => runWithOverrides(
() => codePushClientWrapper.maybeGetChannel(
appId: appId,
name: channelName,
),
),
exitsWithCode(ExitCode.software),
);
@@ -180,12 +197,15 @@ void main() {
});
test('returns null when channel does not exist', () async {
when(() => codePushClient.getChannels(appId: any(named: 'appId')))
.thenAnswer((_) async => []);
when(
() => codePushClient.getChannels(appId: any(named: 'appId')),
).thenAnswer((_) async => []);
final result = await codePushClientWrapper.maybeGetChannel(
appId: appId,
name: channelName,
final result = await runWithOverrides(
() => codePushClientWrapper.maybeGetChannel(
appId: appId,
name: channelName,
),
);
expect(result, isNull);
@@ -193,12 +213,15 @@ void main() {
});
test('returns channel when channel exists', () async {
when(() => codePushClient.getChannels(appId: any(named: 'appId')))
.thenAnswer((_) async => [channel]);
when(
() => codePushClient.getChannels(appId: any(named: 'appId')),
).thenAnswer((_) async => [channel]);
final result = await codePushClientWrapper.maybeGetChannel(
appId: appId,
name: channelName,
final result = await runWithOverrides(
() => codePushClientWrapper.maybeGetChannel(
appId: appId,
name: channelName,
),
);
expect(result, channel);
@@ -217,9 +240,11 @@ void main() {
).thenThrow(error);
await expectLater(
() async => codePushClientWrapper.createChannel(
appId: appId,
name: channelName,
() async => runWithOverrides(
() => codePushClientWrapper.createChannel(
appId: appId,
name: channelName,
),
),
exitsWithCode(ExitCode.software),
);
@@ -234,9 +259,11 @@ void main() {
),
).thenAnswer((_) async => channel);
final result = await codePushClientWrapper.createChannel(
appId: appId,
name: channelName,
final result = await runWithOverrides(
() => codePushClientWrapper.createChannel(
appId: appId,
name: channelName,
),
);
expect(result, channel);
@@ -249,13 +276,16 @@ void main() {
group('getRelease', () {
test('throws error when fetching release fails.', () async {
const error = 'something went wrong';
when(() => codePushClient.getReleases(appId: any(named: 'appId')))
.thenThrow(error);
when(
() => codePushClient.getReleases(appId: any(named: 'appId')),
).thenThrow(error);
await expectLater(
() async => codePushClientWrapper.getRelease(
appId: appId,
releaseVersion: releaseVersion,
() async => runWithOverrides(
() => codePushClientWrapper.getRelease(
appId: appId,
releaseVersion: releaseVersion,
),
),
exitsWithCode(ExitCode.software),
);
@@ -263,13 +293,16 @@ void main() {
});
test('throws error when release does not exist', () async {
when(() => codePushClient.getReleases(appId: any(named: 'appId')))
.thenAnswer((_) async => []);
when(
() => codePushClient.getReleases(appId: any(named: 'appId')),
).thenAnswer((_) async => []);
await expectLater(
() async => codePushClientWrapper.getRelease(
appId: appId,
releaseVersion: releaseVersion,
() async => runWithOverrides(
() => codePushClientWrapper.getRelease(
appId: appId,
releaseVersion: releaseVersion,
),
),
exitsWithCode(ExitCode.software),
);
@@ -283,12 +316,15 @@ void main() {
});
test('returns release when release exists', () async {
when(() => codePushClient.getReleases(appId: any(named: 'appId')))
.thenAnswer((_) async => [release]);
when(
() => codePushClient.getReleases(appId: any(named: 'appId')),
).thenAnswer((_) async => [release]);
final result = await codePushClientWrapper.getRelease(
appId: appId,
releaseVersion: releaseVersion,
final result = await runWithOverrides(
() => codePushClientWrapper.getRelease(
appId: appId,
releaseVersion: releaseVersion,
),
);
expect(result, release);
@@ -299,13 +335,16 @@ void main() {
group('maybeGetRelease', () {
test('throws error when fetching apps fails.', () async {
const error = 'something went wrong';
when(() => codePushClient.getReleases(appId: any(named: 'appId')))
.thenThrow(error);
when(
() => codePushClient.getReleases(appId: any(named: 'appId')),
).thenThrow(error);
await expectLater(
() async => codePushClientWrapper.maybeGetRelease(
appId: appId,
releaseVersion: releaseVersion,
() async => runWithOverrides(
() => codePushClientWrapper.maybeGetRelease(
appId: appId,
releaseVersion: releaseVersion,
),
),
exitsWithCode(ExitCode.software),
);
@@ -313,12 +352,15 @@ void main() {
});
test('succeeds if release does not exist', () async {
when(() => codePushClient.getReleases(appId: any(named: 'appId')))
.thenAnswer((_) async => []);
when(
() => codePushClient.getReleases(appId: any(named: 'appId')),
).thenAnswer((_) async => []);
final result = await codePushClientWrapper.maybeGetRelease(
appId: appId,
releaseVersion: releaseVersion,
final result = await runWithOverrides(
() => codePushClientWrapper.maybeGetRelease(
appId: appId,
releaseVersion: releaseVersion,
),
);
expect(result, isNull);
@@ -327,12 +369,15 @@ void main() {
});
test('returns release when release exists', () async {
when(() => codePushClient.getReleases(appId: any(named: 'appId')))
.thenAnswer((_) async => [release]);
when(
() => codePushClient.getReleases(appId: any(named: 'appId')),
).thenAnswer((_) async => [release]);
final result = await codePushClientWrapper.maybeGetRelease(
appId: appId,
releaseVersion: releaseVersion,
final result = await runWithOverrides(
() => codePushClientWrapper.maybeGetRelease(
appId: appId,
releaseVersion: releaseVersion,
),
);
expect(result, release);
@@ -354,10 +399,12 @@ void main() {
).thenThrow(error);
await expectLater(
() async => codePushClientWrapper.getReleaseArtifacts(
releaseId: releaseId,
architectures: archMap,
platform: platform,
() async => runWithOverrides(
() => codePushClientWrapper.getReleaseArtifacts(
releaseId: releaseId,
architectures: archMap,
platform: platform,
),
),
exitsWithCode(ExitCode.software),
);
@@ -374,10 +421,12 @@ void main() {
),
).thenAnswer((_) async => releaseArtifact);
final result = await codePushClientWrapper.getReleaseArtifacts(
releaseId: releaseId,
architectures: archMap,
platform: platform,
final result = await runWithOverrides(
() => codePushClientWrapper.getReleaseArtifacts(
releaseId: releaseId,
architectures: archMap,
platform: platform,
),
);
expect(result, {arch: releaseArtifact});
@@ -397,10 +446,12 @@ void main() {
).thenThrow(error);
await expectLater(
() async => codePushClientWrapper.maybeGetReleaseArtifact(
releaseId: releaseId,
arch: arch.name,
platform: platform,
() async => runWithOverrides(
() => codePushClientWrapper.maybeGetReleaseArtifact(
releaseId: releaseId,
arch: arch.name,
platform: platform,
),
),
exitsWithCode(ExitCode.software),
);
@@ -417,10 +468,12 @@ void main() {
),
).thenThrow(CodePushNotFoundException(message: 'not found'));
final result = await codePushClientWrapper.maybeGetReleaseArtifact(
releaseId: releaseId,
arch: arch.name,
platform: platform,
final result = await runWithOverrides(
() => codePushClientWrapper.maybeGetReleaseArtifact(
releaseId: releaseId,
arch: arch.name,
platform: platform,
),
);
expect(result, isNull);
@@ -438,10 +491,12 @@ void main() {
),
).thenAnswer((_) async => releaseArtifact);
final result = await codePushClientWrapper.maybeGetReleaseArtifact(
releaseId: releaseId,
arch: arch.name,
platform: platform,
final result = await runWithOverrides(
() => codePushClientWrapper.maybeGetReleaseArtifact(
releaseId: releaseId,
arch: arch.name,
platform: platform,
),
);
expect(result, releaseArtifact);
@@ -455,12 +510,15 @@ void main() {
group('createPatch', () {
test('exits with code 70 when creating patch fails', () async {
const error = 'something went wrong';
when(() => codePushClient.createPatch(releaseId: releaseId))
.thenThrow(error);
when(
() => codePushClient.createPatch(releaseId: releaseId),
).thenThrow(error);
await expectLater(
() async => codePushClientWrapper.createPatch(
releaseId: releaseId,
() async => runWithOverrides(
() => codePushClientWrapper.createPatch(
releaseId: releaseId,
),
),
exitsWithCode(ExitCode.software),
);
@@ -468,11 +526,14 @@ void main() {
});
test('returns patch when patch is successfully created.', () async {
when(() => codePushClient.createPatch(releaseId: releaseId))
.thenAnswer((_) async => patch);
when(
() => codePushClient.createPatch(releaseId: releaseId),
).thenAnswer((_) async => patch);
final result = await codePushClientWrapper.createPatch(
releaseId: releaseId,
final result = await runWithOverrides(
() => codePushClientWrapper.createPatch(
releaseId: releaseId,
),
);
expect(result, patch);
@@ -491,16 +552,18 @@ void main() {
).thenThrow(error);
await expectLater(
() async => codePushClientWrapper.promotePatch(
patchId: patchId,
channel: channel,
() async => runWithOverrides(
() => codePushClientWrapper.promotePatch(
patchId: patchId,
channel: channel,
),
),
exitsWithCode(ExitCode.software),
);
verify(() => progress.fail(error)).called(1);
});
test('TODO', () async {
test('completes progress when patch is promoted', () async {
when(
() => codePushClient.promotePatch(
patchId: any(named: 'patchId'),
@@ -508,9 +571,11 @@ void main() {
),
).thenAnswer((_) async => patch);
await codePushClientWrapper.promotePatch(
patchId: patchId,
channel: channel,
await runWithOverrides(
() => codePushClientWrapper.promotePatch(
patchId: patchId,
channel: channel,
),
);
verify(() => progress.complete()).called(1);
@@ -533,10 +598,12 @@ void main() {
).thenThrow(error);
await expectLater(
() async => codePushClientWrapper.createPatchArtifacts(
patch: patch,
platform: platform,
patchArtifactBundles: patchArtifactBundles,
() async => runWithOverrides(
() => codePushClientWrapper.createPatchArtifacts(
patch: patch,
platform: platform,
patchArtifactBundles: patchArtifactBundles,
),
),
exitsWithCode(ExitCode.software),
);
@@ -556,10 +623,12 @@ void main() {
),
).thenAnswer((_) async {});
await codePushClientWrapper.createPatchArtifacts(
patch: patch,
platform: platform,
patchArtifactBundles: patchArtifactBundles,
await runWithOverrides(
() => codePushClientWrapper.createPatchArtifacts(
patch: patch,
platform: platform,
patchArtifactBundles: patchArtifactBundles,
),
);
verify(() => progress.complete()).called(1);
@@ -577,9 +646,9 @@ void main() {
group('publishPatch', () {
setUp(() {
when(() => codePushClient.createPatch(releaseId: releaseId))
.thenAnswer((_) async => patch);
when(
() => codePushClient.createPatch(releaseId: releaseId),
).thenAnswer((_) async => patch);
when(
() => codePushClient.createPatchArtifact(
patchId: any(named: 'patchId'),
@@ -589,10 +658,9 @@ void main() {
hash: any(named: 'hash'),
),
).thenAnswer((_) async {});
when(() => codePushClient.getChannels(appId: any(named: 'appId')))
.thenAnswer((_) async => [channel]);
when(
() => codePushClient.getChannels(appId: any(named: 'appId')),
).thenAnswer((_) async => [channel]);
when(
() => codePushClient.promotePatch(
patchId: any(named: 'patchId'),
@@ -602,16 +670,19 @@ void main() {
});
test('makes expected calls to code push client', () async {
await codePushClientWrapper.publishPatch(
appId: appId,
releaseId: releaseId,
platform: platform,
channelName: channelName,
patchArtifactBundles: patchArtifactBundles,
await runWithOverrides(
() => codePushClientWrapper.publishPatch(
appId: appId,
releaseId: releaseId,
platform: platform,
channelName: channelName,
patchArtifactBundles: patchArtifactBundles,
),
);
verify(() => codePushClient.createPatch(releaseId: releaseId))
.called(1);
verify(
() => codePushClient.createPatch(releaseId: releaseId),
).called(1);
verify(
() => codePushClient.createPatchArtifact(
artifactPath: partchArtifactBundle.path,
@@ -621,16 +692,13 @@ void main() {
hash: partchArtifactBundle.hash,
),
).called(1);
verify(() => codePushClient.getChannels(appId: appId)).called(1);
verifyNever(
() => codePushClient.createChannel(
appId: any(named: 'appId'),
channel: any(named: 'channel'),
),
);
verify(
() => codePushClient.promotePatch(
patchId: patchId,
@@ -640,8 +708,9 @@ void main() {
});
test('creates channel if none exists', () async {
when(() => codePushClient.getChannels(appId: any(named: 'appId')))
.thenAnswer((_) async => []);
when(
() => codePushClient.getChannels(appId: any(named: 'appId')),
).thenAnswer((_) async => []);
when(
() => codePushClient.createChannel(
@@ -650,16 +719,19 @@ void main() {
),
).thenAnswer((_) async => channel);
await codePushClientWrapper.publishPatch(
appId: appId,
releaseId: releaseId,
platform: platform,
channelName: channelName,
patchArtifactBundles: patchArtifactBundles,
await runWithOverrides(
() => codePushClientWrapper.publishPatch(
appId: appId,
releaseId: releaseId,
platform: platform,
channelName: channelName,
patchArtifactBundles: patchArtifactBundles,
),
);
verify(() => codePushClient.createPatch(releaseId: releaseId))
.called(1);
verify(
() => codePushClient.createPatch(releaseId: releaseId),
).called(1);
verify(
() => codePushClient.createPatchArtifact(
artifactPath: partchArtifactBundle.path,
@@ -669,16 +741,13 @@ void main() {
hash: partchArtifactBundle.hash,
),
).called(1);
verify(() => codePushClient.getChannels(appId: appId)).called(1);
verify(
() => codePushClient.createChannel(
appId: appId,
channel: channelName,
),
).called(1);
verify(
() => codePushClient.promotePatch(
patchId: patchId,
@@ -1,8 +1,9 @@
import 'package:args/command_runner.dart';
import 'package:cli_completion/cli_completion.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/command_runner.dart';
import 'package:shorebird_cli/src/logger.dart' hide logger;
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:shorebird_cli/src/version.dart';
@@ -18,20 +19,23 @@ void main() {
late ShorebirdProcessResult processResult;
late ShorebirdCliCommandRunner commandRunner;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
ShorebirdCliCommandRunner buildRunner() {
return runScoped(
ShorebirdCliCommandRunner.new,
values: {loggerRef.overrideWith(() => logger)},
);
}
setUp(() {
logger = _MockLogger();
ShorebirdEnvironment.shorebirdEngineRevision = 'test-revision';
processResult = _MockProcessResult();
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
commandRunner = ShorebirdCliCommandRunner(logger: logger);
});
test('can be instantiated without an explicit analytics/logger instance',
() {
final commandRunner = ShorebirdCliCommandRunner();
expect(commandRunner, isNotNull);
expect(commandRunner, isA<CompletionCommandRunner<int>>());
commandRunner = buildRunner();
});
test('handles FormatException', () async {
@@ -43,7 +47,9 @@ void main() {
throw exception;
}
});
final result = await commandRunner.run(['--version']);
final result = await runWithOverrides(
() => commandRunner.run(['--version']),
);
expect(result, equals(ExitCode.usage.code));
verify(() => logger.err(exception.message)).called(1);
verify(() => logger.info(commandRunner.usage)).called(1);
@@ -58,7 +64,9 @@ void main() {
throw exception;
}
});
final result = await commandRunner.run(['--version']);
final result = await runWithOverrides(
() => commandRunner.run(['--version']),
);
expect(result, equals(ExitCode.usage.code));
verify(() => logger.err(exception.message)).called(1);
verify(() => logger.info('exception usage')).called(1);
@@ -66,7 +74,9 @@ void main() {
group('--version', () {
test('outputs current version and engine revisions', () async {
final result = await commandRunner.run(['--version']);
final result = await runWithOverrides(
() => commandRunner.run(['--version']),
);
expect(result, equals(ExitCode.success.code));
verify(
() => logger.info(
@@ -80,14 +90,18 @@ Shorebird Engine • revision ${ShorebirdEnvironment.shorebirdEngineRevision}'''
group('--verbose', () {
test('enables verbose logging', () async {
final result = await commandRunner.run(['--verbose']);
final result = await runWithOverrides(
() => commandRunner.run(['--verbose']),
);
expect(result, equals(ExitCode.success.code));
});
});
group('completion', () {
test('fast tracks completion', () async {
final result = await commandRunner.run(['completion']);
final result = await runWithOverrides(
() => commandRunner.run(['completion']),
);
expect(result, equals(ExitCode.success.code));
});
});
@@ -1,8 +1,10 @@
import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/account/account.dart';
import 'package:shorebird_cli/src/logger.dart' hide logger;
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
import 'package:test/test.dart';
@@ -26,6 +28,10 @@ void main() {
late CreateAccountCommand createAccountCommand;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
auth = _MockAuth();
httpClient = _MockHttpClient();
@@ -40,10 +46,7 @@ void main() {
when(() => user.displayName).thenReturn(userName);
when(() => user.email).thenReturn(email);
createAccountCommand = CreateAccountCommand(
logger: logger,
auth: auth,
);
createAccountCommand = CreateAccountCommand(auth: auth);
});
test('has a description', () {
@@ -51,7 +54,9 @@ void main() {
});
test('login prompt is correct', () {
createAccountCommand.authPrompt('https://shorebird.dev');
runWithOverrides(
() => createAccountCommand.authPrompt('https://shorebird.dev'),
);
verify(
() => logger.info('''
Shorebird currently requires a Google account for authentication. If you'd like to use a different kind of auth, please let us know: ${lightCyan.wrap('https://github.com/shorebirdtech/shorebird/issues/335')}.
@@ -65,11 +70,12 @@ Waiting for your authorization...'''),
});
test('namePrompt asks user for name', () {
final name = createAccountCommand.namePrompt();
final name = runWithOverrides(() => createAccountCommand.namePrompt());
expect(name, userName);
verify(
() =>
logger.prompt('Tell us your name to finish creating your account:'),
() => logger.prompt(
'Tell us your name to finish creating your account:',
),
).called(1);
});
@@ -81,7 +87,7 @@ Waiting for your authorization...'''),
),
).thenThrow(UserAlreadyLoggedInException(email: email));
final result = await createAccountCommand.run();
final result = await runWithOverrides(createAccountCommand.run);
expect(result, ExitCode.success.code);
@@ -100,7 +106,7 @@ Waiting for your authorization...'''),
),
).thenThrow(UserAlreadyExistsException(user));
final result = await createAccountCommand.run();
final result = await runWithOverrides(createAccountCommand.run);
expect(result, ExitCode.success.code);
verify(
@@ -116,7 +122,7 @@ Waiting for your authorization...'''),
),
).thenThrow(Exception('login failed'));
final result = await createAccountCommand.run();
final result = await runWithOverrides(createAccountCommand.run);
expect(result, ExitCode.software.code);
verify(() => logger.err(any(that: contains('login failed')))).called(1);
@@ -131,7 +137,7 @@ Waiting for your authorization...'''),
),
).thenAnswer((_) async => user);
final result = await createAccountCommand.run();
final result = await runWithOverrides(createAccountCommand.run);
expect(result, ExitCode.success.code);
verify(
@@ -1,8 +1,10 @@
import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/account/account.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
import 'package:test/test.dart';
@@ -31,6 +33,10 @@ void main() {
late SubscribeAccountCommand subscribeAccountCommand;
group(SubscribeAccountCommand, () {
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
auth = _MockAuth();
codePushClient = _MockCodePushClient();
@@ -53,7 +59,6 @@ void main() {
when(() => user.hasActiveSubscription).thenReturn(false);
subscribeAccountCommand = SubscribeAccountCommand(
logger: logger,
auth: auth,
buildCodePushClient: ({required httpClient, hostedUri}) =>
codePushClient,
@@ -74,7 +79,7 @@ void main() {
test('exits with code 67 when user is not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
final result = await subscribeAccountCommand.run();
final result = await runWithOverrides(subscribeAccountCommand.run);
expect(result, ExitCode.noUser.code);
@@ -89,7 +94,7 @@ void main() {
when(() => codePushClient.getCurrentUser())
.thenThrow(Exception('oh no!'));
final result = await subscribeAccountCommand.run();
final result = await runWithOverrides(subscribeAccountCommand.run);
expect(result, ExitCode.software.code);
verify(() => progress.fail(any(that: contains('oh no!')))).called(1);
@@ -99,7 +104,7 @@ void main() {
test('exits with code 70 when getCurrentUser returns null', () async {
when(() => codePushClient.getCurrentUser()).thenAnswer((_) async => null);
final result = await subscribeAccountCommand.run();
final result = await runWithOverrides(subscribeAccountCommand.run);
expect(result, ExitCode.software.code);
verify(
@@ -118,7 +123,7 @@ void main() {
'exits with code 0 and prints message and exits if user already has '
'an active subscription', () async {
when(() => user.hasActiveSubscription).thenReturn(true);
final result = await subscribeAccountCommand.run();
final result = await runWithOverrides(subscribeAccountCommand.run);
expect(result, ExitCode.success.code);
verify(
@@ -135,7 +140,7 @@ void main() {
when(() => codePushClient.createPaymentLink())
.thenThrow(Exception(errorMessage));
final result = await subscribeAccountCommand.run();
final result = await runWithOverrides(subscribeAccountCommand.run);
expect(result, ExitCode.software.code);
verify(() => codePushClient.createPaymentLink()).called(1);
@@ -143,7 +148,7 @@ void main() {
});
test('exits with code 0 and prints payment link', () async {
final result = await subscribeAccountCommand.run();
final result = await runWithOverrides(subscribeAccountCommand.run);
expect(result, ExitCode.success.code);
verify(() => progress.complete('Link generated!')).called(1);
@@ -2,8 +2,10 @@ import 'package:args/args.dart';
import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
import 'package:test/test.dart';
@@ -29,6 +31,10 @@ void main() {
late CodePushClient codePushClient;
late CreateAppCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
argResults = _MockArgResults();
httpClient = _MockHttpClient();
@@ -47,7 +53,6 @@ void main() {
}) {
return codePushClient;
},
logger: logger,
)..testArgResults = argResults;
});
@@ -57,7 +62,7 @@ void main() {
test('returns no user error when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.noUser.code);
});
@@ -65,7 +70,7 @@ void main() {
when(
() => logger.prompt(any(), defaultValue: any(named: 'defaultValue')),
).thenReturn(displayName);
await command.run();
await runWithOverrides(command.run);
verify(
() => logger.prompt(any(), defaultValue: any(named: 'defaultValue')),
).called(1);
@@ -76,7 +81,7 @@ void main() {
test('uses provided app name when provided', () async {
when(() => argResults['app-name']).thenReturn(displayName);
await command.run();
await runWithOverrides(command.run);
verifyNever(() => logger.prompt(any()));
verify(
() => codePushClient.createApp(displayName: displayName),
@@ -88,7 +93,7 @@ void main() {
when(
() => codePushClient.createApp(displayName: displayName),
).thenAnswer((_) async => const App(id: appId, displayName: displayName));
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.success.code);
});
@@ -98,7 +103,7 @@ void main() {
when(
() => codePushClient.createApp(displayName: displayName),
).thenThrow(error);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.software.code);
verify(() => logger.err('$error')).called(1);
});
@@ -2,8 +2,10 @@ import 'package:args/args.dart';
import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
import 'package:test/test.dart';
@@ -28,6 +30,10 @@ void main() {
late CodePushClient codePushClient;
late DeleteAppCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
argResults = _MockArgResults();
httpClient = _MockHttpClient();
@@ -46,7 +52,6 @@ void main() {
}) {
return codePushClient;
},
logger: logger,
)..testArgResults = argResults;
});
@@ -59,28 +64,28 @@ void main() {
test('returns no user error when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.noUser.code);
});
test('prompts for app-id when not provided', () async {
when(() => logger.confirm(any())).thenReturn(false);
when(() => logger.prompt(any())).thenReturn(appId);
await command.run();
await runWithOverrides(command.run);
verify(() => logger.prompt(any())).called(1);
});
test('uses provided app-id when provided', () async {
when(() => logger.confirm(any())).thenReturn(false);
when(() => argResults['app-id']).thenReturn(appId);
await command.run();
await runWithOverrides(command.run);
verifyNever(() => logger.prompt(any()));
});
test('aborts when user does not confirm', () async {
when(() => logger.confirm(any())).thenReturn(false);
when(() => argResults['app-id']).thenReturn(appId);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.success.code);
verifyNever(() => codePushClient.deleteApp(appId: appId));
verify(() => logger.info('Aborted.')).called(1);
@@ -92,7 +97,7 @@ void main() {
when(
() => codePushClient.deleteApp(appId: appId),
).thenAnswer((_) async {});
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.success.code);
});
@@ -101,7 +106,7 @@ void main() {
when(() => logger.confirm(any())).thenReturn(true);
when(() => argResults['app-id']).thenReturn(appId);
when(() => codePushClient.deleteApp(appId: appId)).thenThrow(error);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.software.code);
verify(() => logger.err('$error')).called(1);
});
@@ -1,8 +1,10 @@
import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
import 'package:test/test.dart';
@@ -20,9 +22,12 @@ void main() {
late Auth auth;
late CodePushClient codePushClient;
late Logger logger;
late ListAppsCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
httpClient = _MockHttpClient();
auth = _MockAuth();
@@ -40,7 +45,6 @@ void main() {
}) {
return codePushClient;
},
logger: logger,
);
});
@@ -50,17 +54,17 @@ void main() {
test('returns ExitCode.noUser when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
expect(await command.run(), ExitCode.noUser.code);
expect(await runWithOverrides(command.run), ExitCode.noUser.code);
});
test('returns ExitCode.software when unable to get apps', () async {
when(() => codePushClient.getApps()).thenThrow(Exception());
expect(await command.run(), ExitCode.software.code);
expect(await runWithOverrides(command.run), ExitCode.software.code);
});
test('returns ExitCode.success when apps are empty', () async {
when(() => codePushClient.getApps()).thenAnswer((_) async => []);
expect(await command.run(), ExitCode.success.code);
expect(await runWithOverrides(command.run), ExitCode.success.code);
verify(() => logger.info('(empty)')).called(1);
});
@@ -78,7 +82,7 @@ void main() {
),
];
when(() => codePushClient.getApps()).thenAnswer((_) async => apps);
expect(await command.run(), ExitCode.success.code);
expect(await runWithOverrides(command.run), ExitCode.success.code);
verify(
() => logger.info(
'''
@@ -5,8 +5,10 @@ import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/build/build.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:test/test.dart';
@@ -59,9 +61,12 @@ flutter:
late Progress progress;
late ShorebirdProcess shorebirdProcess;
late ShorebirdProcessResult processResult;
late BuildAarCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
Directory setUpTempDir({bool includeModule = true}) {
final tempDir = Directory.systemTemp.createTempSync();
File(
@@ -100,11 +105,7 @@ flutter:
return processResult;
});
command = BuildAarCommand(
auth: auth,
logger: logger,
validators: [],
)
command = BuildAarCommand(auth: auth, validators: [])
..testArgResults = argResults
..testProcess = shorebirdProcess
..testEngineConfig = const EngineConfig.empty();
@@ -117,7 +118,7 @@ flutter:
test('exits with no user when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.noUser.code));
verify(
@@ -128,7 +129,7 @@ flutter:
test('exits with 78 if no pubspec.yaml exists', () async {
final tempDir = Directory.systemTemp.createTempSync();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -138,7 +139,7 @@ flutter:
test('exits with 78 if no module entry exists in pubspec.yaml', () async {
final tempDir = setUpTempDir(includeModule: false);
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -151,7 +152,7 @@ flutter:
final tempDir = setUpTempDir();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -169,15 +170,16 @@ flutter:
runInShell: any(named: 'runInShell'),
),
).called(1);
verify(() => progress.fail(any(that: contains('Failed to build'))))
.called(1);
verify(
() => progress.fail(any(that: contains('Failed to build'))),
).called(1);
});
test('exits with code 0 when building aar succeeds', () async {
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
final tempDir = setUpTempDir();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -227,7 +229,7 @@ ${lightCyan.wrap(
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
final tempDir = setUpTempDir();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -5,8 +5,10 @@ import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/build/build.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
import 'package:test/test.dart';
@@ -39,6 +41,10 @@ void main() {
late ShorebirdFlutterValidator flutterValidator;
late ShorebirdProcess shorebirdProcess;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
argResults = _MockArgResults();
httpClient = _MockHttpClient();
@@ -66,7 +72,6 @@ void main() {
command = BuildApkCommand(
auth: auth,
logger: logger,
validators: [flutterValidator],
)
..testArgResults = argResults
@@ -81,7 +86,7 @@ void main() {
test('exits with no user when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.noUser.code));
verify(
@@ -95,7 +100,7 @@ void main() {
final tempDir = Directory.systemTemp.createTempSync();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -113,7 +118,7 @@ void main() {
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
final tempDir = Directory.systemTemp.createTempSync();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -145,7 +150,7 @@ ${lightCyan.wrap(p.join('build', 'app', 'outputs', 'apk', 'release', 'app-releas
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
final tempDir = Directory.systemTemp.createTempSync();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -188,7 +193,7 @@ ${lightCyan.wrap(p.join('build', 'app', 'outputs', 'apk', flavor, 'release', 'ap
);
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.success.code));
verify(
@@ -210,7 +215,7 @@ ${lightCyan.wrap(p.join('build', 'app', 'outputs', 'apk', flavor, 'release', 'ap
],
);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.config.code));
verify(() => logger.err('Aborting due to validation errors.')).called(1);
@@ -5,8 +5,10 @@ import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/build/build.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
import 'package:test/test.dart';
@@ -39,6 +41,10 @@ void main() {
late ShorebirdFlutterValidator flutterValidator;
late ShorebirdProcess shorebirdProcess;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
argResults = _MockArgResults();
httpClient = _MockHttpClient();
@@ -66,7 +72,6 @@ void main() {
command = BuildAppBundleCommand(
auth: auth,
logger: logger,
validators: [flutterValidator],
)
..testArgResults = argResults
@@ -81,7 +86,7 @@ void main() {
test('exits with no user when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.noUser.code));
verify(
@@ -95,7 +100,7 @@ void main() {
final tempDir = Directory.systemTemp.createTempSync();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -113,7 +118,7 @@ void main() {
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
final tempDir = Directory.systemTemp.createTempSync();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -145,7 +150,7 @@ ${lightCyan.wrap(p.join('build', 'app', 'outputs', 'bundle', 'release', 'app-rel
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
final tempDir = Directory.systemTemp.createTempSync();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -205,7 +210,7 @@ ${lightCyan.wrap(p.join('build', 'app', 'outputs', 'bundle', '${flavor}Release',
);
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.success.code));
verify(
@@ -226,7 +231,7 @@ ${lightCyan.wrap(p.join('build', 'app', 'outputs', 'bundle', '${flavor}Release',
],
);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.config.code));
verify(() => logger.err('Aborting due to validation errors.')).called(1);
@@ -1,18 +1,12 @@
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:shorebird_cli/src/commands/build/build.dart';
import 'package:test/test.dart';
class _MockLogger extends Mock implements Logger {}
void main() {
group('build', () {
late Logger logger;
late BuildCommand command;
setUp(() {
logger = _MockLogger();
command = BuildCommand(logger: logger);
command = BuildCommand();
});
test('has a description', () async {
@@ -5,8 +5,10 @@ import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/build/build.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
import 'package:test/test.dart';
@@ -39,6 +41,10 @@ void main() {
late ShorebirdFlutterValidator flutterValidator;
late ShorebirdProcess shorebirdProcess;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
argResults = _MockArgResults();
httpClient = _MockHttpClient();
@@ -67,7 +73,6 @@ void main() {
command = BuildIpaCommand(
auth: auth,
logger: logger,
validators: [flutterValidator],
)
..testArgResults = argResults
@@ -82,7 +87,7 @@ void main() {
test('exits with no user when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.noUser.code));
verify(
@@ -96,7 +101,7 @@ void main() {
final tempDir = Directory.systemTemp.createTempSync();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -114,7 +119,7 @@ void main() {
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
final tempDir = Directory.systemTemp.createTempSync();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -152,7 +157,7 @@ ${lightCyan.wrap(p.join('build', 'ios', 'ipa', 'Runner.ipa'))}''',
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
final tempDir = Directory.systemTemp.createTempSync();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -193,7 +198,7 @@ ${lightCyan.wrap(p.join('build', 'ios', 'ipa', 'Runner.ipa'))}''',
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
final tempDir = Directory.systemTemp.createTempSync();
final result = await IOOverrides.runZoned(
() async => command.run(),
() async => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -239,7 +244,7 @@ ${lightCyan.wrap(p.join('build', 'ios', 'ipa', 'Runner.ipa'))}''',
);
when(() => processResult.exitCode).thenReturn(ExitCode.success.code);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.success.code));
verify(
@@ -261,7 +266,7 @@ ${lightCyan.wrap(p.join('build', 'ios', 'ipa', 'Runner.ipa'))}''',
],
);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.config.code));
verify(() => logger.err('Aborting due to validation errors.')).called(1);
@@ -1,18 +1,12 @@
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:shorebird_cli/src/commands/cache/cache_command.dart';
import 'package:test/test.dart';
class _MockLogger extends Mock implements Logger {}
void main() {
group('cache', () {
late Logger logger;
late CacheCommand command;
setUp(() {
logger = _MockLogger();
command = CacheCommand(logger: logger);
command = CacheCommand();
});
test('has a description', () {
@@ -1,7 +1,9 @@
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/cache.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:test/test.dart';
class _MockLogger extends Mock implements Logger {}
@@ -14,10 +16,14 @@ void main() {
late Logger logger;
late CleanCacheCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
cache = _MockCache();
logger = _MockLogger();
command = CleanCacheCommand(cache: cache, logger: logger);
command = runWithOverrides(() => CleanCacheCommand(cache: cache));
});
test('has a description', () {
@@ -25,7 +31,7 @@ void main() {
});
test('clears the cache', () async {
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.success.code));
verify(() => logger.success('✅ Cleared Cache!')).called(1);
verify(cache.clear).called(1);
@@ -2,8 +2,10 @@ import 'package:args/args.dart';
import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
import 'package:test/test.dart';
@@ -32,6 +34,10 @@ void main() {
late Progress progress;
late AddCollaboratorsCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
argResults = _MockArgResults();
httpClient = _MockHttpClient();
@@ -55,7 +61,6 @@ void main() {
}) {
return codePushClient;
},
logger: logger,
)..testArgResults = argResults;
});
@@ -72,17 +77,17 @@ void main() {
test('returns ExitCode.noUser when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
expect(await command.run(), ExitCode.noUser.code);
expect(await runWithOverrides(command.run), ExitCode.noUser.code);
});
test('returns ExitCode.usage when app id is missing.', () async {
when(() => argResults['app-id']).thenReturn(null);
expect(await command.run(), ExitCode.usage.code);
expect(await runWithOverrides(command.run), ExitCode.usage.code);
});
test('returns ExitCode.success when user aborts', () async {
when(() => logger.confirm(any())).thenReturn(false);
expect(await command.run(), ExitCode.success.code);
expect(await runWithOverrides(command.run), ExitCode.success.code);
verify(() => logger.info('Aborted.')).called(1);
verifyNever(
() => codePushClient.createCollaborator(
@@ -102,7 +107,7 @@ void main() {
email: any(named: 'email'),
),
).thenThrow(error);
expect(await command.run(), ExitCode.software.code);
expect(await runWithOverrides(command.run), ExitCode.software.code);
verify(() => logger.err(error)).called(1);
});
@@ -115,7 +120,7 @@ void main() {
email: any(named: 'email'),
),
).thenAnswer((_) async {});
expect(await command.run(), ExitCode.success.code);
expect(await runWithOverrides(command.run), ExitCode.success.code);
verify(
() => logger.prompt(
'''${lightGreen.wrap('?')} What is the email of the collaborator you would like to add?''',
@@ -133,7 +138,7 @@ void main() {
email: any(named: 'email'),
),
).thenAnswer((_) async {});
expect(await command.run(), ExitCode.success.code);
expect(await runWithOverrides(command.run), ExitCode.success.code);
verify(() => logger.success('\n✅ New Collaborator Added!')).called(1);
});
});
@@ -5,8 +5,10 @@ import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
import 'package:test/test.dart';
@@ -36,6 +38,10 @@ void main() {
late Progress progress;
late DeleteCollaboratorsCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
argResults = _MockArgResults();
httpClient = _MockHttpClient();
@@ -68,7 +74,6 @@ void main() {
}) {
return codePushClient;
},
logger: logger,
)..testArgResults = argResults;
});
@@ -81,17 +86,17 @@ void main() {
test('returns ExitCode.noUser when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
expect(await command.run(), ExitCode.noUser.code);
expect(await runWithOverrides(command.run), ExitCode.noUser.code);
});
test('returns ExitCode.usage when app id is missing.', () async {
when(() => argResults['app-id']).thenReturn(null);
expect(await command.run(), ExitCode.usage.code);
expect(await runWithOverrides(command.run), ExitCode.usage.code);
});
test('returns ExitCode.success when user aborts', () async {
when(() => logger.confirm(any())).thenReturn(false);
expect(await command.run(), ExitCode.success.code);
expect(await runWithOverrides(command.run), ExitCode.success.code);
verifyNever(
() => codePushClient.deleteCollaborator(
appId: any(named: 'appId'),
@@ -108,7 +113,7 @@ void main() {
when(
() => codePushClient.getCollaborators(appId: any(named: 'appId')),
).thenThrow(error);
expect(await command.run(), ExitCode.software.code);
expect(await runWithOverrides(command.run), ExitCode.software.code);
verify(() => logger.err(error)).called(1);
});
@@ -117,7 +122,7 @@ void main() {
when(
() => codePushClient.getCollaborators(appId: any(named: 'appId')),
).thenAnswer((_) async => []);
expect(await command.run(), ExitCode.software.code);
expect(await runWithOverrides(command.run), ExitCode.software.code);
verify(
() => logger.err(
any(
@@ -139,7 +144,7 @@ void main() {
userId: any(named: 'userId'),
),
).thenThrow(error);
expect(await command.run(), ExitCode.software.code);
expect(await runWithOverrides(command.run), ExitCode.software.code);
verify(() => logger.err(error)).called(1);
});
@@ -152,7 +157,7 @@ void main() {
userId: any(named: 'userId'),
),
).thenAnswer((_) async => collaborator);
expect(await command.run(), ExitCode.success.code);
expect(await runWithOverrides(command.run), ExitCode.success.code);
verify(
() => logger.prompt(
'''${lightGreen.wrap('?')} What is the email of the collaborator you would like to delete?''',
@@ -179,7 +184,7 @@ void main() {
),
).thenAnswer((_) async {});
final result = await IOOverrides.runZoned(
() => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(result, ExitCode.success.code);
@@ -199,7 +204,7 @@ void main() {
userId: any(named: 'userId'),
),
).thenAnswer((_) async {});
expect(await command.run(), ExitCode.success.code);
expect(await runWithOverrides(command.run), ExitCode.success.code);
verify(() => logger.success('\n✅ Collaborator Deleted!')).called(1);
});
});
@@ -2,8 +2,10 @@ import 'package:args/args.dart';
import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
import 'package:test/test.dart';
@@ -28,6 +30,10 @@ void main() {
late Logger logger;
late ListCollaboratorsCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
argResults = _MockArgResults();
httpClient = _MockHttpClient();
@@ -47,7 +53,6 @@ void main() {
}) {
return codePushClient;
},
logger: logger,
)..testArgResults = argResults;
});
@@ -68,12 +73,12 @@ void main() {
test('returns ExitCode.noUser when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
expect(await command.run(), ExitCode.noUser.code);
expect(await runWithOverrides(command.run), ExitCode.noUser.code);
});
test('returns ExitCode.usage when app id is missing.', () async {
when(() => argResults['app-id']).thenReturn(null);
expect(await command.run(), ExitCode.usage.code);
expect(await runWithOverrides(command.run), ExitCode.usage.code);
});
test('returns ExitCode.software when unable to get collaborators',
@@ -81,14 +86,14 @@ void main() {
when(
() => codePushClient.getCollaborators(appId: any(named: 'appId')),
).thenThrow(Exception());
expect(await command.run(), ExitCode.software.code);
expect(await runWithOverrides(command.run), ExitCode.software.code);
});
test('returns ExitCode.success when collaborators are empty', () async {
when(
() => codePushClient.getCollaborators(appId: any(named: 'appId')),
).thenAnswer((_) async => []);
expect(await command.run(), ExitCode.success.code);
expect(await runWithOverrides(command.run), ExitCode.success.code);
verify(() => logger.info('(empty)')).called(1);
});
@@ -100,7 +105,7 @@ void main() {
when(
() => codePushClient.getCollaborators(appId: any(named: 'appId')),
).thenAnswer((_) async => collaborators);
expect(await command.run(), ExitCode.success.code);
expect(await runWithOverrides(command.run), ExitCode.success.code);
verify(
() => logger.info(
'''
@@ -1,23 +0,0 @@
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:test/test.dart';
void main() {
group(ShorebirdCommand, () {
test('passes logger to auth in default builder', () {
final logger = Logger();
final command = TestCommand(logger: logger);
expect(command.auth.logger, logger);
});
});
}
class TestCommand extends ShorebirdCommand {
TestCommand({required super.logger});
@override
String get description => 'A test command';
@override
String get name => 'test';
}
@@ -1,7 +1,9 @@
import 'package:args/args.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
@@ -37,6 +39,10 @@ void main() {
late ShorebirdFlutterValidator shorebirdFlutterValidator;
late ShorebirdProcess shorebirdProcess;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
argResults = _MockArgResults();
logger = _MockLogger();
@@ -77,13 +83,14 @@ void main() {
when(() => shorebirdFlutterValidator.validate(any()))
.thenAnswer((_) async => []);
command = DoctorCommand(
logger: logger,
validators: [
androidInternetPermissionValidator,
shorebirdVersionValidator,
shorebirdFlutterValidator,
],
command = runWithOverrides(
() => DoctorCommand(
validators: [
androidInternetPermissionValidator,
shorebirdVersionValidator,
shorebirdFlutterValidator,
],
),
)
..testArgResults = argResults
..testProcess = shorebirdProcess
@@ -91,7 +98,7 @@ void main() {
});
test('prints "no issues" when everything is OK', () async {
await command.run();
await runWithOverrides(command.run);
for (final validator in command.validators) {
verify(() => validator.validate(shorebirdProcess)).called(1);
}
@@ -116,7 +123,7 @@ void main() {
],
);
await command.run();
await runWithOverrides(command.run);
for (final validator in command.validators) {
verify(() => validator.validate(any())).called(1);
@@ -148,7 +155,7 @@ void main() {
],
);
await command.run();
await runWithOverrides(command.run);
verify(
() => logger.info(
@@ -174,7 +181,7 @@ void main() {
],
);
await command.run();
await runWithOverrides(command.run);
verifyNever(
() => logger.info(
@@ -204,7 +211,7 @@ void main() {
],
);
await command.run();
await runWithOverrides(command.run);
expect(fixCalled, isFalse);
verifyNever(() => progress.update('Fixing'));
@@ -234,7 +241,7 @@ void main() {
},
);
await command.run();
await runWithOverrides(command.run);
expect(fixCalled, isTrue);
verify(() => progress.update('Fixing')).called(1);
@@ -262,7 +269,7 @@ void main() {
],
);
await command.run();
await runWithOverrides(command.run);
expect(fixCalled, isTrue);
verify(() => progress.update('Fixing')).called(1);
@@ -292,7 +299,7 @@ void main() {
],
);
await command.run();
await runWithOverrides(command.run);
verify(() => progress.update('Fixing')).called(1);
verify(
@@ -6,8 +6,10 @@ import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:platform/platform.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/init_command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
import 'package:test/test.dart';
@@ -53,6 +55,10 @@ environment:
late Progress progress;
late InitCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
Directory setUpAppTempDir() {
final tempDir = Directory.systemTemp.createTempSync();
Directory(p.join(tempDir.path, 'android')).createSync(recursive: true);
@@ -75,7 +81,6 @@ environment:
logger = _MockLogger();
progress = _MockProgress();
// when(() => argResults['force']).thenReturn(false);
when(() => auth.isAuthenticated).thenReturn(true);
when(() => auth.client).thenReturn(httpClient);
when(
@@ -109,7 +114,6 @@ environment:
}) {
return codePushClient;
},
logger: logger,
)
..testProcess = process
..testArgResults = argResults;
@@ -264,14 +268,14 @@ environment:
test('returns no user error when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.noUser.code);
});
test('throws no input error when pubspec.yaml is not found.', () async {
final tempDir = Directory.systemTemp.createTempSync();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -289,7 +293,7 @@ Please make sure you are running "shorebird init" from the root of your Flutter
final tempDir = Directory.systemTemp.createTempSync();
File(p.join(tempDir.path, 'pubspec.yaml')).createSync();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -307,7 +311,7 @@ Please make sure you are running "shorebird init" from the root of your Flutter
).writeAsStringSync(pubspecYamlContent);
File(p.join(tempDir.path, 'shorebird.yaml')).createSync();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -328,7 +332,7 @@ If you want to reinitialize Shorebird, please run "shorebird init --force".''',
).writeAsStringSync(pubspecYamlContent);
File(p.join(tempDir.path, 'shorebird.yaml')).createSync();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verifyNever(
@@ -356,7 +360,7 @@ If you want to reinitialize Shorebird, please run "shorebird init --force".''',
p.join(tempDir.path, 'pubspec.yaml'),
).writeAsStringSync(pubspecYamlContent);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => logger.progress('Detecting product flavors')).called(1);
@@ -380,7 +384,7 @@ If you want to reinitialize Shorebird, please run "shorebird init --force".''',
() => codePushClient.createApp(displayName: any(named: 'displayName')),
).thenThrow(error);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -396,7 +400,7 @@ If you want to reinitialize Shorebird, please run "shorebird init --force".''',
p.join(tempDir.path, 'pubspec.yaml'),
).writeAsStringSync(pubspecYamlContent);
await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(
@@ -431,7 +435,7 @@ If you want to reinitialize Shorebird, please run "shorebird init --force".''',
p.join(tempDir.path, 'pubspec.yaml'),
).writeAsStringSync(pubspecYamlContent);
await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(
@@ -465,7 +469,7 @@ flutter:
- shorebird.yaml
''');
await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(
@@ -480,7 +484,7 @@ flutter:
p.join(tempDir.path, 'pubspec.yaml'),
).writeAsStringSync(pubspecYamlContent);
await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(
@@ -502,7 +506,7 @@ flutter:
uses-material-design: true
''');
await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(
@@ -526,7 +530,7 @@ flutter:
- some/asset.txt
''');
await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(
@@ -4,8 +4,10 @@ import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/login_command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:test/test.dart';
class _MockAuth extends Mock implements Auth {}
@@ -22,7 +24,11 @@ void main() {
late http.Client httpClient;
late Directory applicationConfigHome;
late Logger logger;
late LoginCommand loginCommand;
late LoginCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
applicationConfigHome = Directory.systemTemp.createTempSync();
@@ -35,14 +41,15 @@ void main() {
p.join(applicationConfigHome.path, 'credentials.json'),
);
loginCommand = LoginCommand(auth: auth, logger: logger);
command = LoginCommand(auth: auth);
});
test('exits with code 0 when already logged in', () async {
when(() => auth.login(any()))
.thenThrow(UserAlreadyLoggedInException(email: email));
when(
() => auth.login(any()),
).thenThrow(UserAlreadyLoggedInException(email: email));
final result = await loginCommand.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.success.code));
verify(
@@ -56,10 +63,11 @@ void main() {
});
test('exits with code 70 if no user is found', () async {
when(() => auth.login(any()))
.thenThrow(UserNotFoundException(email: email));
when(
() => auth.login(any()),
).thenThrow(UserNotFoundException(email: email));
final result = await loginCommand.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.software.code));
verify(
@@ -74,7 +82,7 @@ void main() {
final error = Exception('oops something went wrong!');
when(() => auth.login(any())).thenThrow(error);
final result = await loginCommand.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.software.code));
verify(() => auth.login(any())).called(1);
@@ -85,7 +93,7 @@ void main() {
when(() => auth.login(any())).thenAnswer((_) async {});
when(() => auth.email).thenReturn(email);
final result = await loginCommand.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.success.code));
verify(() => auth.login(any())).called(1);
@@ -98,7 +106,7 @@ void main() {
test('prompt is correct', () {
const url = 'http://example.com';
loginCommand.prompt(url);
runWithOverrides(() => command.prompt(url));
verify(
() => logger.info('''
@@ -1,8 +1,10 @@
import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/logout_command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:test/test.dart';
class _MockAuth extends Mock implements Auth {}
@@ -18,7 +20,11 @@ void main() {
late Auth auth;
late Logger logger;
late http.Client httpClient;
late LogoutCommand logoutCommand;
late LogoutCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
auth = _MockAuth();
@@ -28,12 +34,12 @@ void main() {
when(() => auth.client).thenReturn(httpClient);
when(() => logger.progress(any())).thenReturn(_MockProgress());
logoutCommand = LogoutCommand(auth: auth, logger: logger);
command = LogoutCommand(auth: auth);
});
test('exits with code 0 when already logged out', () async {
when(() => auth.isAuthenticated).thenReturn(false);
final result = await logoutCommand.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.success.code));
verify(
@@ -48,7 +54,7 @@ void main() {
when(() => progress.complete(any())).thenAnswer((invocation) {});
when(() => logger.progress(any())).thenReturn(progress);
final result = await logoutCommand.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.success.code));
verify(() => logger.progress('Logging out of shorebird.dev')).called(1);
@@ -6,10 +6,12 @@ import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:platform/platform.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/archive_analysis/archive_analysis.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/cache.dart' show Cache;
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
@@ -137,6 +139,10 @@ flutter:
late ShorebirdFlutterValidator flutterValidator;
late ShorebirdProcess shorebirdProcess;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
Directory setUpTempDir({bool includeModule = true}) {
final tempDir = Directory.systemTemp.createTempSync();
File(
@@ -333,7 +339,6 @@ flutter:
return codePushClient;
},
cache: cache,
logger: logger,
httpClient: httpClient,
validators: [flutterValidator],
unzipFn: (_, __) async {},
@@ -346,7 +351,7 @@ flutter:
test('throws config error when shorebird is not initialized', () async {
final tempDir = Directory.systemTemp.createTempSync();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -365,7 +370,7 @@ flutter:
when(() => auth.isAuthenticated).thenReturn(false);
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
() => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.noUser.code));
@@ -375,7 +380,7 @@ flutter:
final tempDir = setUpTempDir(includeModule: false);
final result = await IOOverrides.runZoned(
() async => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -388,7 +393,7 @@ flutter:
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
() async => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -402,7 +407,7 @@ flutter:
when(() => argResults['force']).thenReturn(true);
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.usage.code));
@@ -414,7 +419,7 @@ flutter:
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -429,7 +434,7 @@ flutter:
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -449,7 +454,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -468,7 +473,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -506,7 +511,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -520,7 +525,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -548,7 +553,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -566,7 +571,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -594,7 +599,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -625,7 +630,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -640,7 +645,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -667,7 +672,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -697,7 +702,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -715,7 +720,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -729,7 +734,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.success.code));
@@ -744,7 +749,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.success.code);
@@ -756,7 +761,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.success.code));
@@ -774,7 +779,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -795,7 +800,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -810,7 +815,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -831,7 +836,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -852,7 +857,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -863,7 +868,7 @@ Please create a release using "shorebird release aar" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -892,7 +897,7 @@ flavors:
development: $appId''');
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => logger.success('\n✅ Published Patch!')).called(1);
@@ -912,7 +917,7 @@ app_id: $appId
base_url: $baseUrl''',
);
await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(capturedHostedUri, equals(Uri.parse(baseUrl)));
@@ -935,7 +940,7 @@ base_url: $baseUrl''',
);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -961,7 +966,7 @@ base_url: $baseUrl''',
);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -6,11 +6,13 @@ import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:platform/platform.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/archive_analysis/archive_analysis.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/cache.dart' show Cache;
import 'package:shorebird_cli/src/code_push_client_wrapper.dart';
import 'package:shorebird_cli/src/commands/patch/patch_android_command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
@@ -114,6 +116,10 @@ flutter:
late ShorebirdFlutterValidator flutterValidator;
late ShorebirdProcess shorebirdProcess;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
Directory setUpTempDir() {
final tempDir = Directory.systemTemp.createTempSync();
File(
@@ -172,7 +178,6 @@ flutter:
auth: auth,
codePushClientWrapper: codePushClientWrapper,
cache: cache,
logger: logger,
httpClient: httpClient,
validators: [flutterValidator],
)
@@ -323,7 +328,7 @@ flutter:
test('throws config error when shorebird is not initialized', () async {
final tempDir = Directory.systemTemp.createTempSync();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -342,7 +347,7 @@ flutter:
when(() => auth.isAuthenticated).thenReturn(false);
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
() => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.noUser.code));
@@ -354,7 +359,7 @@ flutter:
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
() async => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -368,7 +373,7 @@ flutter:
when(() => argResults['force']).thenReturn(true);
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.usage.code));
@@ -379,7 +384,7 @@ flutter:
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.success.code);
@@ -393,7 +398,7 @@ flutter:
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -412,7 +417,7 @@ flutter:
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -449,7 +454,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -467,7 +472,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -489,7 +494,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -522,7 +527,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -537,7 +542,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -557,7 +562,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -584,7 +589,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -619,7 +624,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -643,7 +648,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -657,7 +662,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.success.code));
@@ -678,7 +683,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.success.code));
@@ -698,7 +703,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -731,7 +736,7 @@ flavors:
development: $appId''');
setUpTempArtifacts(tempDir, flavor: flavor);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => logger.success('\n✅ Published Patch!')).called(1);
@@ -755,7 +760,7 @@ flavors:
);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -781,7 +786,7 @@ flavors:
);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -5,9 +5,11 @@ import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/archive_analysis/archive_analysis.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/patch/patch.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
@@ -96,9 +98,12 @@ flutter:
late Uri? capturedHostedUri;
late ShorebirdFlutterValidator flutterValidator;
late ShorebirdProcess shorebirdProcess;
late PatchIosCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
Directory setUpTempDir() {
final tempDir = Directory.systemTemp.createTempSync();
File(
@@ -226,7 +231,6 @@ flutter:
command = PatchIosCommand(
auth: auth,
ipaReader: ipaReader,
logger: logger,
validators: [flutterValidator],
buildCodePushClient: ({
required http.Client httpClient,
@@ -249,7 +253,7 @@ flutter:
when(() => auth.isAuthenticated).thenReturn(false);
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
() => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.noUser.code));
@@ -261,7 +265,7 @@ flutter:
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
() async => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -275,7 +279,7 @@ flutter:
when(() => argResults['force']).thenReturn(true);
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.usage.code));
@@ -287,7 +291,7 @@ flutter:
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -302,7 +306,7 @@ flutter:
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -320,7 +324,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.success.code);
@@ -334,7 +338,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -353,7 +357,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -391,7 +395,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -405,7 +409,7 @@ https://github.com/shorebirdtech/shorebird/issues/472
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -428,14 +432,15 @@ Please create a release using "shorebird release" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
() async => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.software.code));
verify(
() => progress
.fail(any(that: contains('Failed to determine release version'))),
() => progress.fail(
any(that: contains('Failed to determine release version')),
),
).called(1);
});
@@ -446,7 +451,7 @@ Please create a release using "shorebird release" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -460,7 +465,7 @@ Please create a release using "shorebird release" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.success.code));
@@ -475,7 +480,7 @@ Please create a release using "shorebird release" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.success.code));
@@ -493,7 +498,7 @@ Please create a release using "shorebird release" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -514,7 +519,7 @@ Please create a release using "shorebird release" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -529,7 +534,7 @@ Please create a release using "shorebird release" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -550,7 +555,7 @@ Please create a release using "shorebird release" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -571,7 +576,7 @@ Please create a release using "shorebird release" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -582,7 +587,7 @@ Please create a release using "shorebird release" and try again.
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -615,7 +620,7 @@ flavors:
development: $appId''');
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => logger.success('\n✅ Published Patch!')).called(1);
@@ -635,7 +640,7 @@ app_id: $appId
base_url: $baseUrl''',
);
await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(capturedHostedUri, equals(Uri.parse(baseUrl)));
@@ -658,7 +663,7 @@ base_url: $baseUrl''',
);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -684,7 +689,7 @@ base_url: $baseUrl''',
);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -5,8 +5,10 @@ import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
@@ -101,6 +103,10 @@ flutter:
late ShorebirdFlutterValidator flutterValidator;
late ShorebirdProcess shorebirdProcess;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
Directory setUpTempDir({bool includeModule = true}) {
final tempDir = Directory.systemTemp.createTempSync();
File(
@@ -226,7 +232,6 @@ flutter:
return codePushClient;
},
unzipFn: (_, __) async {},
logger: logger,
validators: [flutterValidator],
)
..testArgResults = argResults
@@ -242,7 +247,7 @@ flutter:
final tempDir = Directory.systemTemp.createTempSync();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -259,7 +264,7 @@ flutter:
final tempDir = setUpTempDir(includeModule: false);
final result = await IOOverrides.runZoned(
() async => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -273,7 +278,7 @@ flutter:
final tempDir = Directory.systemTemp.createTempSync();
final result = await IOOverrides.runZoned(
() async => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -284,7 +289,7 @@ flutter:
final tempDir = setUpTempDir(includeModule: false);
final result = await IOOverrides.runZoned(
() async => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -297,7 +302,7 @@ flutter:
final tempDir = setUpTempDir();
final result = await IOOverrides.runZoned(
() async => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -325,7 +330,7 @@ flutter:
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -340,7 +345,7 @@ flutter:
when(() => codePushClient.getApps()).thenAnswer((_) async => []);
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -364,7 +369,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
// setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.success.code);
@@ -378,7 +383,7 @@ Did you forget to run "shorebird init"?''',
).thenThrow(error);
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -395,7 +400,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
// setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -420,9 +425,8 @@ Did you forget to run "shorebird init"?''',
),
).thenThrow(error);
final tempDir = setUpTempDir();
// setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -448,7 +452,7 @@ Did you forget to run "shorebird init"?''',
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -486,7 +490,7 @@ Did you forget to run "shorebird init"?''',
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -524,7 +528,7 @@ Did you forget to run "shorebird init"?''',
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -560,7 +564,7 @@ Did you forget to run "shorebird init"?''',
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -582,7 +586,7 @@ Did you forget to run "shorebird init"?''',
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -598,7 +602,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => logger.success('\n✅ Published Release!')).called(1);
@@ -629,7 +633,7 @@ flavors:
development: $appId''');
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => logger.success('\n✅ Published Release!')).called(1);
@@ -663,7 +667,7 @@ flavors:
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -691,7 +695,7 @@ flavors:
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.config.code));
@@ -6,9 +6,11 @@ import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:platform/platform.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/cache.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
@@ -95,6 +97,10 @@ flutter:
late ShorebirdFlutterValidator flutterValidator;
late ShorebirdProcess shorebirdProcess;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
Directory setUpTempDir() {
final tempDir = Directory.systemTemp.createTempSync();
File(
@@ -258,7 +264,6 @@ flutter:
return codePushClient;
},
cache: cache,
logger: logger,
validators: [flutterValidator],
)
..testArgResults = argResults
@@ -273,7 +278,7 @@ flutter:
test('throws config error when shorebird is not initialized', () async {
final tempDir = Directory.systemTemp.createTempSync();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -288,7 +293,7 @@ flutter:
when(() => auth.isAuthenticated).thenReturn(false);
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
() => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.noUser.code));
@@ -300,7 +305,7 @@ flutter:
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
() async => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -314,7 +319,7 @@ flutter:
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -329,7 +334,7 @@ flutter:
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -368,7 +373,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -386,7 +391,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -408,7 +413,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.success.code);
@@ -423,7 +428,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -437,7 +442,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -455,7 +460,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -479,7 +484,7 @@ Please bump your version number and try again.'''),
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -501,7 +506,7 @@ Please bump your version number and try again.'''),
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -528,7 +533,7 @@ Please bump your version number and try again.'''),
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -554,7 +559,7 @@ Please bump your version number and try again.'''),
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -578,7 +583,7 @@ Please bump your version number and try again.'''),
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -596,7 +601,7 @@ Please bump your version number and try again.'''),
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => logger.success('\n✅ Published Release!')).called(1);
@@ -611,7 +616,7 @@ Please bump your version number and try again.'''),
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => logger.success('\n✅ Published Release!')).called(1);
@@ -644,7 +649,7 @@ flavors:
development: $appId''');
setUpTempArtifacts(tempDir, flavor: flavor);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => logger.success('\n✅ Published Release!')).called(1);
@@ -677,7 +682,7 @@ flavors:
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => logger.success('\n✅ Published Release!')).called(1);
@@ -704,7 +709,7 @@ flavors:
final tempDir = setUpTempDir();
setUpTempArtifacts(tempDir);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.config.code));
@@ -6,9 +6,11 @@ import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:platform/platform.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/archive_analysis/archive_analysis.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_environment.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
@@ -86,6 +88,10 @@ flutter:
late ShorebirdFlutterValidator flutterValidator;
late ShorebirdProcess shorebirdProcess;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
Directory setUpTempDir() {
final tempDir = Directory.systemTemp.createTempSync();
File(
@@ -188,7 +194,6 @@ flutter:
return codePushClient;
},
ipaReader: ipaReader,
logger: logger,
validators: [flutterValidator],
)
..testArgResults = argResults
@@ -203,7 +208,7 @@ flutter:
test('throws config error when shorebird is not initialized', () async {
final tempDir = Directory.systemTemp.createTempSync();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(
@@ -218,7 +223,7 @@ flutter:
when(() => auth.isAuthenticated).thenReturn(false);
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
() => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.noUser.code));
@@ -230,7 +235,7 @@ flutter:
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -246,7 +251,7 @@ flutter:
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -266,7 +271,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
() async => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -282,14 +287,15 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
() async => command.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.software.code));
verify(
() => progress
.fail(any(that: contains('Failed to determine release version'))),
() => progress.fail(
any(that: contains('Failed to determine release version')),
),
).called(1);
});
@@ -309,7 +315,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -335,7 +341,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, equals(ExitCode.config.code));
@@ -347,7 +353,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -363,7 +369,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verify(() => progress.fail(error)).called(1);
@@ -377,7 +383,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
expect(exitCode, ExitCode.software.code);
@@ -395,7 +401,7 @@ Did you forget to run "shorebird init"?''',
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -420,7 +426,7 @@ Please bump your version number and try again.'''),
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -436,7 +442,7 @@ Please bump your version number and try again.'''),
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -452,7 +458,7 @@ Please bump your version number and try again.'''),
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -477,7 +483,7 @@ flavors:
development: $appId''');
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -5,8 +5,10 @@ import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/releases/releases.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
import 'package:test/test.dart';
@@ -39,6 +41,18 @@ flutter:
assets:
- shorebird.yaml''';
late ArgResults argResults;
late http.Client httpClient;
late Auth auth;
late Logger logger;
late CodePushClient codePushClient;
late Progress progress;
late DeleteReleasesCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
Directory setUpTempDir() {
final tempDir = Directory.systemTemp.createTempSync();
File(
@@ -50,14 +64,6 @@ flutter:
return tempDir;
}
late ArgResults argResults;
late http.Client httpClient;
late Auth auth;
late Logger logger;
late CodePushClient codePushClient;
late Progress progress;
late DeleteReleasesCommand command;
setUp(() {
argResults = _MockArgResults();
httpClient = _MockHttpClient();
@@ -109,7 +115,6 @@ flutter:
}) {
return codePushClient;
},
logger: logger,
)..testArgResults = argResults;
});
@@ -123,13 +128,13 @@ flutter:
test('returns no user error when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.noUser.code);
});
test('returns config exit code if shorebird.yaml is not present', () async {
final exitCode = await command.run();
final exitCode = await runWithOverrides(command.run);
expect(exitCode, ExitCode.config.code);
});
@@ -140,7 +145,7 @@ flutter:
final tempDir = setUpTempDir();
await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -155,19 +160,20 @@ flutter:
() async {
final tempDir = setUpTempDir();
await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
verifyNever(() => logger.prompt(any()));
});
test('returns software exit code if get releases request fails', () async {
when(() => codePushClient.getReleases(appId: any(named: 'appId')))
.thenThrow(Exception('oops'));
when(
() => codePushClient.getReleases(appId: any(named: 'appId')),
).thenThrow(Exception('oops'));
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -179,7 +185,7 @@ flutter:
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -195,7 +201,7 @@ flutter:
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -213,7 +219,7 @@ flutter:
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -231,7 +237,7 @@ flutter:
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -257,7 +263,7 @@ flavors:
).thenAnswer((_) async {});
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -5,8 +5,10 @@ import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:path/path.dart' as p;
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
import 'package:test/test.dart';
@@ -42,6 +44,10 @@ flutter:
assets:
- shorebird.yaml''';
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
Directory setUpTempDir() {
final tempDir = Directory.systemTemp.createTempSync();
File(
@@ -65,7 +71,6 @@ flutter:
command = ListReleasesCommand(
auth: auth,
logger: logger,
buildCodePushClient: ({
required httpClient,
hostedUri,
@@ -80,11 +85,11 @@ flutter:
test('returns ExitCode.noUser when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
expect(await command.run(), ExitCode.noUser.code);
expect(await runWithOverrides(command.run), ExitCode.noUser.code);
});
test('returns ExitCode.config when shorebird is not initialized', () async {
final exitCode = await command.run();
final exitCode = await runWithOverrides(command.run);
verify(
() => logger.err(
@@ -100,12 +105,13 @@ flutter:
});
test('returns ExitCode.software when unable to get releases', () async {
when(() => codePushClient.getReleases(appId: any(named: 'appId')))
.thenThrow(Exception());
when(
() => codePushClient.getReleases(appId: any(named: 'appId')),
).thenThrow(Exception());
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -118,7 +124,7 @@ flutter:
final tempDir = setUpTempDir();
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -149,7 +155,7 @@ flavors:
);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -188,7 +194,7 @@ flavors:
);
final exitCode = await IOOverrides.runZoned(
command.run,
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -6,8 +6,10 @@ import 'package:args/args.dart';
import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/run_command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
@@ -43,10 +45,14 @@ void main() {
late Logger logger;
late Process process;
late CodePushClient codePushClient;
late RunCommand runCommand;
late AndroidInternetPermissionValidator androidInternetPermissionValidator;
late ShorebirdFlutterValidator flutterValidator;
late ShorebirdProcess shorebirdProcess;
late RunCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
argResults = _MockArgResults();
@@ -78,9 +84,8 @@ void main() {
).thenAnswer((_) async => []);
when(() => flutterValidator.validate(any())).thenAnswer((_) async => []);
runCommand = RunCommand(
command = RunCommand(
auth: auth,
logger: logger,
buildCodePushClient: ({
required http.Client httpClient,
Uri? hostedUri,
@@ -100,7 +105,7 @@ void main() {
test('exits with no user when not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
final result = await runCommand.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.noUser.code));
verify(
@@ -126,7 +131,7 @@ void main() {
when(() => process.exitCode).thenAnswer((_) async => exitCode);
final result = await IOOverrides.runZoned(
() => runCommand.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -150,7 +155,7 @@ void main() {
).thenAnswer((_) async => ExitCode.success.code);
final result = await IOOverrides.runZoned(
() => runCommand.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -178,7 +183,7 @@ void main() {
).thenAnswer((_) async => ExitCode.success.code);
final result = await IOOverrides.runZoned(
() => runCommand.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -235,7 +240,7 @@ void main() {
).thenAnswer((_) async => ExitCode.success.code);
final result = await IOOverrides.runZoned(
() => runCommand.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -264,7 +269,7 @@ void main() {
when(() => logger.progress(any())).thenReturn(progress);
final result = await IOOverrides.runZoned(
() => runCommand.run(),
() => runWithOverrides(command.run),
getCurrentDirectory: () => tempDir,
);
@@ -1,8 +1,10 @@
import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/auth/auth.dart';
import 'package:shorebird_cli/src/commands/subscription/cancel_subscription_command.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
import 'package:test/test.dart';
@@ -30,9 +32,12 @@ void main() {
late http.Client httpClient;
late Logger logger;
late Progress progress;
late CancelSubscriptionCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
auth = _MockAuth();
codePushClient = _MockCodePushClient();
@@ -45,7 +50,6 @@ void main() {
when(() => logger.progress(any())).thenReturn(progress);
command = CancelSubscriptionCommand(
logger: logger,
auth: auth,
buildCodePushClient: ({
required http.Client httpClient,
@@ -62,7 +66,7 @@ void main() {
test('prints an error if the user is not logged in', () async {
when(() => auth.isAuthenticated).thenReturn(false);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.noUser.code);
verify(
@@ -76,7 +80,7 @@ void main() {
Exception('an error occurred'),
);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.software.code);
verify(
@@ -88,7 +92,7 @@ void main() {
when(() => auth.isAuthenticated).thenReturn(true);
when(() => codePushClient.getCurrentUser()).thenAnswer((_) async => null);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.software.code);
verify(
@@ -102,10 +106,11 @@ void main() {
'prints an error if the user does not have an active subscription',
() async {
when(() => auth.isAuthenticated).thenReturn(true);
when(() => codePushClient.getCurrentUser())
.thenAnswer((_) async => noSubscriptionUser);
when(
() => codePushClient.getCurrentUser(),
).thenAnswer((_) async => noSubscriptionUser);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.software.code);
verify(
@@ -118,8 +123,9 @@ void main() {
test('exits successfully if the user opts not to cancel', () async {
when(() => auth.isAuthenticated).thenReturn(true);
when(() => codePushClient.getCurrentUser())
.thenAnswer((_) async => subscriptionUser);
when(
() => codePushClient.getCurrentUser(),
).thenAnswer((_) async => subscriptionUser);
when(
() => logger.confirm(
any(
@@ -130,7 +136,7 @@ void main() {
),
).thenReturn(false);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.success.code);
verify(() => logger.info('Aborting.')).called(1);
@@ -138,8 +144,9 @@ void main() {
test('prints an error if call to cancel subscription fails', () async {
when(() => auth.isAuthenticated).thenReturn(true);
when(() => codePushClient.getCurrentUser())
.thenAnswer((_) async => subscriptionUser);
when(
() => codePushClient.getCurrentUser(),
).thenAnswer((_) async => subscriptionUser);
when(
() => logger.confirm(
any(
@@ -153,7 +160,7 @@ void main() {
Exception('an error occurred'),
);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.software.code);
verify(
@@ -186,7 +193,7 @@ void main() {
),
);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, ExitCode.success.code);
@@ -1,6 +1,8 @@
import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:scoped/scoped.dart';
import 'package:shorebird_cli/src/commands/commands.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:test/test.dart';
@@ -23,8 +25,12 @@ void main() {
late ShorebirdProcessResult fetchLatestVersionResult;
late ShorebirdProcessResult hardResetResult;
late ShorebirdProcessResult pruneFlutterOriginResult;
late UpgradeCommand command;
late ShorebirdProcess shorebirdProcess;
late UpgradeCommand command;
R runWithOverrides<R>(R Function() body) {
return runScoped(body, values: {loggerRef.overrideWith(() => logger)});
}
setUp(() {
final progress = _MockProgress();
@@ -37,9 +43,7 @@ void main() {
hardResetResult = _MockProcessResult();
pruneFlutterOriginResult = _MockProcessResult();
shorebirdProcess = _MockShorebirdProcess();
command = UpgradeCommand(
logger: logger,
)
command = UpgradeCommand()
..testProcess = shorebirdProcess
..testEngineConfig = const EngineConfig.empty();
@@ -103,7 +107,7 @@ void main() {
});
test('can be instantiated', () {
final command = UpgradeCommand(logger: logger);
final command = UpgradeCommand();
expect(command, isNotNull);
});
@@ -113,7 +117,7 @@ void main() {
const errorMessage = 'oops';
when(() => fetchCurrentVersionResult.exitCode).thenReturn(1);
when(() => fetchCurrentVersionResult.stderr).thenReturn(errorMessage);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.software.code));
verify(() => logger.progress('Checking for updates')).called(1);
verify(
@@ -128,7 +132,7 @@ void main() {
const errorMessage = 'oops';
when(() => fetchLatestVersionResult.exitCode).thenReturn(1);
when(() => fetchLatestVersionResult.stderr).thenReturn(errorMessage);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.software.code));
verify(() => logger.progress('Checking for updates')).called(1);
verify(() => logger.err('Checking for updates failed: oops')).called(1);
@@ -144,7 +148,7 @@ void main() {
).thenReturn(newerShorebirdRevision);
when(() => hardResetResult.exitCode).thenReturn(1);
when(() => hardResetResult.stderr).thenReturn(errorMessage);
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.software.code));
verify(() => logger.progress('Checking for updates')).called(1);
verify(() => logger.err('Updating failed: oops')).called(1);
@@ -158,7 +162,7 @@ void main() {
when(() => pruneFlutterOriginResult.exitCode).thenReturn(1);
when(() => logger.progress(any())).thenReturn(_MockProgress());
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.software.code));
});
@@ -170,7 +174,7 @@ void main() {
() => fetchLatestVersionResult.stdout,
).thenReturn(newerShorebirdRevision);
when(() => logger.progress(any())).thenReturn(_MockProgress());
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.success.code));
verify(() => logger.progress('Checking for updates')).called(1);
verify(() => logger.progress('Updating')).called(1);
@@ -181,7 +185,7 @@ void main() {
'does not update when already on latest version',
() async {
when(() => logger.progress(any())).thenReturn(_MockProgress());
final result = await command.run();
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.success.code));
verify(
() => logger.info('Shorebird is already at the latest version.'),
@@ -7,8 +7,6 @@ import 'package:shorebird_cli/src/shorebird_process.dart';
import 'package:shorebird_cli/src/validators/validators.dart';
import 'package:test/test.dart';
class _MockLogger extends Mock implements Logger {}
class _MockProcessResult extends Mock implements ShorebirdProcessResult {}
class _MockShorebirdProcess extends Mock implements ShorebirdProcess {}
@@ -19,21 +17,17 @@ void main() {
group('ShorebirdVersionValidator', () {
late ShorebirdVersionValidator validator;
late Logger logger;
late DoctorCommand command;
late ShorebirdProcessResult fetchCurrentVersionResult;
late ShorebirdProcessResult fetchLatestVersionResult;
late ShorebirdProcess shorebirdProcess;
late DoctorCommand command;
setUp(() {
logger = _MockLogger();
fetchCurrentVersionResult = _MockProcessResult();
fetchLatestVersionResult = _MockProcessResult();
shorebirdProcess = _MockShorebirdProcess();
command = DoctorCommand(
logger: logger,
)
command = DoctorCommand()
..testProcess = shorebirdProcess
..testEngineConfig = const EngineConfig.empty();