NOTE: this is in a distinct file because the various string constants are pretty verbose.
(t *testing.T)
| 19 | // pretty verbose. |
| 20 | |
| 21 | func TestSelectBestService(t *testing.T) { |
| 22 | mustParseURL := func(ss string) *url.URL { |
| 23 | u, err := url.Parse(ss) |
| 24 | if err != nil { |
| 25 | t.Fatalf("error parsing URL %q: %v", ss, err) |
| 26 | } |
| 27 | return u |
| 28 | } |
| 29 | |
| 30 | // Run a fake IGD server to respond to UPnP requests. |
| 31 | igd, err := NewTestIGD(t, TestIGDOptions{UPnP: true}) |
| 32 | if err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
| 35 | defer igd.Close() |
| 36 | |
| 37 | testCases := []struct { |
| 38 | name string |
| 39 | rootDesc string |
| 40 | control map[string]map[string]any |
| 41 | want string // controlURL field |
| 42 | }{ |
| 43 | { |
| 44 | name: "single_device", |
| 45 | rootDesc: testRootDesc, |
| 46 | control: map[string]map[string]any{ |
| 47 | // Service that's up and should be selected. |
| 48 | "/ctl/IPConn": { |
| 49 | "GetExternalIPAddress": testGetExternalIPAddressResponse, |
| 50 | "GetStatusInfo": testGetStatusInfoResponse, |
| 51 | }, |
| 52 | }, |
| 53 | want: "/ctl/IPConn", |
| 54 | }, |
| 55 | { |
| 56 | name: "first_device_disconnected", |
| 57 | rootDesc: testSelectRootDesc, |
| 58 | control: map[string]map[string]any{ |
| 59 | // Service that's down; it's important that this is the |
| 60 | // one that's down since it's ordered first in the XML |
| 61 | // and we want to verify that our code properly queries |
| 62 | // and then skips it. |
| 63 | "/upnp/control/yomkmsnooi/wanipconn-1": { |
| 64 | "GetStatusInfo": testGetStatusInfoResponseDisconnected, |
| 65 | // NOTE: nothing else should be called |
| 66 | // if GetStatusInfo returns a |
| 67 | // disconnected result |
| 68 | }, |
| 69 | // Service that's up and should be selected. |
| 70 | "/upnp/control/xstnsgeuyh/wanipconn-7": { |
| 71 | "GetExternalIPAddress": testGetExternalIPAddressResponse, |
| 72 | "GetStatusInfo": testGetStatusInfoResponse, |
| 73 | }, |
| 74 | }, |
| 75 | want: "/upnp/control/xstnsgeuyh/wanipconn-7", |
| 76 | }, |
| 77 | { |
| 78 | name: "prefer_public_external_IP", |
nothing calls this directly
no test coverage detected
searching dependent graphs…