Skip to content

Commit

Permalink
test: all plugin tests with & without url specified
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Oct 14, 2022
1 parent 1fe350a commit 8a65d11
Showing 1 changed file with 82 additions and 73 deletions.
155 changes: 82 additions & 73 deletions test/plugin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,24 @@ void main() {
injector.registerSingleton<CLISetup>(() => MockCLI(), override: true);
});

Future<Iterable<String>> runWith(String config) async {
// properly indent the configuration for the `sentry` section in the yaml
final configIndented =
config.trim().split('\n').map((l) => ' ${l.trim()}').join('\n');

fs.file('pubspec.yaml').writeAsStringSync('''
for (final url in const ['http://127.0.0.1', null]) {
group('url: $url', () {
final commonArgs =
'${url == null ? '' : '--url http://127.0.0.1 '}--auth-token t';
final commonCommands = [
if (!Platform.isWindows) 'chmod +x $cli',
'$cli help'
];

Future<Iterable<String>> runWith(String config) async {
// properly indent the configuration for the `sentry` section in the yaml
if (url != null) {
config = 'url: $url\n$config';
}
final configIndented =
config.trim().split('\n').map((l) => ' ${l.trim()}').join('\n');

fs.file('pubspec.yaml').writeAsStringSync('''
name: $project
version: $version
Expand All @@ -49,86 +61,83 @@ sentry:
$configIndented
''');

final exitCode = await plugin.run([]);
expect(exitCode, 0);
expect(pm.commandLog.take(2), const ['chmod +x $cli', '$cli help']);
return pm.commandLog.skip(2);
}
final exitCode = await plugin.run([]);
expect(exitCode, 0);
expect(pm.commandLog.take(commonCommands.length), commonCommands);
return pm.commandLog.skip(commonCommands.length);
}

test('fails without args and pubspec', () async {
final exitCode = await plugin.run([]);
expect(exitCode, 1);
expect(pm.commandLog, const ['chmod +x $cli', '$cli help']);
});
test('fails without args and pubspec', () async {
final exitCode = await plugin.run([]);
expect(exitCode, 1);
expect(pm.commandLog, commonCommands);
});

test('works with pubspec', () async {
// TODO: because `url` param affects all commands, make it a test-group argument and run all test cases with/without it.
final commandLog = await runWith('''
test('works with pubspec', () async {
final commandLog = await runWith('''
upload_native_symbols: true
include_native_sources: true
upload_source_maps: true
url: http://127.0.0.1
log_level: debug
''');
const args = '--url http://127.0.0.1 --auth-token t --log-level debug';
expect(commandLog, const [
'$cli $args upload-dif $orgAndProject --include-sources $buildDir',
'$cli $args releases $orgAndProject new $release',
'$cli $args releases $orgAndProject files $release upload-sourcemaps $buildDir/build/web --ext map --ext js',
'$cli $args releases $orgAndProject files $release upload-sourcemaps $buildDir --ext dart',
'$cli $args releases $orgAndProject set-commits $release --auto',
'$cli $args releases $orgAndProject finalize $release'
]);
});

test('defaults', () async {
final commandLog = await runWith('');
const args = '--auth-token t';
expect(commandLog, const [
'$cli $args upload-dif $orgAndProject $buildDir',
'$cli $args releases $orgAndProject new $release',
'$cli $args releases $orgAndProject set-commits $release --auto',
'$cli $args releases $orgAndProject finalize $release'
]);
});

group('commits', () {
const args = '--auth-token t';

// https://docs.sentry.io/product/cli/releases/#sentry-cli-commit-integration
for (final value in const [
null, // test the implicit default
'true',
'auto',
'repo_name@293ea41d67225d27a8c212f901637e771d73c0f7',
'repo_name@293ea41d67225d27a8c212f901637e771d73c0f7..1e248e5e6c24b79a5c46a2e8be12cef0e41bd58d',
]) {
test(value, () async {
final commandLog =
await runWith(value == null ? '' : 'commits: $value');
final expectedArgs =
(value == null || value == 'auto' || value == 'true')
? '--auto'
: '--commit $value';
final args = '$commonArgs --log-level debug';
expect(commandLog, [
'$cli $args upload-dif $orgAndProject $buildDir',
'$cli $args upload-dif $orgAndProject --include-sources $buildDir',
'$cli $args releases $orgAndProject new $release',
'$cli $args releases $orgAndProject set-commits $release $expectedArgs',
'$cli $args releases $orgAndProject files $release upload-sourcemaps $buildDir/build/web --ext map --ext js',
'$cli $args releases $orgAndProject files $release upload-sourcemaps $buildDir --ext dart',
'$cli $args releases $orgAndProject set-commits $release --auto',
'$cli $args releases $orgAndProject finalize $release'
]);
});
}

// if explicitly disabled
test('false', () async {
final commandLog = await runWith('commits: false');
expect(commandLog, [
'$cli $args upload-dif $orgAndProject $buildDir',
'$cli $args releases $orgAndProject new $release',
'$cli $args releases $orgAndProject finalize $release'
]);

test('defaults', () async {
final commandLog = await runWith('');
expect(commandLog, [
'$cli $commonArgs upload-dif $orgAndProject $buildDir',
'$cli $commonArgs releases $orgAndProject new $release',
'$cli $commonArgs releases $orgAndProject set-commits $release --auto',
'$cli $commonArgs releases $orgAndProject finalize $release'
]);
});

group('commits', () {
// https://docs.sentry.io/product/cli/releases/#sentry-cli-commit-integration
for (final value in const [
null, // test the implicit default
'true',
'auto',
'repo_name@293ea41d67225d27a8c212f901637e771d73c0f7',
'repo_name@293ea41d67225d27a8c212f901637e771d73c0f7..1e248e5e6c24b79a5c46a2e8be12cef0e41bd58d',
]) {
test(value, () async {
final commandLog =
await runWith(value == null ? '' : 'commits: $value');
final expectedArgs =
(value == null || value == 'auto' || value == 'true')
? '--auto'
: '--commit $value';
expect(commandLog, [
'$cli $commonArgs upload-dif $orgAndProject $buildDir',
'$cli $commonArgs releases $orgAndProject new $release',
'$cli $commonArgs releases $orgAndProject set-commits $release $expectedArgs',
'$cli $commonArgs releases $orgAndProject finalize $release'
]);
});
}

// if explicitly disabled
test('false', () async {
final commandLog = await runWith('commits: false');
expect(commandLog, [
'$cli $commonArgs upload-dif $orgAndProject $buildDir',
'$cli $commonArgs releases $orgAndProject new $release',
'$cli $commonArgs releases $orgAndProject finalize $release'
]);
});
});
});
});
}
}

class MockProcessManager implements ProcessManager {
Expand Down

0 comments on commit 8a65d11

Please sign in to comment.