30 lines
1.2 KiB
Go
30 lines
1.2 KiB
Go
package ddwrt
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func init() {
|
|
}
|
|
|
|
func TestRequester_GetOutboundIp(t *testing.T) {
|
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/plain")
|
|
fmt.Fprintln(w, `{wan_shortproto::dhcp_auth}{wan_status::Error <input class="button" type="button" value="Error" onclick="connect(this.form, '" "_dhcp_auth')" />}{wan_uptime::1 day, 4:17:41}{pppoe_ac_name::}{wan_3g_signal::n.A.}{wan_ipaddr::92.130.63.129}{wan_netmask::255.255.248.0}{wan_gateway::92.130.56.1}{wan_dns0::192.168.1.250}{wan_dns1::80.10.246.4}{wan_dns2::81.253.149.15}{dhcp_remaining::0 days 15:24:14}{ttraff_in::142865}{ttraff_out::70849}{uptime:: 08:18:05 up 1 day, 4:18, load average: 1.00, 1.02, 1.00}{ipinfo:: IPv4: 92.130.63.129 IPv6: 2a01:cb22:112:c800:200:ff:fe00:0}`)
|
|
}))
|
|
defer s.Close()
|
|
|
|
requester := NewIpRequester(s.Client(), s.URL, "laurent", "&951753seiko38613861")
|
|
result := <-requester.GetOutboundIp()
|
|
fmt.Printf("%+v\n", result)
|
|
if result.Error != nil {
|
|
t.Error(result.Error)
|
|
}
|
|
if result.Ip != "92.130.63.129" {
|
|
t.Errorf("expected : 92.130.63.129, actual : %s", result.Ip)
|
|
}
|
|
}
|