22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- import 'dart:convert' ;
6-
75import 'package:args/command_runner.dart' ;
86import 'package:file/file.dart' ;
97import 'package:flutter_plugin_tools/src/common/core.dart' ;
108import 'package:flutter_plugin_tools/src/version_check_command.dart' ;
119import 'package:git/git.dart' ;
12- import 'package:http/http.dart' as http;
13- import 'package:http/testing.dart' ;
1410import 'package:pub_semver/pub_semver.dart' ;
1511import 'package:test/test.dart' ;
1612
@@ -40,15 +36,11 @@ void testAllowedVersion(
4036}
4137
4238void main () {
43- const indentation = ' ' ;
4439 group ('VersionCheckCommand' , () {
4540 late MockPlatform mockPlatform;
4641 late Directory packagesDir;
4742 late CommandRunner <void > runner;
4843 late RecordingProcessRunner gitProcessRunner;
49- // Ignored if mockHttpResponse is set.
50- int mockHttpStatus;
51- Map <String , dynamic >? mockHttpResponse;
5244
5345 setUp (() {
5446 mockPlatform = MockPlatform ();
@@ -57,22 +49,11 @@ void main() {
5749 (: packagesDir, : processRunner, : gitProcessRunner, : gitDir) =
5850 configureBaseCommandMocks (platform: mockPlatform);
5951
60- // Default to simulating the plugin never having been published.
61- mockHttpStatus = 404 ;
62- mockHttpResponse = null ;
63- final mockClient = MockClient ((http.Request request) async {
64- return http.Response (
65- json.encode (mockHttpResponse),
66- mockHttpResponse == null ? mockHttpStatus : 200 ,
67- );
68- });
69-
7052 final command = VersionCheckCommand (
7153 packagesDir,
7254 processRunner: processRunner,
7355 platform: mockPlatform,
7456 gitDir: gitDir,
75- httpClient: mockClient,
7657 );
7758
7859 runner = CommandRunner <void >(
@@ -448,7 +429,7 @@ void main() {
448429 Error ? commandError;
449430 final List <String > output = await runCapturingPrint (
450431 runner,
451- < String > ['version-check' , '--base-sha=main' , '--against-pub' ],
432+ < String > ['version-check' , '--base-sha=main' ],
452433 errorHandler: (Error e) {
453434 commandError = e;
454435 },
@@ -594,7 +575,7 @@ void main() {
594575 var hasError = false ;
595576 final List <String > output = await runCapturingPrint (
596577 runner,
597- < String > ['version-check' , '--base-sha=main' , '--against-pub' ],
578+ < String > ['version-check' , '--base-sha=main' ],
598579 errorHandler: (Error e) {
599580 expect (e, isA <ToolExit >());
600581 hasError = true ;
@@ -669,7 +650,7 @@ void main() {
669650 var hasError = false ;
670651 final List <String > output = await runCapturingPrint (
671652 runner,
672- < String > ['version-check' , '--base-sha=main' , '--against-pub' ],
653+ < String > ['version-check' , '--base-sha=main' ],
673654 errorHandler: (Error e) {
674655 expect (e, isA <ToolExit >());
675656 hasError = true ;
@@ -1652,114 +1633,6 @@ packages/plugin/lib/plugin.dart
16521633 });
16531634 });
16541635
1655- test ('allows valid against pub' , () async {
1656- mockHttpResponse = < String , dynamic > {
1657- 'name' : 'some_package' ,
1658- 'versions' : < String > ['0.0.1' , '0.0.2' , '1.0.0' ],
1659- };
1660-
1661- createFakePlugin ('plugin' , packagesDir, version: '2.0.0' );
1662- final List <String > output = await runCapturingPrint (runner, < String > [
1663- 'version-check' ,
1664- '--base-sha=main' ,
1665- '--against-pub' ,
1666- ]);
1667-
1668- expect (
1669- output,
1670- containsAllInOrder (< Matcher > [
1671- contains ('plugin: Current largest version on pub: 1.0.0' ),
1672- ]),
1673- );
1674- });
1675-
1676- test ('denies invalid against pub' , () async {
1677- mockHttpResponse = < String , dynamic > {
1678- 'name' : 'some_package' ,
1679- 'versions' : < String > ['0.0.1' , '0.0.2' ],
1680- };
1681-
1682- createFakePlugin ('plugin' , packagesDir, version: '2.0.0' );
1683-
1684- var hasError = false ;
1685- final List <String > result = await runCapturingPrint (
1686- runner,
1687- < String > ['version-check' , '--base-sha=main' , '--against-pub' ],
1688- errorHandler: (Error e) {
1689- expect (e, isA <ToolExit >());
1690- hasError = true ;
1691- },
1692- );
1693- expect (hasError, isTrue);
1694-
1695- expect (
1696- result,
1697- containsAllInOrder (< Matcher > [
1698- contains (
1699- '''
1700- ${indentation }Incorrectly updated version.
1701- ${indentation }HEAD: 2.0.0, pub: 0.0.2.
1702- ${indentation }Allowed versions: {1.0.0: NextVersionType.BREAKING_MAJOR, 0.1.0: NextVersionType.MINOR, 0.0.3: NextVersionType.PATCH}''' ,
1703- ),
1704- ]),
1705- );
1706- });
1707-
1708- test (
1709- 'throw and print error message if http request failed when checking against pub' ,
1710- () async {
1711- mockHttpStatus = 400 ;
1712-
1713- createFakePlugin ('plugin' , packagesDir, version: '2.0.0' );
1714- var hasError = false ;
1715- final List <String > result = await runCapturingPrint (
1716- runner,
1717- < String > ['version-check' , '--base-sha=main' , '--against-pub' ],
1718- errorHandler: (Error e) {
1719- expect (e, isA <ToolExit >());
1720- hasError = true ;
1721- },
1722- );
1723- expect (hasError, isTrue);
1724-
1725- expect (
1726- result,
1727- containsAllInOrder (< Matcher > [
1728- contains ('''
1729- ${indentation }Error fetching version on pub for plugin.
1730- ${indentation }HTTP Status 400
1731- ${indentation }HTTP response: null
1732- ''' ),
1733- ]),
1734- );
1735- },
1736- );
1737-
1738- test (
1739- 'when checking against pub, allow any version if http status is 404.' ,
1740- () async {
1741- mockHttpStatus = 404 ;
1742-
1743- createFakePlugin ('plugin' , packagesDir, version: '2.0.0' );
1744- gitProcessRunner.mockProcessesForExecutable['git-show' ] =
1745- < FakeProcessInfo > [
1746- FakeProcessInfo (MockProcess (stdout: 'version: 1.0.0' )),
1747- ];
1748- final List <String > result = await runCapturingPrint (runner, < String > [
1749- 'version-check' ,
1750- '--base-sha=main' ,
1751- '--against-pub' ,
1752- ]);
1753-
1754- expect (
1755- result,
1756- containsAllInOrder (< Matcher > [
1757- contains ('Unable to find previous version on pub server.' ),
1758- ]),
1759- );
1760- },
1761- );
1762-
17631636 group ('prelease versions' , () {
17641637 test (
17651638 'allow an otherwise-valid transition that also adds a pre-release component' ,
0 commit comments