From 0e457e1eaf5e5f3e6b9b67998fcd23d04d30530e Mon Sep 17 00:00:00 2001 From: sundowndev Date: Mon, 15 Jun 2020 11:00:03 +0200 Subject: [PATCH] feat: create NewGoogleSearch method --- google.go | 4 ++++ google_test.go | 30 +++++++++++++++--------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/google.go b/google.go index b824567..38f1507 100644 --- a/google.go +++ b/google.go @@ -23,6 +23,10 @@ type GoogleSearch struct { EngineFactory } +func NewGoogleSearch() *GoogleSearch { + return &GoogleSearch{} +} + // String converts all tags to a single request func (e *GoogleSearch) String() string { return strings.Join(e.tags, " ") diff --git a/google_test.go b/google_test.go index b2add49..55cf9cc 100644 --- a/google_test.go +++ b/google_test.go @@ -13,7 +13,7 @@ func TestInit(t *testing.T) { assert := assertion.New(t) t.Run("should convert to URL correctly", func(t *testing.T) { - dork = &GoogleSearch{} + dork = NewGoogleSearch() result := dork. Site("example.com"). @@ -23,7 +23,7 @@ func TestInit(t *testing.T) { }) t.Run("should convert to string correctly", func(t *testing.T) { - dork = &GoogleSearch{} + dork = NewGoogleSearch() result := fmt.Sprint(dork.Site("example.com")) @@ -31,7 +31,7 @@ func TestInit(t *testing.T) { }) t.Run("should handle site tag correctly", func(t *testing.T) { - dork = &GoogleSearch{} + dork = NewGoogleSearch() result := dork. Site("example.com"). @@ -41,7 +41,7 @@ func TestInit(t *testing.T) { }) t.Run("should handle intext tag correctly", func(t *testing.T) { - dork = &GoogleSearch{} + dork = NewGoogleSearch() result := dork. Intext("text"). @@ -51,7 +51,7 @@ func TestInit(t *testing.T) { }) t.Run("should handle inurl tag correctly", func(t *testing.T) { - dork = &GoogleSearch{} + dork = NewGoogleSearch() result := dork. Inurl("index.php"). @@ -61,7 +61,7 @@ func TestInit(t *testing.T) { }) t.Run("should handle filetype tag correctly", func(t *testing.T) { - dork = &GoogleSearch{} + dork = NewGoogleSearch() result := dork. Filetype("pdf"). @@ -71,7 +71,7 @@ func TestInit(t *testing.T) { }) t.Run("should handle cache tag correctly", func(t *testing.T) { - dork = &GoogleSearch{} + dork = NewGoogleSearch() result := dork. Cache("www.google.com"). @@ -81,7 +81,7 @@ func TestInit(t *testing.T) { }) t.Run("should handle related tag correctly", func(t *testing.T) { - dork = &GoogleSearch{} + dork = NewGoogleSearch() result := dork. Related("www.google.com"). @@ -91,7 +91,7 @@ func TestInit(t *testing.T) { }) t.Run("should handle ext tag correctly", func(t *testing.T) { - dork = &GoogleSearch{} + dork = NewGoogleSearch() result := dork. Ext("(doc | pdf | xls | txt | xml)"). @@ -101,7 +101,7 @@ func TestInit(t *testing.T) { }) t.Run("should handle exclude tag correctly", func(t *testing.T) { - dork = &GoogleSearch{} + dork = NewGoogleSearch() result := dork. Exclude("html"). @@ -114,7 +114,7 @@ func TestInit(t *testing.T) { }) t.Run("should handle or tag correctly", func(t *testing.T) { - dork = &GoogleSearch{} + dork = NewGoogleSearch() result := dork. Site("facebook.com"). @@ -126,22 +126,22 @@ func TestInit(t *testing.T) { }) t.Run("should handle group tag correctly", func(t *testing.T) { - dork = &GoogleSearch{} + dork = NewGoogleSearch() result := dork. Site("linkedin.com"). - Group((&GoogleSearch{}).Intext("1").Or().Intext("2")). + Group((NewGoogleSearch()).Intext("1").Or().Intext("2")). String() assert.Equal(result, "site:linkedin.com (intext:\"1\" OR intext:\"2\")", "they should be equal") }) t.Run("should handle group tag correctly", func(t *testing.T) { - dork = &GoogleSearch{} + dork = NewGoogleSearch() result := dork. Site("linkedin.com"). - Group((&GoogleSearch{}).Intext("1").Or().Intext("2")). + Group((NewGoogleSearch()).Intext("1").Or().Intext("2")). Intitle("jordan"). String()