fix test
This commit is contained in:
parent
ba27df891e
commit
ed50c32702
@ -15,21 +15,22 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type IpRequester struct {
|
type IpRequester struct {
|
||||||
client *http.Client
|
StatusUrl string
|
||||||
statusUrl string
|
|
||||||
login string
|
client *http.Client
|
||||||
password string
|
login string
|
||||||
|
password string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIpRequester(client *http.Client, statusUrl string, login string, password string) *IpRequester {
|
func NewIpRequester(client *http.Client, statusUrl string, login string, password string) *IpRequester {
|
||||||
return &IpRequester{client: client, statusUrl: statusUrl, login: login, password: password}
|
return &IpRequester{client: client, StatusUrl: statusUrl, login: login, password: password}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r IpRequester) GetOutboundIp() <-chan outboundip.IpRequestResult {
|
func (r IpRequester) GetOutboundIp() <-chan outboundip.IpRequestResult {
|
||||||
result := make(chan outboundip.IpRequestResult)
|
result := make(chan outboundip.IpRequestResult)
|
||||||
go func() {
|
go func() {
|
||||||
defer close(result)
|
defer close(result)
|
||||||
url := r.statusUrl
|
url := r.StatusUrl
|
||||||
if url == "" {
|
if url == "" {
|
||||||
url = DefaultUrl
|
url = DefaultUrl
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,27 @@ package ddwrt
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
}
|
||||||
|
|
||||||
func TestRequester_GetOutboundIp(t *testing.T) {
|
func TestRequester_GetOutboundIp(t *testing.T) {
|
||||||
requester := NewIpRequester(&http.Client{
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
Timeout: 30 * time.Second,
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
}, "", "laurent", "&951753seiko38613861")
|
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()
|
result := <-requester.GetOutboundIp()
|
||||||
fmt.Printf("%+v\n", result)
|
fmt.Printf("%+v\n", result)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
t.Error(result.Error)
|
t.Error(result.Error)
|
||||||
}
|
}
|
||||||
|
if result.Ip != "92.130.63.129" {
|
||||||
|
t.Errorf("expected : 92.130.63.129, actual : %s", result.Ip)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user