2020-10-26 09:36:59 +00:00
|
|
|
package ddwrt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-10-26 13:04:14 +00:00
|
|
|
"net/http"
|
2020-10-27 12:55:53 +00:00
|
|
|
"net/http/httptest"
|
2020-10-26 09:36:59 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2020-10-27 12:55:53 +00:00
|
|
|
func init() {
|
|
|
|
}
|
|
|
|
|
2020-10-26 09:36:59 +00:00
|
|
|
func TestRequester_GetOutboundIp(t *testing.T) {
|
2020-10-27 12:55:53 +00:00
|
|
|
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")
|
2020-10-26 09:36:59 +00:00
|
|
|
result := <-requester.GetOutboundIp()
|
|
|
|
fmt.Printf("%+v\n", result)
|
|
|
|
if result.Error != nil {
|
|
|
|
t.Error(result.Error)
|
|
|
|
}
|
2020-10-27 12:55:53 +00:00
|
|
|
if result.Ip != "92.130.63.129" {
|
|
|
|
t.Errorf("expected : 92.130.63.129, actual : %s", result.Ip)
|
|
|
|
}
|
2020-10-26 09:36:59 +00:00
|
|
|
}
|