add unit test

This commit is contained in:
thinkerou 2021-03-27 12:46:46 +08:00
parent 56fbadcde6
commit feaee20a81
2 changed files with 16 additions and 0 deletions

View File

@ -55,6 +55,13 @@ func TestRunEmpty(t *testing.T) {
testRequest(t, "http://localhost:8080/example")
}
func TestTrustedCIDRsForRun(t *testing.T) {
os.Setenv("PORT", "")
router := New()
router.TrustedProxies = []string{"hello/world"}
assert.Error(t, router.Run(":8080"))
}
func TestRunTLS(t *testing.T) {
router := New()
go func() {

View File

@ -647,6 +647,15 @@ func TestPrepareTrustedCIRDsWith(t *testing.T) {
assert.Error(t, err)
}
// nil value
{
r.TrustedProxies = nil
trustedCIDRs, err := r.prepareTrustedCIDRs()
assert.Nil(t, trustedCIDRs)
assert.Nil(t, err)
}
}
func parseCIDR(cidr string) *net.IPNet {