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
09b2f435
Unverified
Commit
09b2f435
authored
Feb 25, 2021
by
Jonah Williams
Committed by
GitHub
Feb 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove mockito from mdns client test (#76747)
parent
33a9d6c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
44 deletions
+77
-44
mdns_discovery_test.dart
...flutter_tools/test/general.shard/mdns_discovery_test.dart
+77
-44
No files found.
packages/flutter_tools/test/general.shard/mdns_discovery_test.dart
View file @
09b2f435
...
...
@@ -6,14 +6,16 @@
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/device.dart'
;
import
'package:flutter_tools/src/ios/devices.dart'
;
import
'package:flutter_tools/src/mdns_discovery.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:multicast_dns/multicast_dns.dart'
;
import
'package:test/fake.dart'
;
import
'../src/common.dart'
;
import
'../src/mocks.dart'
;
void
main
(
)
{
group
(
'mDNS Discovery'
,
()
{
...
...
@@ -33,33 +35,9 @@ void main() {
resetNetworkInterfaceLister
();
});
MDnsClient
getMockClient
(
List
<
PtrResourceRecord
>
ptrRecords
,
Map
<
String
,
List
<
SrvResourceRecord
>>
srvResponse
,
{
Map
<
String
,
List
<
TxtResourceRecord
>>
txtResponse
=
const
<
String
,
List
<
TxtResourceRecord
>>{},
})
{
final
MDnsClient
client
=
MockMDnsClient
();
when
(
client
.
lookup
<
PtrResourceRecord
>(
ResourceRecordQuery
.
serverPointer
(
MDnsObservatoryDiscovery
.
dartObservatoryName
),
)).
thenAnswer
((
_
)
=>
Stream
<
PtrResourceRecord
>.
fromIterable
(
ptrRecords
));
for
(
final
MapEntry
<
String
,
List
<
SrvResourceRecord
>>
entry
in
srvResponse
.
entries
)
{
when
(
client
.
lookup
<
SrvResourceRecord
>(
ResourceRecordQuery
.
service
(
entry
.
key
),
)).
thenAnswer
((
_
)
=>
Stream
<
SrvResourceRecord
>.
fromIterable
(
entry
.
value
));
}
for
(
final
MapEntry
<
String
,
List
<
TxtResourceRecord
>>
entry
in
txtResponse
.
entries
)
{
when
(
client
.
lookup
<
TxtResourceRecord
>(
ResourceRecordQuery
.
text
(
entry
.
key
),
)).
thenAnswer
((
_
)
=>
Stream
<
TxtResourceRecord
>.
fromIterable
(
entry
.
value
));
}
return
client
;
}
testWithoutContext
(
'No ports available'
,
()
async
{
final
MDnsClient
client
=
getMock
Client
(<
PtrResourceRecord
>[],
<
String
,
List
<
SrvResourceRecord
>>{});
final
MDnsClient
client
=
FakeMDns
Client
(<
PtrResourceRecord
>[],
<
String
,
List
<
SrvResourceRecord
>>{});
final
MDnsObservatoryDiscovery
portDiscovery
=
MDnsObservatoryDiscovery
(
mdnsClient:
client
,
...
...
@@ -71,7 +49,7 @@ void main() {
});
testWithoutContext
(
'Prints helpful message when there is no ipv4 link local address.'
,
()
async
{
final
MDnsClient
client
=
getMock
Client
(<
PtrResourceRecord
>[],
<
String
,
List
<
SrvResourceRecord
>>{});
final
MDnsClient
client
=
FakeMDns
Client
(<
PtrResourceRecord
>[],
<
String
,
List
<
SrvResourceRecord
>>{});
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
MDnsObservatoryDiscovery
portDiscovery
=
MDnsObservatoryDiscovery
(
mdnsClient:
client
,
...
...
@@ -80,14 +58,14 @@ void main() {
);
final
Uri
uri
=
await
portDiscovery
.
getObservatoryUri
(
''
,
Mock
IOSDevice
(),
Fake
IOSDevice
(),
);
expect
(
uri
,
isNull
);
expect
(
logger
.
errorText
,
contains
(
'Personal Hotspot'
));
});
testWithoutContext
(
'One port available, no appId'
,
()
async
{
final
MDnsClient
client
=
getMock
Client
(
final
MDnsClient
client
=
FakeMDns
Client
(
<
PtrResourceRecord
>[
PtrResourceRecord
(
'foo'
,
year3000
,
domainName:
'bar'
),
],
...
...
@@ -108,7 +86,7 @@ void main() {
});
testWithoutContext
(
'One port available, no appId, with authCode'
,
()
async
{
final
MDnsClient
client
=
getMock
Client
(
final
MDnsClient
client
=
FakeMDns
Client
(
<
PtrResourceRecord
>[
PtrResourceRecord
(
'foo'
,
year3000
,
domainName:
'bar'
),
],
...
...
@@ -135,7 +113,7 @@ void main() {
});
testWithoutContext
(
'Multiple ports available, without appId'
,
()
async
{
final
MDnsClient
client
=
getMock
Client
(
final
MDnsClient
client
=
FakeMDns
Client
(
<
PtrResourceRecord
>[
PtrResourceRecord
(
'foo'
,
year3000
,
domainName:
'bar'
),
PtrResourceRecord
(
'baz'
,
year3000
,
domainName:
'fiz'
),
...
...
@@ -159,7 +137,7 @@ void main() {
});
testWithoutContext
(
'Multiple ports available, with appId'
,
()
async
{
final
MDnsClient
client
=
getMock
Client
(
final
MDnsClient
client
=
FakeMDns
Client
(
<
PtrResourceRecord
>[
PtrResourceRecord
(
'foo'
,
year3000
,
domainName:
'bar'
),
PtrResourceRecord
(
'baz'
,
year3000
,
domainName:
'fiz'
),
...
...
@@ -184,7 +162,7 @@ void main() {
});
testWithoutContext
(
'Multiple ports available per process, with appId'
,
()
async
{
final
MDnsClient
client
=
getMock
Client
(
final
MDnsClient
client
=
FakeMDns
Client
(
<
PtrResourceRecord
>[
PtrResourceRecord
(
'foo'
,
year3000
,
domainName:
'bar'
),
PtrResourceRecord
(
'baz'
,
year3000
,
domainName:
'fiz'
),
...
...
@@ -211,7 +189,7 @@ void main() {
});
testWithoutContext
(
'Query returns null'
,
()
async
{
final
MDnsClient
client
=
getMock
Client
(
final
MDnsClient
client
=
FakeMDns
Client
(
<
PtrResourceRecord
>[],
<
String
,
List
<
SrvResourceRecord
>>{},
);
...
...
@@ -226,10 +204,8 @@ void main() {
});
testWithoutContext
(
'Throws Exception when client throws OSError on start'
,
()
async
{
final
MDnsClient
client
=
MockMDnsClient
();
when
(
client
.
start
()).
thenAnswer
((
_
)
{
throw
const
OSError
(
'Operation not suppoted on socket'
,
102
);
});
final
MDnsClient
client
=
FakeMDnsClient
(<
PtrResourceRecord
>[],
<
String
,
List
<
SrvResourceRecord
>>{},
osErrorOnStart:
true
);
final
MDnsObservatoryDiscovery
portDiscovery
=
MDnsObservatoryDiscovery
(
mdnsClient:
client
,
...
...
@@ -243,7 +219,7 @@ void main() {
});
testWithoutContext
(
'Correctly builds Observatory URI with hostVmservicePort == 0'
,
()
async
{
final
MDnsClient
client
=
getMock
Client
(
final
MDnsClient
client
=
FakeMDns
Client
(
<
PtrResourceRecord
>[
PtrResourceRecord
(
'foo'
,
year3000
,
domainName:
'bar'
),
],
...
...
@@ -254,17 +230,74 @@ void main() {
},
);
final
MockIOSDevice
mockDevice
=
MockIOSDevice
();
when
(
mockDevice
.
portForwarder
).
thenReturn
(
const
NoOpDevicePortForwarder
());
final
FakeIOSDevice
device
=
FakeIOSDevice
();
final
MDnsObservatoryDiscovery
portDiscovery
=
MDnsObservatoryDiscovery
(
mdnsClient:
client
,
logger:
BufferLogger
.
test
(),
flutterUsage:
TestUsage
(),
);
final
Uri
uri
=
await
portDiscovery
.
getObservatoryUri
(
'bar'
,
mockD
evice
,
hostVmservicePort:
0
);
final
Uri
uri
=
await
portDiscovery
.
getObservatoryUri
(
'bar'
,
d
evice
,
hostVmservicePort:
0
);
expect
(
uri
.
toString
(),
'http://127.0.0.1:123/'
);
});
});
}
class
MockMDnsClient
extends
Mock
implements
MDnsClient
{}
class
FakeMDnsClient
extends
Fake
implements
MDnsClient
{
FakeMDnsClient
(
this
.
ptrRecords
,
this
.
srvResponse
,
{
this
.
txtResponse
=
const
<
String
,
List
<
TxtResourceRecord
>>{},
this
.
osErrorOnStart
=
false
,
});
final
List
<
PtrResourceRecord
>
ptrRecords
;
final
Map
<
String
,
List
<
SrvResourceRecord
>>
srvResponse
;
final
Map
<
String
,
List
<
TxtResourceRecord
>>
txtResponse
;
final
bool
osErrorOnStart
;
@override
Future
<
void
>
start
({
InternetAddress
listenAddress
,
NetworkInterfacesFactory
interfacesFactory
,
int
mDnsPort
=
5353
,
InternetAddress
mDnsAddress
,
})
async
{
if
(
osErrorOnStart
)
{
throw
const
OSError
(
'Operation not suppoted on socket'
,
102
);
}
}
@override
Stream
<
T
>
lookup
<
T
extends
ResourceRecord
>(
ResourceRecordQuery
query
,
{
Duration
timeout
=
const
Duration
(
seconds:
5
),
})
{
if
(
T
==
PtrResourceRecord
&&
query
.
fullyQualifiedName
==
MDnsObservatoryDiscovery
.
dartObservatoryName
)
{
return
Stream
<
PtrResourceRecord
>.
fromIterable
(
ptrRecords
)
as
Stream
<
T
>;
}
if
(
T
==
SrvResourceRecord
)
{
final
String
key
=
query
.
fullyQualifiedName
;
return
Stream
<
SrvResourceRecord
>.
fromIterable
(
srvResponse
[
key
]
??
<
SrvResourceRecord
>[])
as
Stream
<
T
>;
}
if
(
T
==
TxtResourceRecord
)
{
final
String
key
=
query
.
fullyQualifiedName
;
return
Stream
<
TxtResourceRecord
>.
fromIterable
(
txtResponse
[
key
]
??
<
TxtResourceRecord
>[])
as
Stream
<
T
>;
}
throw
UnsupportedError
(
'Unsupported query type
$T
'
);
}
@override
void
stop
()
{}
}
class
FakeIOSDevice
extends
Fake
implements
IOSDevice
{
@override
Future
<
TargetPlatform
>
get
targetPlatform
async
=>
TargetPlatform
.
ios
;
@override
bool
isSupported
()
=>
true
;
@override
bool
isSupportedForProject
(
FlutterProject
flutterProject
)
=>
true
;
@override
DevicePortForwarder
get
portForwarder
=>
const
NoOpDevicePortForwarder
();
}
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