mirror of
https://gitlab.com/pnx-tools/dns-updater.git
synced 2026-06-16 05:54:56 +02:00
ip/resolver/basic_http/service_test.go: Adding error tests.
This commit is contained in:
parent
e762ef8dd0
commit
e0a4b6ee95
1 changed files with 31 additions and 0 deletions
|
|
@ -51,3 +51,34 @@ func TestService_Lookup_WithHeaders(t *testing.T) {
|
|||
|
||||
assert.Equal(t, net.IPv4(125, 74, 233, 13), ip)
|
||||
}
|
||||
|
||||
func TestService_Lookup_HTTPError(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(404)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
s := Service{
|
||||
Url: server.URL,
|
||||
}
|
||||
|
||||
ip, err := s.Lookup()
|
||||
assert.EqualError(t, err, "HTTP Response: 404 Not Found")
|
||||
assert.Nil(t, ip)
|
||||
}
|
||||
|
||||
func TestService_Lookup_ParseError(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_, err := w.Write([]byte("random_string"))
|
||||
assert.NoError(t, err)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
s := Service{
|
||||
Url: server.URL,
|
||||
}
|
||||
|
||||
ip, err := s.Lookup()
|
||||
assert.EqualError(t, err, "Failed to parse ip: random_string")
|
||||
assert.Nil(t, ip)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue