Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
5d7b4019
Unverified
Commit
5d7b4019
authored
May 14, 2021
by
Jonah Williams
Committed by
GitHub
May 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove mocks from downgrade and devices test (#82579)
parent
aa9b2d91
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
57 deletions
+69
-57
downgrade.dart
packages/flutter_tools/lib/src/commands/downgrade.dart
+2
-2
downgrade_test.dart
...er_tools/test/commands.shard/hermetic/downgrade_test.dart
+41
-43
devices_test.dart
...ter_tools/test/commands.shard/permeable/devices_test.dart
+26
-12
No files found.
packages/flutter_tools/lib/src/commands/downgrade.dart
View file @
5d7b4019
...
...
@@ -35,7 +35,7 @@ class DowngradeCommand extends FlutterCommand {
Logger
logger
,
ProcessManager
processManager
,
FlutterVersion
flutterVersion
,
Ansi
Terminal
terminal
,
Terminal
terminal
,
Stdio
stdio
,
FileSystem
fileSystem
,
})
:
_terminal
=
terminal
,
...
...
@@ -61,7 +61,7 @@ class DowngradeCommand extends FlutterCommand {
);
}
Ansi
Terminal
_terminal
;
Terminal
_terminal
;
FlutterVersion
_flutterVersion
;
PersistentToolState
_persistentToolState
;
ProcessUtils
_processUtils
;
...
...
packages/flutter_tools/test/commands.shard/hermetic/downgrade_test.dart
View file @
5d7b4019
...
...
@@ -12,7 +12,7 @@ import 'package:flutter_tools/src/base/terminal.dart';
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/commands/downgrade.dart'
;
import
'package:flutter_tools/src/persistent_tool_state.dart'
;
import
'package:
mockito/mockito
.dart'
;
import
'package:
test/fake
.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
...
...
@@ -22,9 +22,9 @@ import '../../src/test_flutter_command_runner.dart';
void
main
(
)
{
FileSystem
fileSystem
;
BufferLogger
bufferLogger
;
Ansi
Terminal
terminal
;
Fake
Terminal
terminal
;
ProcessManager
processManager
;
MockStdio
mockS
tdio
;
FakeStdio
s
tdio
;
setUpAll
(()
{
Cache
.
disableLocking
();
...
...
@@ -35,9 +35,9 @@ void main() {
});
setUp
(()
{
mockStdio
=
Mock
Stdio
();
stdio
=
Fake
Stdio
();
processManager
=
FakeProcessManager
.
any
();
terminal
=
Mock
Terminal
();
terminal
=
Fake
Terminal
();
fileSystem
=
MemoryFileSystem
.
test
();
bufferLogger
=
BufferLogger
.
test
(
terminal:
terminal
);
});
...
...
@@ -50,7 +50,7 @@ void main() {
persistentToolState:
PersistentToolState
.
test
(
directory:
fileSystem
.
currentDirectory
,
logger:
bufferLogger
),
processManager:
processManager
,
terminal:
terminal
,
stdio:
mockS
tdio
,
stdio:
s
tdio
,
flutterVersion:
fakeFlutterVersion
,
logger:
bufferLogger
,
);
...
...
@@ -75,7 +75,7 @@ void main() {
)
]),
terminal:
terminal
,
stdio:
mockS
tdio
,
stdio:
s
tdio
,
flutterVersion:
fakeFlutterVersion
,
logger:
bufferLogger
,
);
...
...
@@ -103,7 +103,7 @@ void main() {
)
]),
terminal:
terminal
,
stdio:
mockS
tdio
,
stdio:
s
tdio
,
flutterVersion:
fakeFlutterVersion
,
logger:
bufferLogger
,
);
...
...
@@ -114,67 +114,49 @@ void main() {
testUsingContext
(
'Downgrade prompts for user input when terminal is attached - y'
,
()
async
{
final
FakeFlutterVersion
fakeFlutterVersion
=
FakeFlutterVersion
(
channel:
'master'
);
when
(
mockStdio
.
hasTerminal
).
thenReturn
(
true
)
;
stdio
.
hasTerminal
=
true
;
fileSystem
.
currentDirectory
.
childFile
(
'.flutter_tool_state'
)
.
writeAsStringSync
(
'{"last-active-master-version":"g6b00b5e88"}'
);
final
DowngradeCommand
command
=
DowngradeCommand
(
persistentToolState:
PersistentToolState
.
test
(
directory:
fileSystem
.
currentDirectory
,
logger:
bufferLogger
),
processManager:
processManager
,
terminal:
terminal
,
stdio:
mockS
tdio
,
stdio:
s
tdio
,
flutterVersion:
fakeFlutterVersion
,
logger:
bufferLogger
,
);
when
(
terminal
.
promptForCharInput
(
const
<
String
>[
'y'
,
'n'
],
prompt:
anyNamed
(
'prompt'
),
logger:
anyNamed
(
'logger'
),
)).
thenAnswer
((
Invocation
invocation
)
async
=>
'y'
);
terminal
.
addPrompt
(
const
<
String
>[
'y'
,
'n'
],
'y'
);
await
createTestCommandRunner
(
command
).
run
(
const
<
String
>[
'downgrade'
]);
verify
(
terminal
.
promptForCharInput
(
const
<
String
>[
'y'
,
'n'
],
prompt:
anyNamed
(
'prompt'
),
logger:
anyNamed
(
'logger'
),
)).
called
(
1
);
expect
(
bufferLogger
.
statusText
,
contains
(
'Success'
));
});
testUsingContext
(
'Downgrade prompts for user input when terminal is attached - n'
,
()
async
{
final
FakeFlutterVersion
fakeFlutterVersion
=
FakeFlutterVersion
(
channel:
'master'
);
when
(
mockStdio
.
hasTerminal
).
thenReturn
(
true
)
;
stdio
.
hasTerminal
=
true
;
fileSystem
.
currentDirectory
.
childFile
(
'.flutter_tool_state'
)
.
writeAsStringSync
(
'{"last-active-master-version":"g6b00b5e88"}'
);
final
DowngradeCommand
command
=
DowngradeCommand
(
persistentToolState:
PersistentToolState
.
test
(
directory:
fileSystem
.
currentDirectory
,
logger:
bufferLogger
),
processManager:
processManager
,
terminal:
terminal
,
stdio:
mockS
tdio
,
stdio:
s
tdio
,
flutterVersion:
fakeFlutterVersion
,
logger:
bufferLogger
,
);
when
(
terminal
.
promptForCharInput
(
const
<
String
>[
'y'
,
'n'
],
prompt:
anyNamed
(
'prompt'
),
logger:
anyNamed
(
'logger'
),
)).
thenAnswer
((
Invocation
invocation
)
async
=>
'n'
);
terminal
.
addPrompt
(
const
<
String
>[
'y'
,
'n'
],
'n'
);
await
createTestCommandRunner
(
command
).
run
(
const
<
String
>[
'downgrade'
]);
verify
(
terminal
.
promptForCharInput
(
const
<
String
>[
'y'
,
'n'
],
prompt:
anyNamed
(
'prompt'
),
logger:
anyNamed
(
'logger'
),
)).
called
(
1
);
expect
(
bufferLogger
.
statusText
,
isNot
(
contains
(
'Success'
)));
});
testUsingContext
(
'Downgrade does not prompt when there is no terminal'
,
()
async
{
final
FakeFlutterVersion
fakeFlutterVersion
=
FakeFlutterVersion
(
channel:
'master'
);
when
(
mockStdio
.
hasTerminal
).
thenReturn
(
false
)
;
stdio
.
hasTerminal
=
false
;
fileSystem
.
currentDirectory
.
childFile
(
'.flutter_tool_state'
)
.
writeAsStringSync
(
'{"last-active-master-version":"g6b00b5e88"}'
);
final
DowngradeCommand
command
=
DowngradeCommand
(
...
...
@@ -184,24 +166,19 @@ void main() {
),
processManager:
processManager
,
terminal:
terminal
,
stdio:
mockS
tdio
,
stdio:
s
tdio
,
flutterVersion:
fakeFlutterVersion
,
logger:
bufferLogger
,
);
await
createTestCommandRunner
(
command
).
run
(
const
<
String
>[
'downgrade'
]);
verifyNever
(
terminal
.
promptForCharInput
(
const
<
String
>[
'y'
,
'n'
],
prompt:
anyNamed
(
'prompt'
),
logger:
anyNamed
(
'logger'
),
));
expect
(
bufferLogger
.
statusText
,
contains
(
'Success'
));
});
testUsingContext
(
'Downgrade performs correct git commands'
,
()
async
{
final
FakeFlutterVersion
fakeFlutterVersion
=
FakeFlutterVersion
(
channel:
'master'
);
when
(
mockStdio
.
hasTerminal
).
thenReturn
(
false
)
;
stdio
.
hasTerminal
=
false
;
fileSystem
.
currentDirectory
.
childFile
(
'.flutter_tool_state'
)
.
writeAsStringSync
(
'{"last-active-master-version":"g6b00b5e88"}'
);
final
DowngradeCommand
command
=
DowngradeCommand
(
...
...
@@ -228,7 +205,7 @@ void main() {
),
]),
terminal:
terminal
,
stdio:
mockS
tdio
,
stdio:
s
tdio
,
flutterVersion:
fakeFlutterVersion
,
logger:
bufferLogger
,
);
...
...
@@ -239,5 +216,26 @@ void main() {
});
}
class
MockTerminal
extends
Mock
implements
AnsiTerminal
{}
class
MockStdio
extends
Mock
implements
Stdio
{}
class
FakeTerminal
extends
Fake
implements
Terminal
{
@override
bool
usesTerminalUi
=
false
;
void
addPrompt
(
List
<
String
>
characters
,
String
selected
)
{
_characters
=
characters
;
_selected
=
selected
;
}
List
<
String
>
_characters
;
String
_selected
;
@override
Future
<
String
>
promptForCharInput
(
List
<
String
>
acceptedCharacters
,
{
Logger
logger
,
String
prompt
,
int
defaultChoiceIndex
,
bool
displayAcceptedCharacters
=
true
})
async
{
expect
(
acceptedCharacters
,
_characters
);
return
_selected
;
}
}
class
FakeStdio
extends
Fake
implements
Stdio
{
@override
bool
hasTerminal
=
true
;
}
packages/flutter_tools/test/commands.shard/permeable/devices_test.dart
View file @
5d7b4019
...
...
@@ -13,21 +13,27 @@ import 'package:flutter_tools/src/cache.dart';
import
'package:flutter_tools/src/commands/devices.dart'
;
import
'package:flutter_tools/src/device.dart'
;
import
'package:flutter_tools/src/features.dart'
;
import
'package:flutter_tools/src/globals.dart'
as
globals
;
import
'package:flutter_tools/src/web/web_device.dart'
;
import
'package:
mockito/mockito
.dart'
;
import
'package:
test/fake
.dart'
;
import
'../../src/context.dart'
;
import
'../../src/fakes.dart'
;
import
'../../src/test_flutter_command_runner.dart'
;
void
main
(
)
{
FakeDeviceManager
deviceManager
;
BufferLogger
logger
;
setUpAll
(()
{
Cache
.
disableLocking
();
});
setUp
(()
{
deviceManager
=
FakeDeviceManager
();
logger
=
BufferLogger
.
test
();
});
testUsingContext
(
'devices can display no connected devices with the --machine flag'
,
()
async
{
final
BufferLogger
logger
=
context
.
get
<
Logger
>()
as
BufferLogger
;
final
DevicesCommand
command
=
DevicesCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'devices'
,
'--machine'
]);
...
...
@@ -38,16 +44,13 @@ void main() {
);
},
overrides:
<
Type
,
Generator
>{
FeatureFlags:
()
=>
TestFeatureFlags
(
isWebEnabled:
false
),
Logger:
()
=>
logger
,
});
testUsingContext
(
'devices can display via the --machine flag'
,
()
async
{
when
(
globals
.
deviceManager
.
refreshAllConnectedDevices
()).
thenAnswer
((
Invocation
invocation
)
async
{
return
<
Device
>[
WebServerDevice
(
logger:
BufferLogger
.
test
()),
];
});
final
BufferLogger
logger
=
context
.
get
<
Logger
>()
as
BufferLogger
;
deviceManager
.
devices
=
<
Device
>[
WebServerDevice
(
logger:
logger
),
];
final
DevicesCommand
command
=
DevicesCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'devices'
,
'--machine'
]);
...
...
@@ -76,8 +79,19 @@ void main() {
);
},
overrides:
<
Type
,
Generator
>{
FeatureFlags:
()
=>
TestFeatureFlags
(
isWebEnabled:
true
),
DeviceManager:
()
=>
MockDeviceManager
(),
DeviceManager:
()
=>
deviceManager
,
Logger:
()
=>
logger
,
});
}
class
MockDeviceManager
extends
Mock
implements
DeviceManager
{}
class
FakeDeviceManager
extends
Fake
implements
DeviceManager
{
List
<
Device
>
devices
=
<
Device
>[];
@override
String
specifiedDeviceId
;
@override
Future
<
List
<
Device
>>
refreshAllConnectedDevices
({
Duration
timeout
})
async
{
return
devices
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment