mirror of
https://github.com/wneessen/go-hibp.git
synced 2024-11-09 15:32:52 +01:00
Better test coverage
This commit is contained in:
parent
f21e27fe8b
commit
77a3b1f3c5
1 changed files with 37 additions and 0 deletions
37
hibp_test.go
37
hibp_test.go
|
@ -2,6 +2,7 @@ package hibp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -72,3 +73,39 @@ func TestNewWithUserAgent(t *testing.T) {
|
||||||
DefaultUserAgent, hc.ua)
|
DefaultUserAgent, hc.ua)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClient_HTTPReq(t *testing.T) {
|
||||||
|
u1 := "this://is.invalid.tld/with/invalid/chars/" + string([]byte{0x7f})
|
||||||
|
u2 := "this://is.invalid.tld/"
|
||||||
|
hc := New()
|
||||||
|
_, err := hc.HTTPReq(http.MethodGet, u1, map[string]string{"foo": "bar"})
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("HTTP GET request was supposed to fail, but didn't")
|
||||||
|
}
|
||||||
|
_, err = hc.HTTPReq("äöü", u2, map[string]string{"foo": "bar"})
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("HTTP GET request was supposed to fail, but didn't")
|
||||||
|
}
|
||||||
|
_, err = hc.HTTPReq("POST", u2, map[string]string{"foo": "bar"})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("HTTP POST request failed: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_HTTPResBody(t *testing.T) {
|
||||||
|
u1 := "this://is.invalid.tld/with/invalid/chars/" + string([]byte{0x7f})
|
||||||
|
u2 := "this://is.invalid.tld/"
|
||||||
|
hc := New()
|
||||||
|
_, _, err := hc.HTTPResBody(http.MethodGet, u1, map[string]string{"foo": "bar"})
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("HTTP GET request was supposed to fail, but didn't")
|
||||||
|
}
|
||||||
|
_, _, err = hc.HTTPResBody("äöü", u2, map[string]string{"foo": "bar"})
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("HTTP GET request was supposed to fail, but didn't")
|
||||||
|
}
|
||||||
|
_, _, err = hc.HTTPResBody("POST", u2, map[string]string{"foo": "bar"})
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("HTTP POST request was supposed to fail, but didn't")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue