chore(shorebird_cli): remove redundant api and storage access validators (#2574)
This commit is contained in:
@@ -29,8 +29,6 @@ class Doctor {
|
||||
ShorebirdVersionValidator(),
|
||||
ShorebirdFlutterValidator(),
|
||||
AndroidInternetPermissionValidator(),
|
||||
ShorebirdApiAccessValidator(),
|
||||
StorageAccessValidator(),
|
||||
ShorebirdYamlAssetValidator(),
|
||||
];
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:shorebird_cli/src/http_client/http_client.dart';
|
||||
import 'package:shorebird_cli/src/validators/validators.dart';
|
||||
|
||||
/// Verifies that the user has access to api.shorebird.dev.
|
||||
class ShorebirdApiAccessValidator extends Validator {
|
||||
@override
|
||||
String get description => 'Has access to api.shorebird.dev';
|
||||
|
||||
@override
|
||||
Future<List<ValidationIssue>> validate() async {
|
||||
final uri = Uri.parse('https://api.shorebird.dev');
|
||||
final result = await httpClient.get(uri);
|
||||
if (result.statusCode != HttpStatus.ok) {
|
||||
return [
|
||||
const ValidationIssue(
|
||||
severity: ValidationIssueSeverity.error,
|
||||
message: 'Unable to access api.shorebird.dev',
|
||||
),
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
// cspell:words googleapis
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:shorebird_cli/src/http_client/http_client.dart';
|
||||
import 'package:shorebird_cli/src/validators/validators.dart';
|
||||
|
||||
/// Verifies that the user has access to storage.googleapis.com.
|
||||
class StorageAccessValidator extends Validator {
|
||||
@override
|
||||
String get description => 'Has access to storage.googleapis.com';
|
||||
|
||||
@override
|
||||
Future<List<ValidationIssue>> validate() async {
|
||||
final testFileUrl = Uri.parse(
|
||||
'https://storage.googleapis.com/shorebird_doctor/hello',
|
||||
);
|
||||
final result = await httpClient.get(testFileUrl);
|
||||
if (result.statusCode != HttpStatus.ok || result.body != 'hello') {
|
||||
return [
|
||||
const ValidationIssue(
|
||||
severity: ValidationIssueSeverity.error,
|
||||
message: 'Unable to access storage.googleapis.com',
|
||||
),
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,9 @@ import 'package:shorebird_cli/src/shorebird_process.dart';
|
||||
|
||||
export 'android_internet_permission_validator.dart';
|
||||
export 'flavor_validator.dart';
|
||||
export 'shorebird_api_access_validator.dart';
|
||||
export 'shorebird_flutter_validator.dart';
|
||||
export 'shorebird_version_validator.dart';
|
||||
export 'shorebird_yaml_asset_validator.dart';
|
||||
export 'storage_access_validator.dart';
|
||||
|
||||
/// Severity level of a [ValidationIssue].
|
||||
enum ValidationIssueSeverity {
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:scoped_deps/scoped_deps.dart';
|
||||
import 'package:shorebird_cli/src/http_client/http_client.dart';
|
||||
import 'package:shorebird_cli/src/validators/validators.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../mocks.dart';
|
||||
|
||||
void main() {
|
||||
group(ShorebirdApiAccessValidator, () {
|
||||
late http.Client httpClient;
|
||||
late ShorebirdApiAccessValidator validator;
|
||||
|
||||
R runWithOverrides<R>(R Function() body) {
|
||||
return runScoped(
|
||||
() => body(),
|
||||
values: {
|
||||
httpClientRef.overrideWith(() => httpClient),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
setUpAll(() {
|
||||
registerFallbackValue(Uri());
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
httpClient = MockHttpClient();
|
||||
validator = ShorebirdApiAccessValidator();
|
||||
|
||||
when(() => httpClient.get(any())).thenAnswer(
|
||||
(_) async => http.Response('', HttpStatus.ok),
|
||||
);
|
||||
});
|
||||
|
||||
group('description', () {
|
||||
test('has a non-empty description', () {
|
||||
expect(validator.description, isNotEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
group('validate', () {
|
||||
group('when url is accessible', () {
|
||||
setUp(() {
|
||||
when(() => httpClient.get(any())).thenAnswer(
|
||||
(_) async => http.Response('', HttpStatus.ok),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns empty list of validation issues', () async {
|
||||
final results = await runWithOverrides(validator.validate);
|
||||
expect(results, isEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
group('when url is inaccessible', () {
|
||||
setUp(() {
|
||||
when(() => httpClient.get(any())).thenAnswer(
|
||||
(_) async => http.Response('Not Found', HttpStatus.notFound),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns validation error', () async {
|
||||
final results = await runWithOverrides(validator.validate);
|
||||
expect(
|
||||
results,
|
||||
equals(
|
||||
[
|
||||
const ValidationIssue(
|
||||
severity: ValidationIssueSeverity.error,
|
||||
message: 'Unable to access api.shorebird.dev',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:scoped_deps/scoped_deps.dart';
|
||||
import 'package:shorebird_cli/src/http_client/http_client.dart';
|
||||
import 'package:shorebird_cli/src/validators/validators.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../mocks.dart';
|
||||
|
||||
void main() {
|
||||
group(StorageAccessValidator, () {
|
||||
late http.Client httpClient;
|
||||
late StorageAccessValidator validator;
|
||||
|
||||
R runWithOverrides<R>(R Function() body) {
|
||||
return runScoped(
|
||||
() => body(),
|
||||
values: {
|
||||
httpClientRef.overrideWith(() => httpClient),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
setUpAll(() {
|
||||
registerFallbackValue(Uri.parse('http://example.com'));
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
httpClient = MockHttpClient();
|
||||
validator = StorageAccessValidator();
|
||||
|
||||
when(() => httpClient.get(any())).thenAnswer(
|
||||
(_) async => http.Response('', HttpStatus.ok),
|
||||
);
|
||||
});
|
||||
|
||||
group('description', () {
|
||||
test('has a non-empty description', () {
|
||||
expect(validator.description, isNotEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
group('validate', () {
|
||||
group('when storage url is accessible', () {
|
||||
setUp(() {
|
||||
when(() => httpClient.get(any())).thenAnswer(
|
||||
(_) async => http.Response('hello', HttpStatus.ok),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns empty list of validation issues', () async {
|
||||
final results = await runWithOverrides(validator.validate);
|
||||
expect(results, isEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
group('when storage url is inaccessible', () {
|
||||
setUp(() {
|
||||
when(() => httpClient.get(any())).thenAnswer(
|
||||
(_) async => http.Response('Not Found', HttpStatus.notFound),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns validation error', () async {
|
||||
final results = await runWithOverrides(validator.validate);
|
||||
expect(
|
||||
results,
|
||||
equals(
|
||||
[
|
||||
const ValidationIssue(
|
||||
severity: ValidationIssueSeverity.error,
|
||||
message: 'Unable to access storage.googleapis.com',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user