Testing: fix MainIP, simplify parser

This commit is contained in:
kayos@tcp.direct 2022-05-05 05:57:10 -07:00
parent 56a209e5bd
commit 10344ac6f2
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
2 changed files with 10 additions and 19 deletions

View File

@ -44,21 +44,6 @@ func (bw *bwUsed) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
return nil
}
type ipAddr netaddr.IP
func (ipa *ipAddr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var content string
if err := d.DecodeElement(&content, &start); err != nil {
return err
}
ip, err := netaddr.ParseIP(content)
if err != nil {
return err
}
*ipa = ipAddr(ip)
return nil
}
type errMsg struct {
content string
}
@ -94,7 +79,7 @@ type Response struct {
Status string `xml:"vmstat"`
Err errMsg `xml:"statusmsg"`
Hostname string `xml:"hostname"`
MainIP ipAddr `xml:"ipaddress"`
MainIP ipList `xml:"ipaddress"`
AllIPs ipList `xml:"ipaddr"`
Node string `xml:"node"`
BandwidthUsed bwUsed `xml:"bw"`

View File

@ -42,17 +42,23 @@ func TestParseResposne(t *testing.T) {
t.Fatalf("bad value for node, wanted %s, got %s", "KVM-69.FT.BUYVM.NET", resp.Node)
case resp.BandwidthUsed != bwUsed(2199023255552):
t.Fatalf("bad value for bandwidth used, wanted %d, got %d", bwUsed(2199023255552), resp.BandwidthUsed)
case resp.MainIP != ipAddr(netaddr.MustParseIP("127.0.0.1")):
t.Fatalf("bad value for main IP, wanted %v, got %v", ipAddr(netaddr.MustParseIP("127.0.0.1")), resp.MainIP)
case resp.Location != "Fuck Town, Washington, US":
t.Fatalf("bad value for location, wanted %s, got %s", "Fuck Town, Washington, US", resp.Location)
default:
//
}
//goland:noinspection GoNilness
for i, ip := range resp.AllIPs {
//goland:noinspection GoNilness
if ips[i] != ip {
t.Fatalf("missing ip: %v", ips[i])
}
t.Logf("%s == %s", ips[i].String(), ip.String())
}
//goland:noinspection GoNilness
if resp.MainIP[0] != ips[0] {
t.Fatalf("bad main IP, got %v, wanted %v", ips[0], resp.MainIP)
}
var rj []byte