@@ -175,3 +175,56 @@ func TestSearch_ServiceRawHeader(t *testing.T) {
175
175
}
176
176
}
177
177
}
178
+
179
+ func TestSearch_AdvetiserWithHost (t * testing.T ) {
180
+ a , err := Advertise ("test:search+advertiserwithhost" , "usn:search+advertiserwithhost" , "location:search+advertiserwithhost" , "server:search+advertiserwithhost" , 600 , AdvertiserOptionAddHost ())
181
+ if err != nil {
182
+ t .Fatalf ("failed to Advertise: %s" , err )
183
+ }
184
+ defer a .Close ()
185
+
186
+ srvs , err := Search ("test:search+advertiserwithhost" , 1 , "" )
187
+ if err != nil {
188
+ t .Fatalf ("failed to Search: %s" , err )
189
+ }
190
+ if len (srvs ) == 0 {
191
+ t .Fatal ("no services found" )
192
+ }
193
+
194
+ expHdr := map [string ]string {
195
+ "St" : "test:search+advertiserwithhost" ,
196
+ "Usn" : "usn:search+advertiserwithhost" ,
197
+ "Location" : "location:search+advertiserwithhost" ,
198
+ "Server" : "server:search+advertiserwithhost" ,
199
+ "Cache-Control" : "max-age=600" ,
200
+ "Ext" : "" ,
201
+ "Host" : "239.255.255.250:1900" ,
202
+ }
203
+ for i , s := range srvs {
204
+ if s .Type != "test:search+advertiserwithhost" {
205
+ t .Errorf ("unmatch type#%d:\n want=%q\n got=%q" , i , "test:search+request" , s .Type )
206
+ }
207
+ if s .USN != "usn:search+advertiserwithhost" {
208
+ t .Errorf ("unexpected alive#%d usn: want=%q got=%q" , i , "usn:search+advertiserwithhost" , s .USN )
209
+ }
210
+ if s .Location != "location:search+advertiserwithhost" {
211
+ t .Errorf ("unexpected alive#%d location: want=%q got=%q" , i , "location:search+advertiserwithhost" , s .Location )
212
+ }
213
+ if s .Server != "server:search+advertiserwithhost" {
214
+ t .Errorf ("unexpected alive#%d server: want=%q got=%q" , i , "server:search+advertiserwithhost" , s .Server )
215
+ }
216
+ if s .MaxAge () != 600 {
217
+ t .Errorf ("unexpected max-age: want=%d got=%d" , 600 , s .MaxAge ())
218
+ }
219
+
220
+ h := s .Header ()
221
+ for k := range h {
222
+ exp , ok := expHdr [k ]
223
+ if ! ok {
224
+ t .Errorf ("unexpected header #%d %q=%q" , i , k , h .Get (k ))
225
+ } else if act := h .Get (k ); act != exp {
226
+ t .Errorf ("header #%d %q value mismatch:\n want=%q\n got=%q" , i , k , exp , act )
227
+ }
228
+ }
229
+ }
230
+ }
0 commit comments