@@ -112,6 +112,56 @@ void main() {
112
112
expect (portDiscovery.queryForAttach, throwsToolExit ());
113
113
});
114
114
115
+ testWithoutContext ('Find duplicates in preliminary client' , () async {
116
+ final MDnsClient client = FakeMDnsClient (
117
+ < PtrResourceRecord > [
118
+ PtrResourceRecord ('foo' , future, domainName: 'bar' ),
119
+ PtrResourceRecord ('foo' , future, domainName: 'bar' ),
120
+ ],
121
+ < String , List <SrvResourceRecord >> {
122
+ 'bar' : < SrvResourceRecord > [
123
+ SrvResourceRecord ('bar' , future, port: 123 , weight: 1 , priority: 1 , target: 'appId' ),
124
+ ],
125
+ },
126
+ );
127
+
128
+ final MDnsVmServiceDiscovery portDiscovery = MDnsVmServiceDiscovery (
129
+ mdnsClient: emptyClient,
130
+ preliminaryMDnsClient: client,
131
+ logger: BufferLogger .test (),
132
+ flutterUsage: TestUsage (),
133
+ );
134
+
135
+ final MDnsVmServiceDiscoveryResult ? result = await portDiscovery.queryForAttach ();
136
+ expect (result, isNotNull);
137
+ });
138
+
139
+ testWithoutContext ('Find similar named in preliminary client' , () async {
140
+ final MDnsClient client = FakeMDnsClient (
141
+ < PtrResourceRecord > [
142
+ PtrResourceRecord ('foo' , future, domainName: 'bar' ),
143
+ PtrResourceRecord ('foo' , future, domainName: 'bar (2)' ),
144
+ ],
145
+ < String , List <SrvResourceRecord >> {
146
+ 'bar' : < SrvResourceRecord > [
147
+ SrvResourceRecord ('bar' , future, port: 123 , weight: 1 , priority: 1 , target: 'appId' ),
148
+ ],
149
+ 'bar (2)' : < SrvResourceRecord > [
150
+ SrvResourceRecord ('bar' , future, port: 123 , weight: 1 , priority: 1 , target: 'appId' ),
151
+ ],
152
+ },
153
+ );
154
+
155
+ final MDnsVmServiceDiscovery portDiscovery = MDnsVmServiceDiscovery (
156
+ mdnsClient: emptyClient,
157
+ preliminaryMDnsClient: client,
158
+ logger: BufferLogger .test (),
159
+ flutterUsage: TestUsage (),
160
+ );
161
+
162
+ expect (portDiscovery.queryForAttach, throwsToolExit ());
163
+ });
164
+
115
165
testWithoutContext ('No ports available' , () async {
116
166
final MDnsVmServiceDiscovery portDiscovery = MDnsVmServiceDiscovery (
117
167
mdnsClient: emptyClient,
@@ -680,6 +730,112 @@ void main() {
680
730
expect (result? .domainName, 'srv-bar' );
681
731
expect (result? .port, 222 );
682
732
});
733
+ testWithoutContext ('find with no txt record' , () async {
734
+ final MDnsClient client = FakeMDnsClient (
735
+ < PtrResourceRecord > [
736
+ PtrResourceRecord ('foo' , future, domainName: 'srv-foo' ),
737
+ ],
738
+ < String , List <SrvResourceRecord >> {
739
+ 'srv-foo' : < SrvResourceRecord > [
740
+ SrvResourceRecord ('srv-foo' , future, port: 111 , weight: 1 , priority: 1 , target: 'target-foo' ),
741
+ ],
742
+ },
743
+ ipResponse: < String , List <IPAddressResourceRecord >> {
744
+ 'target-foo' : < IPAddressResourceRecord > [
745
+ IPAddressResourceRecord ('target-foo' , 0 , address: InternetAddress .tryParse ('111.111.111.111' )! ),
746
+ ],
747
+ },
748
+ );
749
+
750
+ final MDnsVmServiceDiscovery portDiscovery = MDnsVmServiceDiscovery (
751
+ mdnsClient: client,
752
+ logger: BufferLogger .test (),
753
+ flutterUsage: TestUsage (),
754
+ );
755
+ final MDnsVmServiceDiscoveryResult ? result = await portDiscovery.firstMatchingVmService (
756
+ client,
757
+ applicationId: 'srv-foo' ,
758
+ isNetworkDevice: true ,
759
+ );
760
+ expect (result? .domainName, 'srv-foo' );
761
+ expect (result? .port, 111 );
762
+ expect (result? .authCode, '' );
763
+ expect (result? .ipAddress? .address, '111.111.111.111' );
764
+ });
765
+ testWithoutContext ('find with empty txt record' , () async {
766
+ final MDnsClient client = FakeMDnsClient (
767
+ < PtrResourceRecord > [
768
+ PtrResourceRecord ('foo' , future, domainName: 'srv-foo' ),
769
+ ],
770
+ < String , List <SrvResourceRecord >> {
771
+ 'srv-foo' : < SrvResourceRecord > [
772
+ SrvResourceRecord ('srv-foo' , future, port: 111 , weight: 1 , priority: 1 , target: 'target-foo' ),
773
+ ],
774
+ },
775
+ txtResponse: < String , List <TxtResourceRecord >> {
776
+ 'srv-foo' : < TxtResourceRecord > [
777
+ TxtResourceRecord ('srv-foo' , future, text: '' ),
778
+ ],
779
+ },
780
+ ipResponse: < String , List <IPAddressResourceRecord >> {
781
+ 'target-foo' : < IPAddressResourceRecord > [
782
+ IPAddressResourceRecord ('target-foo' , 0 , address: InternetAddress .tryParse ('111.111.111.111' )! ),
783
+ ],
784
+ },
785
+ );
786
+
787
+ final MDnsVmServiceDiscovery portDiscovery = MDnsVmServiceDiscovery (
788
+ mdnsClient: client,
789
+ logger: BufferLogger .test (),
790
+ flutterUsage: TestUsage (),
791
+ );
792
+ final MDnsVmServiceDiscoveryResult ? result = await portDiscovery.firstMatchingVmService (
793
+ client,
794
+ applicationId: 'srv-foo' ,
795
+ isNetworkDevice: true ,
796
+ );
797
+ expect (result? .domainName, 'srv-foo' );
798
+ expect (result? .port, 111 );
799
+ expect (result? .authCode, '' );
800
+ expect (result? .ipAddress? .address, '111.111.111.111' );
801
+ });
802
+ testWithoutContext ('find with valid txt record' , () async {
803
+ final MDnsClient client = FakeMDnsClient (
804
+ < PtrResourceRecord > [
805
+ PtrResourceRecord ('foo' , future, domainName: 'srv-foo' ),
806
+ ],
807
+ < String , List <SrvResourceRecord >> {
808
+ 'srv-foo' : < SrvResourceRecord > [
809
+ SrvResourceRecord ('srv-foo' , future, port: 111 , weight: 1 , priority: 1 , target: 'target-foo' ),
810
+ ],
811
+ },
812
+ txtResponse: < String , List <TxtResourceRecord >> {
813
+ 'srv-foo' : < TxtResourceRecord > [
814
+ TxtResourceRecord ('srv-foo' , future, text: 'authCode=xyz\n ' ),
815
+ ],
816
+ },
817
+ ipResponse: < String , List <IPAddressResourceRecord >> {
818
+ 'target-foo' : < IPAddressResourceRecord > [
819
+ IPAddressResourceRecord ('target-foo' , 0 , address: InternetAddress .tryParse ('111.111.111.111' )! ),
820
+ ],
821
+ },
822
+ );
823
+
824
+ final MDnsVmServiceDiscovery portDiscovery = MDnsVmServiceDiscovery (
825
+ mdnsClient: client,
826
+ logger: BufferLogger .test (),
827
+ flutterUsage: TestUsage (),
828
+ );
829
+ final MDnsVmServiceDiscoveryResult ? result = await portDiscovery.firstMatchingVmService (
830
+ client,
831
+ applicationId: 'srv-foo' ,
832
+ isNetworkDevice: true ,
833
+ );
834
+ expect (result? .domainName, 'srv-foo' );
835
+ expect (result? .port, 111 );
836
+ expect (result? .authCode, 'xyz/' );
837
+ expect (result? .ipAddress? .address, '111.111.111.111' );
838
+ });
683
839
});
684
840
}
685
841
0 commit comments