Use deterministic dates for fake commits. (#4361)
Closes https://github.com/flutter/flutter/issues/165598.
diff --git a/app_dart/test/service/branch_service_test.dart b/app_dart/test/service/branch_service_test.dart
index 4a3b1a8..adcdd78 100644
--- a/app_dart/test/service/branch_service_test.dart
+++ b/app_dart/test/service/branch_service_test.dart
@@ -168,16 +168,19 @@
group('branchFlutterRecipes', () {
const branch = 'flutter-2.13-candidate.0';
const sha = 'abc123';
+ late gh.RepositoryCommit gitCommit;
+
late MockRepositoriesService repositories;
setUp(() {
- gerritService.branchesValue = <String>[];
+ gerritService.branchesValue = [];
repositories = MockRepositoriesService();
+ gitCommit = generateGitCommit(5);
when(
// ignore: discarded_futures
repositories.getCommit(Config.flutterSlug, sha),
- ).thenAnswer((_) async => generateGitCommit(5));
+ ).thenAnswer((_) async => gitCommit);
final mockGithub = MockGitHub();
when(mockGithub.repositories).thenReturn(repositories);
@@ -185,7 +188,12 @@
});
test('does not create branch that already exists', () async {
- gerritService.branchesValue = <String>[branch];
+ gitCommit = generateGitCommit(1, commitDate: DateTime(2025, 1, 9));
+ gerritService.branchesValue = [branch];
+ gerritService.commitsValue = [
+ generateGerritCommit('1', DateTime(2025, 1, 10).millisecondsSinceEpoch),
+ ];
+
expect(
() async => branchService.branchFlutterRecipes(branch, sha),
throwsExceptionWith<BadRequestException>('$branch already exists'),
@@ -211,15 +219,23 @@
test(
'does not create branch if a good branch point cannot be found',
() async {
- gerritService.commitsValue = <GerritCommit>[];
- when(
- repositories.getCommit(Config.flutterSlug, sha),
- ).thenAnswer((_) async => generateGitCommit(5));
+ gitCommit = generateGitCommit(1, commitDate: DateTime(2025, 1, 9));
+ gerritService.branchesValue = [];
+ gerritService.commitsValue = [
+ generateGerritCommit(
+ '1',
+ DateTime(2025, 1, 10).millisecondsSinceEpoch,
+ ),
+ ];
- expect(
- () async => branchService.branchFlutterRecipes(branch, sha),
+ when(
+ repositories.getCommit(Config.flutterSlug, gitCommit.sha),
+ ).thenAnswer((_) async => gitCommit);
+
+ await expectLater(
+ () => branchService.branchFlutterRecipes(branch, gitCommit.sha!),
throwsExceptionWith<InternalServerError>(
- 'HTTP 500: Failed to find a revision to flutter/recipes for $branch before 1969-12-31',
+ 'HTTP 500: Failed to find a revision to flutter/recipes for $branch before 2025-01-09 00:00:00.000',
),
);
},
diff --git a/app_dart/test/src/utilities/entity_generators.dart b/app_dart/test/src/utilities/entity_generators.dart
index ae1648f..bdd3297 100644
--- a/app_dart/test/src/utilities/entity_generators.dart
+++ b/app_dart/test/src/utilities/entity_generators.dart
@@ -356,12 +356,17 @@
),
);
-github.RepositoryCommit generateGitCommit(int i) => github.RepositoryCommit(
+github.RepositoryCommit generateGitCommit(
+ int i, {
+ DateTime? commitDate,
+ String? sha,
+}) => github.RepositoryCommit(
+ sha: sha ?? '$i',
commit: github.GitCommit(
committer: github.GitCommitUser(
'dash',
'dash@flutter.dev',
- DateTime.fromMillisecondsSinceEpoch(i),
+ commitDate ?? DateTime.fromMillisecondsSinceEpoch(i),
),
),
);