Skip to content

Commit c567216

Browse files
committed
add test
1 parent d715b9e commit c567216

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:args/command_runner.dart';
6+
import 'package:file/file.dart';
7+
import 'package:flutter_plugin_tools/src/branch_for_batch_release_command.dart';
8+
import 'package:flutter_plugin_tools/src/common/repository_package.dart';
9+
import 'package:git/git.dart';
10+
import 'package:test/test.dart';
11+
12+
import 'mocks.dart';
13+
14+
import 'util.dart';
15+
16+
void main() {
17+
late Directory packagesDir;
18+
late RecordingProcessRunner processRunner;
19+
late RecordingProcessRunner gitProcessRunner;
20+
late CommandRunner<void> runner;
21+
22+
setUp(() {
23+
final GitDir gitDir;
24+
(:packagesDir, :processRunner, :gitProcessRunner, :gitDir) =
25+
configureBaseCommandMocks();
26+
27+
final BranchForBatchReleaseCommand command = BranchForBatchReleaseCommand(
28+
packagesDir,
29+
processRunner: processRunner,
30+
gitDir: gitDir,
31+
);
32+
runner = CommandRunner<void>('branch_for_batch_release_command',
33+
'Test for branch_for_batch_release_command');
34+
runner.addCommand(command);
35+
});
36+
37+
group('happy path', () {
38+
late RepositoryPackage package;
39+
setUp(() {
40+
package = createFakePackage('a_package', packagesDir);
41+
42+
package.changelogFile.writeAsStringSync('''
43+
## 1.0.0
44+
45+
- Old changes
46+
''');
47+
package.pubspecFile.writeAsStringSync('''
48+
name: a_package
49+
version: 1.0.0
50+
''');
51+
final File pendingChangelog = package.directory
52+
.childDirectory('pending_changelogs')
53+
.childFile('a.yaml')
54+
..createSync(recursive: true);
55+
pendingChangelog.writeAsStringSync('''
56+
changelog: A new feature
57+
version: minor
58+
''');
59+
});
60+
61+
tearDown(() {
62+
package.directory.deleteSync(recursive: true);
63+
});
64+
65+
test('makes a branch', () async {
66+
// Set up a mock for the git calls to have side-effects.
67+
gitProcessRunner.mockProcessesForExecutable['git'] = <FakeProcessInfo>[
68+
// checkout
69+
FakeProcessInfo(
70+
MockProcess(), const <String>['checkout', '-b', 'release-branch']),
71+
// rm
72+
FakeProcessInfo(MockProcess(), <String>[
73+
'rm',
74+
package.directory
75+
.childDirectory('pending_changelogs')
76+
.childFile('a.yaml')
77+
.path
78+
], () {
79+
package.directory
80+
.childDirectory('pending_changelogs')
81+
.childFile('a.yaml')
82+
.deleteSync();
83+
}),
84+
// add
85+
FakeProcessInfo(MockProcess(), <String>[
86+
'add',
87+
package.pubspecFile.path,
88+
package.changelogFile.path
89+
]),
90+
// commit
91+
FakeProcessInfo(MockProcess(),
92+
const <String>['commit', '-m', 'a_package: Prepare for release']),
93+
// push
94+
FakeProcessInfo(MockProcess(),
95+
const <String>['push', 'origin', 'release-branch', '--force']),
96+
];
97+
final List<String> output = await runCapturingPrint(runner, <String>[
98+
'branch-for-batch-release',
99+
'--packages=a_package',
100+
'--branch=release-branch',
101+
]);
102+
103+
expect(
104+
output,
105+
containsAllInOrder(<String>[
106+
'Parsing package "a_package"...',
107+
'Creating and pushing release branch...',
108+
' Creating new branch "release-branch"...',
109+
' Updating pubspec.yaml to version 1.1.0...',
110+
' Updating CHANGELOG.md...',
111+
' Removing pending changelog files...',
112+
' Staging changes...',
113+
' Committing changes...',
114+
' Pushing to remote...',
115+
]));
116+
117+
expect(package.pubspecFile.readAsStringSync(), '''
118+
name: a_package
119+
version: 1.1.0
120+
''');
121+
expect(package.changelogFile.readAsStringSync(), '''
122+
## 1.1.0
123+
124+
A new feature
125+
126+
## 1.0.0
127+
128+
- Old changes
129+
''');
130+
131+
expect(
132+
gitProcessRunner.recordedCalls,
133+
orderedEquals(<ProcessCall>[
134+
const ProcessCall(
135+
'git-checkout', <String>['-b', 'release-branch'], null),
136+
ProcessCall(
137+
'git-rm',
138+
<String>[
139+
package.directory
140+
.childDirectory('pending_changelogs')
141+
.childFile('a.yaml')
142+
.path
143+
],
144+
null),
145+
ProcessCall(
146+
'git-add',
147+
<String>[package.pubspecFile.path, package.changelogFile.path],
148+
null),
149+
const ProcessCall('git-commit',
150+
<String>['-m', 'a_package: Prepare for release'], null),
151+
const ProcessCall('git-push',
152+
<String>['origin', 'release-branch', '--force'], null),
153+
]));
154+
});
155+
});
156+
}

0 commit comments

Comments
 (0)