diff --git a/google.go b/google.go index 38f1507..95eb89f 100644 --- a/google.go +++ b/google.go @@ -32,16 +32,21 @@ func (e *GoogleSearch) String() string { return strings.Join(e.tags, " ") } -// ToURL converts tags to an encoded Google Search URL -func (e *GoogleSearch) ToURL() string { - baseURL, _ := url.Parse(searchURL) - +// QueryValues returns search request as URL values +func (e *GoogleSearch) QueryValues() url.Values { tags := strings.Join(e.tags, " ") params := url.Values{} params.Add("q", tags) - baseURL.RawQuery = params.Encode() + return params +} + +// ToURL converts tags to an encoded Google Search URL +func (e *GoogleSearch) ToURL() string { + baseURL, _ := url.Parse(searchURL) + + baseURL.RawQuery = e.QueryValues().Encode() return baseURL.String() } diff --git a/google_test.go b/google_test.go index 55cf9cc..42b22bb 100644 --- a/google_test.go +++ b/google_test.go @@ -2,6 +2,7 @@ package dorkgen import ( "fmt" + "net/url" "testing" assertion "github.com/stretchr/testify/assert" @@ -147,4 +148,18 @@ func TestInit(t *testing.T) { assert.Equal(result, "site:linkedin.com (intext:\"1\" OR intext:\"2\") intitle:\"jordan\"", "they should be equal") }) + + t.Run("should return URL values", func(t *testing.T) { + dork = NewGoogleSearch() + + result := dork. + Site("linkedin.com"). + Group((NewGoogleSearch()).Intext("1").Or().Intext("2")). + Intitle("jordan"). + QueryValues() + + assert.Equal(url.Values{ + "q": []string{"site:linkedin.com (intext:\"1\" OR intext:\"2\") intitle:\"jordan\""}, + }, result, "they should be equal") + }) }