nuclei/v2/pkg/utils/utils_test.go
Tarun Koyalwar aee0870617
scanallip handle edge cases (#3080)
* bug fix:remove port during dns resolution

* scanallip fix edge cases

* add scanallips testcases

* workflow fix

* removing pull cmd

* Auto Generate Syntax Docs + JSONSchema [Sat Dec 24 13:29:21 UTC 2022] 🤖

Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
2022-12-24 19:03:23 +05:30

43 lines
956 B
Go

package utils
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestUnwrapError(t *testing.T) {
require.Equal(t, nil, UnwrapError(nil))
errOne := fmt.Errorf("error one")
require.Equal(t, errOne, UnwrapError(errOne))
errTwo := fmt.Errorf("error with error: %w", errOne)
require.Equal(t, errOne, UnwrapError(errTwo))
errThree := fmt.Errorf("error with error: %w", errTwo)
require.Equal(t, errOne, UnwrapError(errThree))
}
func TestParseURL(t *testing.T) {
testcases := []struct {
URL string
Hostname string
}{
{"https://scanme.sh:443", "scanme.sh:443"},
{"http://scanme.sh/path", "scanme.sh"},
{"scanme.sh:443/path", "scanme.sh:443"},
{"scanme.sh/path", "scanme.sh"},
}
for _, v := range testcases {
urlx := ParseHostname(v.URL)
if urlx == "" {
t.Errorf("failed to hostname of url %v", v)
}
if urlx != v.Hostname {
t.Errorf("hostname mismatch expected scanme.sh got %v", urlx)
}
}
}