package main import ( "net/url" "strings" "testing" "github.com/stretchr/testify/assert" "golang.org/x/net/html" ) func TestExtractURLs(t *testing.T) { for _, c := range []struct { html string numURLs int }{ {`Google`, 1}, { `
Google Google
`, 1, }, { `
Google Yahoo!
`, 2, }, } { n, err := html.Parse(strings.NewReader(c.html)) assert.Equal(t, nil, err) assert.Equal(t, c.numURLs, len(extractURLs(n))) } } func TestURLParse(t *testing.T) { u, err := url.Parse("file-path") assert.Equal(t, nil, err) assert.Equal(t, "", u.Scheme) } func TestIsURL(t *testing.T) { for _, s := range []string{"http://google.com", "https://google.com", "file-path"} { assert.True(t, isURL(s)) } for _, s := range []string{"ftp://foo.com", "file://file-path"} { assert.False(t, isURL(s)) } }