Skip to content

Commit

Permalink
refactor(code_push_client): upgrade analysis_options (#2719)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Dec 19, 2024
1 parent f31fdd0 commit 82dfa29
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 39 deletions.
3 changes: 2 additions & 1 deletion packages/shorebird_code_push_client/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include: package:very_good_analysis/analysis_options.5.1.0.yaml
include: package:very_good_analysis/analysis_options.7.0.0.yaml
analyzer:
exclude:
- lib/src/version.dart
- example/**
2 changes: 0 additions & 2 deletions packages/shorebird_code_push_client/example/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore_for_file: unused_local_variable

import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

Future<void> main() async {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/// The Shorebird CodePush API Client
library shorebird_code_push_client;

export 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';

export 'src/code_push_client.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ class CodePushClient {
try {
final body = json.decode(response) as Map<String, dynamic>;
error = ErrorResponse.fromJson(body);
} catch (_) {
} on Exception {
throw exceptionBuilder(message: unknownErrorMessage);
}
return exceptionBuilder(message: error.message, details: error.details);
Expand Down
2 changes: 1 addition & 1 deletion packages/shorebird_code_push_client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ dev_dependencies:
build_version: ^2.0.0
mocktail: ^1.0.0
test: ^1.19.2
very_good_analysis: ^6.0.0
very_good_analysis: ^7.0.0
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore_for_file: prefer_const_constructors
import 'dart:convert';
import 'dart:io';

Expand Down Expand Up @@ -51,7 +50,7 @@ void main() {
customHeaders: customHeaders,
);
when(() => httpClient.send(any())).thenAnswer(
(_) async => http.StreamedResponse(Stream.empty(), HttpStatus.ok),
(_) async => http.StreamedResponse(const Stream.empty(), HttpStatus.ok),
);
});

Expand All @@ -75,7 +74,7 @@ void main() {
test('throws CodePushUpgradeRequiredException on 426 response', () async {
when(() => httpClient.send(any())).thenAnswer(
(_) async => http.StreamedResponse(
Stream.empty(),
const Stream.empty(),
HttpStatus.upgradeRequired,
),
);
Expand All @@ -89,7 +88,7 @@ void main() {
test('throws CodePushForbiddenException on 403 response', () async {
when(() => httpClient.send(any())).thenAnswer(
(_) async => http.StreamedResponse(
Stream.empty(),
const Stream.empty(),
HttpStatus.forbidden,
),
);
Expand Down Expand Up @@ -184,7 +183,9 @@ void main() {
platform: platform,
hash: hash,
);
} catch (_) {}
} on Exception {
// ignore
}

final request = verify(() => httpClient.send(captureAny()))
.captured
Expand Down Expand Up @@ -223,7 +224,9 @@ void main() {
hash: hash,
hashSignature: hashSignature,
);
} catch (_) {}
} on Exception {
// ignore
}

final request = verify(() => httpClient.send(captureAny()))
.captured
Expand Down Expand Up @@ -317,7 +320,7 @@ void main() {
Stream.value(
utf8.encode(
json.encode(
CreatePatchArtifactResponse(
const CreatePatchArtifactResponse(
id: artifactId,
patchId: patchId,
arch: arch,
Expand All @@ -331,7 +334,7 @@ void main() {
),
HttpStatus.ok,
),
http.StreamedResponse(Stream.empty(), HttpStatus.badRequest),
http.StreamedResponse(const Stream.empty(), HttpStatus.badRequest),
];
when(() => httpClient.send(any())).thenAnswer(
(_) async => responses.removeAt(0),
Expand Down Expand Up @@ -376,7 +379,7 @@ void main() {
Stream.value(
utf8.encode(
json.encode(
CreatePatchArtifactResponse(
const CreatePatchArtifactResponse(
id: artifactId,
patchId: patchId,
arch: arch,
Expand All @@ -390,7 +393,7 @@ void main() {
),
HttpStatus.ok,
),
http.StreamedResponse(Stream.empty(), HttpStatus.noContent),
http.StreamedResponse(const Stream.empty(), HttpStatus.noContent),
];
when(() => httpClient.send(any())).thenAnswer(
(_) async => responses.removeAt(0),
Expand Down Expand Up @@ -440,7 +443,7 @@ void main() {
final fixture = File(path.join(tempDir.path, 'release.txt'))
..createSync()
..writeAsStringSync('hello');
final expectedRequest = CreateReleaseArtifactRequest(
const expectedRequest = CreateReleaseArtifactRequest(
arch: arch,
platform: platform,
hash: hash,
Expand All @@ -461,7 +464,9 @@ void main() {
canSideload: canSideload,
podfileLockHash: null,
);
} catch (_) {}
} on Exception {
// ignore
}

final request = verify(() => httpClient.send(captureAny()))
.captured
Expand All @@ -473,7 +478,7 @@ void main() {
);
expect(request.hasHeaders(expectedHeaders), isTrue);
expect(
MapEquality<String, dynamic>().equals(
const MapEquality<String, dynamic>().equals(
request.fields,
expectedRequest.toJson(),
),
Expand All @@ -488,7 +493,7 @@ void main() {
final fixture = File(path.join(tempDir.path, 'release.txt'))
..createSync()
..writeAsStringSync('hello');
final expectedRequest = CreateReleaseArtifactRequest(
const expectedRequest = CreateReleaseArtifactRequest(
arch: arch,
platform: platform,
hash: hash,
Expand All @@ -509,7 +514,9 @@ void main() {
canSideload: canSideload,
podfileLockHash: podfileLockHash,
);
} catch (_) {}
} on Exception {
// ignore
}

final request = verify(() => httpClient.send(captureAny()))
.captured
Expand All @@ -521,7 +528,7 @@ void main() {
);
expect(request.hasHeaders(expectedHeaders), isTrue);
expect(
MapEquality<String, dynamic>().equals(
const MapEquality<String, dynamic>().equals(
request.fields,
expectedRequest.toJson(),
),
Expand All @@ -533,7 +540,7 @@ void main() {
test('throws an exception if the http request fails (unknown)', () async {
when(() => httpClient.send(any())).thenAnswer((_) async {
return http.StreamedResponse(
Stream.empty(),
const Stream.empty(),
HttpStatus.failedDependency,
);
});
Expand Down Expand Up @@ -662,7 +669,7 @@ void main() {
Stream.value(
utf8.encode(
json.encode(
CreateReleaseArtifactResponse(
const CreateReleaseArtifactResponse(
id: artifactId,
releaseId: releaseId,
arch: arch,
Expand All @@ -676,7 +683,7 @@ void main() {
),
HttpStatus.ok,
),
http.StreamedResponse(Stream.empty(), HttpStatus.badRequest),
http.StreamedResponse(const Stream.empty(), HttpStatus.badRequest),
];
when(() => httpClient.send(any())).thenAnswer(
(_) async => responses.removeAt(0),
Expand Down Expand Up @@ -723,7 +730,7 @@ void main() {
Stream.value(
utf8.encode(
json.encode(
CreateReleaseArtifactResponse(
const CreateReleaseArtifactResponse(
id: artifactId,
releaseId: releaseId,
arch: arch,
Expand All @@ -737,7 +744,7 @@ void main() {
),
HttpStatus.ok,
),
http.StreamedResponse(Stream.empty(), HttpStatus.noContent),
http.StreamedResponse(const Stream.empty(), HttpStatus.noContent),
];
when(() => httpClient.send(any())).thenAnswer(
(_) async => responses.removeAt(0),
Expand Down Expand Up @@ -841,7 +848,7 @@ void main() {
(_) async => http.StreamedResponse(
Stream.value(
utf8.encode(
json.encode(App(id: appId, displayName: displayName)),
json.encode(const App(id: appId, displayName: displayName)),
),
),
HttpStatus.ok,
Expand Down Expand Up @@ -933,7 +940,7 @@ void main() {
Stream.value(
utf8.encode(
json.encode(
Channel(id: channelId, appId: appId, name: channel),
const Channel(id: channelId, appId: appId, name: channel),
),
),
),
Expand Down Expand Up @@ -1038,7 +1045,7 @@ void main() {
(_) async => http.StreamedResponse(
Stream.value(
utf8.encode(
json.encode(Patch(id: patchId, number: patchNumber)),
json.encode(const Patch(id: patchId, number: patchNumber)),
),
),
HttpStatus.ok,
Expand Down Expand Up @@ -1286,7 +1293,7 @@ void main() {

group('createUser', () {
const userName = 'Jane Doe';
final user = PrivateUser(
const user = PrivateUser(
id: 1,
email: 'tester@shorebird.dev',
displayName: userName,
Expand Down Expand Up @@ -1575,8 +1582,8 @@ void main() {

test('completes when request succeeds (populated)', () async {
final expected = [
Channel(id: 0, appId: '1', name: 'stable'),
Channel(id: 1, appId: '2', name: 'development'),
const Channel(id: 0, appId: '1', name: 'stable'),
const Channel(id: 1, appId: '2', name: 'development'),
];

when(() => httpClient.send(any())).thenAnswer(
Expand Down Expand Up @@ -1665,7 +1672,7 @@ void main() {
when(() => httpClient.send(any())).thenAnswer(
(_) async => http.StreamedResponse(
Stream.value(
utf8.encode(json.encode(GetReleasesResponse(releases: []))),
utf8.encode(json.encode(const GetReleasesResponse(releases: []))),
),
HttpStatus.ok,
),
Expand Down Expand Up @@ -1745,12 +1752,12 @@ void main() {
late ReleasePatch patch;

setUp(() {
patch = ReleasePatch(
patch = const ReleasePatch(
id: 0,
number: 1,
channel: 'stable',
isRolledBack: false,
artifacts: const [],
artifacts: [],
);
response = GetReleasePatchesResponse(patches: [patch]);
when(() => httpClient.send(any())).thenAnswer(
Expand Down Expand Up @@ -1851,7 +1858,7 @@ void main() {

test('completes when request succeeds', () async {
final expected = [
ReleaseArtifact(
const ReleaseArtifact(
id: 0,
releaseId: releaseId,
arch: arch,
Expand Down

0 comments on commit 82dfa29

Please sign in to comment.