mirror of
https://gitlab.com/pnx-tools/dns-updater.git
synced 2026-06-16 05:54:56 +02:00
33 lines
626 B
Go
33 lines
626 B
Go
package ipme
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestService_Name(t *testing.T) {
|
|
s := Service{}
|
|
|
|
assert.Equal(t, "ip.me", s.Name())
|
|
}
|
|
|
|
func TestService_Lookup(t *testing.T) {
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
assert.Equal(t, "curl", r.Header.Get("User-Agent"))
|
|
|
|
_, err := w.Write([]byte("255.240.85.2"))
|
|
assert.NoError(t, err)
|
|
}))
|
|
defer server.Close()
|
|
|
|
s := Service{url: server.URL}
|
|
|
|
ip, err := s.Lookup()
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, net.IPv4(255, 240, 85, 2), ip)
|
|
}
|