diff --git a/src/engines/_engines_test/structs.go b/src/engines/_engines_test/structs.go new file mode 100644 index 00000000..f2f0111a --- /dev/null +++ b/src/engines/_engines_test/structs.go @@ -0,0 +1,34 @@ +package _engines_test + +import ( + "github.com/tminaorg/brzaguza/src/config" + "github.com/tminaorg/brzaguza/src/engines" +) + +type TestCaseHasAnyResults struct { + Query string + Options engines.Options +} + +type TestCaseContainsResults struct { + Query string + ResultURL []string + Options engines.Options +} + +type TestCaseRankedResults struct { + Query string + ResultURL []string + Options engines.Options +} + +func NewConfig(engineName engines.Name) *config.Config { + config.EnabledEngines = append(config.EnabledEngines, engineName) + return &config.Config{ + Engines: map[string]config.Engine{ + engineName.ToLower(): { + Enabled: true, + }, + }, + } +} diff --git a/src/engines/_engines_test/tester.go b/src/engines/_engines_test/tester.go new file mode 100644 index 00000000..f6858311 --- /dev/null +++ b/src/engines/_engines_test/tester.go @@ -0,0 +1,59 @@ +package _engines_test + +import ( + "strings" + "testing" + + "github.com/tminaorg/brzaguza/src/config" + "github.com/tminaorg/brzaguza/src/search" +) + +func CheckTestCases(tchar []TestCaseHasAnyResults, tccr []TestCaseContainsResults, + tcrr []TestCaseRankedResults, t *testing.T, conf *config.Config) { + + // TestCaseHasAnyResults + for _, tc := range tchar { + if results := search.PerformSearch(tc.Query, tc.Options, conf); len(results) == 0 { + defer t.Errorf("Got no results for %v", tc.Query) + } + } + + // TestCaseContainsResults + for _, tc := range tccr { + results := search.PerformSearch(tc.Query, tc.Options, conf) + if len(results) == 0 { + defer t.Errorf("Got no results for %v", tc.Query) + } else { + for _, rURL := range tc.ResultURL { + found := false + + for _, r := range results { + if strings.Contains(r.URL, rURL) { + found = true + break + } + } + + if !found { + defer t.Errorf("Couldn't find %v (%v)", rURL, tc.Query) + } + } + } + } + + // TestCaseRankedResults + for _, tc := range tcrr { + results := search.PerformSearch(tc.Query, tc.Options, conf) + if len(results) == 0 { + defer t.Errorf("Got no results for %v", tc.Query) + } else if len(results) < len(tc.ResultURL) { + defer t.Errorf("Number of results is less than test case URLs.") + } else { + for i, rURL := range tc.ResultURL { + if !strings.Contains(results[i].URL, rURL) { + defer t.Errorf("Wrong result on position %v: %v (%v)", i, rURL, tc.Query) + } + } + } + } +} diff --git a/src/engines/bing/bing.go b/src/engines/bing/bing.go index 2c446676..b9b45802 100644 --- a/src/engines/bing/bing.go +++ b/src/engines/bing/bing.go @@ -19,6 +19,9 @@ func Search(ctx context.Context, query string, relay *bucket.Relay, options engi return err } + // Removes Telemetry. Acknowladge this overwrite user-side. + options.UserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" + var col *colly.Collector var pagesCol *colly.Collector var retError error diff --git a/src/engines/bing/bing_test.go b/src/engines/bing/bing_test.go index 42110de2..f8bcd492 100644 --- a/src/engines/bing/bing_test.go +++ b/src/engines/bing/bing_test.go @@ -3,44 +3,46 @@ package bing_test import ( "testing" - "github.com/tminaorg/brzaguza/src/config" "github.com/tminaorg/brzaguza/src/engines" - "github.com/tminaorg/brzaguza/src/search" + "github.com/tminaorg/brzaguza/src/engines/_engines_test" ) -type TestCase struct { - query string - options engines.Options -} - func TestSearch(t *testing.T) { engineName := engines.Bing // testing config - conf := config.Config{ - Engines: map[string]config.Engine{ - engineName.ToLower(): { - Enabled: true, - }, + conf := _engines_test.NewConfig(engineName) + + // test cases + tchar := [...]_engines_test.TestCaseHasAnyResults{{ + Query: "ping", + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, }, - } + }} - // enabled engines names - config.EnabledEngines = append(config.EnabledEngines, engineName) + //tccr := [...]_engines_test.TestCaseContainsResults{} + //tcrr := [...]_engines_test.TestCaseRankedResults{} - // test cases - testCases := [...]TestCase{{ - query: "wikipedia", - options: engines.Options{ + //bing has hard telemetry links, solved by UA overwrite + tccr := [...]_engines_test.TestCaseContainsResults{{ + Query: "facebook", + ResultURL: []string{"facebook.com"}, + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} + + tcrr := [...]_engines_test.TestCaseRankedResults{{ + Query: "wikipedia", + ResultURL: []string{"wikipedia."}, + Options: engines.Options{ MaxPages: 1, VisitPages: false, }, }} - // running tests - for _, tc := range testCases { - if results := search.PerformSearch(tc.query, tc.options, &conf); len(results) == 0 { - t.Errorf("Got no results for %v", tc.query) - } - } + _engines_test.CheckTestCases(tchar[:], tccr[:], tcrr[:], t, conf) } diff --git a/src/engines/brave/brave_test.go b/src/engines/brave/brave_test.go index 5b0dd1f0..738ffc0e 100644 --- a/src/engines/brave/brave_test.go +++ b/src/engines/brave/brave_test.go @@ -3,44 +3,42 @@ package brave_test import ( "testing" - "github.com/tminaorg/brzaguza/src/config" "github.com/tminaorg/brzaguza/src/engines" - "github.com/tminaorg/brzaguza/src/search" + "github.com/tminaorg/brzaguza/src/engines/_engines_test" ) -type TestCase struct { - query string - options engines.Options -} - func TestSearch(t *testing.T) { engineName := engines.Brave // testing config - conf := config.Config{ - Engines: map[string]config.Engine{ - engineName.ToLower(): { - Enabled: true, - }, + conf := _engines_test.NewConfig(engineName) + + // test cases + tchar := [...]_engines_test.TestCaseHasAnyResults{{ + Query: "ping", + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, }, - } + }} - // enabled engines names - config.EnabledEngines = append(config.EnabledEngines, engineName) + tccr := [...]_engines_test.TestCaseContainsResults{{ + Query: "facebook", + ResultURL: []string{"facebook.com"}, + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} - // test cases - testCases := [...]TestCase{{ - query: "wikipedia", - options: engines.Options{ + tcrr := [...]_engines_test.TestCaseRankedResults{{ + Query: "wikipedia", + ResultURL: []string{"wikipedia."}, + Options: engines.Options{ MaxPages: 1, VisitPages: false, }, }} - // running tests - for _, tc := range testCases { - if results := search.PerformSearch(tc.query, tc.options, &conf); len(results) == 0 { - t.Errorf("Got no results for %v", tc.query) - } - } + _engines_test.CheckTestCases(tchar[:], tccr[:], tcrr[:], t, conf) } diff --git a/src/engines/duckduckgo/duckduckgo_test.go b/src/engines/duckduckgo/duckduckgo_test.go index c53e0aca..b94b2200 100644 --- a/src/engines/duckduckgo/duckduckgo_test.go +++ b/src/engines/duckduckgo/duckduckgo_test.go @@ -3,44 +3,42 @@ package duckduckgo_test import ( "testing" - "github.com/tminaorg/brzaguza/src/config" "github.com/tminaorg/brzaguza/src/engines" - "github.com/tminaorg/brzaguza/src/search" + "github.com/tminaorg/brzaguza/src/engines/_engines_test" ) -type TestCase struct { - query string - options engines.Options -} - func TestSearch(t *testing.T) { engineName := engines.DuckDuckGo // testing config - conf := config.Config{ - Engines: map[string]config.Engine{ - engineName.ToLower(): { - Enabled: true, - }, + conf := _engines_test.NewConfig(engineName) + + // test cases + tchar := [...]_engines_test.TestCaseHasAnyResults{{ + Query: "ping", + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, }, - } + }} - // enabled engines names - config.EnabledEngines = append(config.EnabledEngines, engineName) + tccr := [...]_engines_test.TestCaseContainsResults{{ + Query: "facebook", + ResultURL: []string{"facebook.com"}, + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} - // test cases - testCases := [...]TestCase{{ - query: "wikipedia", - options: engines.Options{ + tcrr := [...]_engines_test.TestCaseRankedResults{{ + Query: "wikipedia", + ResultURL: []string{"wikipedia."}, + Options: engines.Options{ MaxPages: 1, VisitPages: false, }, }} - // running tests - for _, tc := range testCases { - if results := search.PerformSearch(tc.query, tc.options, &conf); len(results) == 0 { - t.Errorf("Got no results for %v", tc.query) - } - } + _engines_test.CheckTestCases(tchar[:], tccr[:], tcrr[:], t, conf) } diff --git a/src/engines/etools/etools_test.go b/src/engines/etools/etools_test.go index b59cc074..b96706a3 100644 --- a/src/engines/etools/etools_test.go +++ b/src/engines/etools/etools_test.go @@ -3,44 +3,42 @@ package etools_test import ( "testing" - "github.com/tminaorg/brzaguza/src/config" "github.com/tminaorg/brzaguza/src/engines" - "github.com/tminaorg/brzaguza/src/search" + "github.com/tminaorg/brzaguza/src/engines/_engines_test" ) -type TestCase struct { - query string - options engines.Options -} - func TestSearch(t *testing.T) { engineName := engines.Etools // testing config - conf := config.Config{ - Engines: map[string]config.Engine{ - engineName.ToLower(): { - Enabled: true, - }, + conf := _engines_test.NewConfig(engineName) + + // test cases + tchar := [...]_engines_test.TestCaseHasAnyResults{{ + Query: "ping", + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, }, - } + }} - // enabled engines names - config.EnabledEngines = append(config.EnabledEngines, engineName) + tccr := [...]_engines_test.TestCaseContainsResults{{ + Query: "facebook", + ResultURL: []string{"facebook.com"}, + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} - // test cases - testCases := [...]TestCase{{ - query: "wikipedia", - options: engines.Options{ + tcrr := [...]_engines_test.TestCaseRankedResults{{ + Query: "wikipedia", + ResultURL: []string{"wikipedia."}, + Options: engines.Options{ MaxPages: 1, VisitPages: false, }, }} - // running tests - for _, tc := range testCases { - if results := search.PerformSearch(tc.query, tc.options, &conf); len(results) == 0 { - t.Errorf("Got no results for %v", tc.query) - } - } + _engines_test.CheckTestCases(tchar[:], tccr[:], tcrr[:], t, conf) } diff --git a/src/engines/google/google_test.go b/src/engines/google/google_test.go index a11b492c..7f1b85b8 100644 --- a/src/engines/google/google_test.go +++ b/src/engines/google/google_test.go @@ -3,44 +3,42 @@ package google_test import ( "testing" - "github.com/tminaorg/brzaguza/src/config" "github.com/tminaorg/brzaguza/src/engines" - "github.com/tminaorg/brzaguza/src/search" + "github.com/tminaorg/brzaguza/src/engines/_engines_test" ) -type TestCase struct { - query string - options engines.Options -} - func TestSearch(t *testing.T) { engineName := engines.Google // testing config - conf := config.Config{ - Engines: map[string]config.Engine{ - engineName.ToLower(): { - Enabled: true, - }, + conf := _engines_test.NewConfig(engineName) + + // test cases + tchar := [...]_engines_test.TestCaseHasAnyResults{{ + Query: "ping", + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, }, - } + }} - // enabled engines names - config.EnabledEngines = append(config.EnabledEngines, engineName) + tccr := [...]_engines_test.TestCaseContainsResults{{ + Query: "facebook", + ResultURL: []string{"facebook.com"}, + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} - // test cases - testCases := [...]TestCase{{ - query: "wikipedia", - options: engines.Options{ + tcrr := [...]_engines_test.TestCaseRankedResults{{ + Query: "wikipedia", + ResultURL: []string{"wikipedia."}, + Options: engines.Options{ MaxPages: 1, VisitPages: false, }, }} - // running tests - for _, tc := range testCases { - if results := search.PerformSearch(tc.query, tc.options, &conf); len(results) == 0 { - t.Errorf("Got no results for %v", tc.query) - } - } + _engines_test.CheckTestCases(tchar[:], tccr[:], tcrr[:], t, conf) } diff --git a/src/engines/mojeek/mojeek_test.go b/src/engines/mojeek/mojeek_test.go index 8772a3f8..d7587201 100644 --- a/src/engines/mojeek/mojeek_test.go +++ b/src/engines/mojeek/mojeek_test.go @@ -3,44 +3,42 @@ package mojeek_test import ( "testing" - "github.com/tminaorg/brzaguza/src/config" "github.com/tminaorg/brzaguza/src/engines" - "github.com/tminaorg/brzaguza/src/search" + "github.com/tminaorg/brzaguza/src/engines/_engines_test" ) -type TestCase struct { - query string - options engines.Options -} - func TestSearch(t *testing.T) { engineName := engines.Mojeek // testing config - conf := config.Config{ - Engines: map[string]config.Engine{ - engineName.ToLower(): { - Enabled: true, - }, + conf := _engines_test.NewConfig(engineName) + + // test cases + tchar := [...]_engines_test.TestCaseHasAnyResults{{ + Query: "ping", + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, }, - } + }} - // enabled engines names - config.EnabledEngines = append(config.EnabledEngines, engineName) + tccr := [...]_engines_test.TestCaseContainsResults{{ + Query: "facebook", + ResultURL: []string{"facebook.com"}, + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} - // test cases - testCases := [...]TestCase{{ - query: "wikipedia", - options: engines.Options{ + tcrr := [...]_engines_test.TestCaseRankedResults{{ + Query: "wikipedia", + ResultURL: []string{"wikipedia."}, + Options: engines.Options{ MaxPages: 1, VisitPages: false, }, }} - // running tests - for _, tc := range testCases { - if results := search.PerformSearch(tc.query, tc.options, &conf); len(results) == 0 { - t.Errorf("Got no results for %v", tc.query) - } - } + _engines_test.CheckTestCases(tchar[:], tccr[:], tcrr[:], t, conf) } diff --git a/src/engines/presearch/presearch_test.go b/src/engines/presearch/presearch_test.go index 6eb4160f..a8729712 100644 --- a/src/engines/presearch/presearch_test.go +++ b/src/engines/presearch/presearch_test.go @@ -3,44 +3,42 @@ package presearch_test import ( "testing" - "github.com/tminaorg/brzaguza/src/config" "github.com/tminaorg/brzaguza/src/engines" - "github.com/tminaorg/brzaguza/src/search" + "github.com/tminaorg/brzaguza/src/engines/_engines_test" ) -type TestCase struct { - query string - options engines.Options -} - func TestSearch(t *testing.T) { engineName := engines.Presearch // testing config - conf := config.Config{ - Engines: map[string]config.Engine{ - engineName.ToLower(): { - Enabled: true, - }, + conf := _engines_test.NewConfig(engineName) + + // test cases + tchar := [...]_engines_test.TestCaseHasAnyResults{{ + Query: "ping", + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, }, - } + }} - // enabled engines names - config.EnabledEngines = append(config.EnabledEngines, engineName) + tccr := [...]_engines_test.TestCaseContainsResults{{ + Query: "facebook", + ResultURL: []string{"facebook.com"}, + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} - // test cases - testCases := [...]TestCase{{ - query: "wikipedia", - options: engines.Options{ + tcrr := [...]_engines_test.TestCaseRankedResults{{ + Query: "wikipedia", + ResultURL: []string{"wikipedia."}, + Options: engines.Options{ MaxPages: 1, VisitPages: false, }, }} - // running tests - for _, tc := range testCases { - if results := search.PerformSearch(tc.query, tc.options, &conf); len(results) == 0 { - t.Errorf("Got no results for %v", tc.query) - } - } + _engines_test.CheckTestCases(tchar[:], tccr[:], tcrr[:], t, conf) } diff --git a/src/engines/qwant/qwant_test.go b/src/engines/qwant/qwant_test.go index 657ecca3..fc28a4f0 100644 --- a/src/engines/qwant/qwant_test.go +++ b/src/engines/qwant/qwant_test.go @@ -3,44 +3,42 @@ package qwant_test import ( "testing" - "github.com/tminaorg/brzaguza/src/config" "github.com/tminaorg/brzaguza/src/engines" - "github.com/tminaorg/brzaguza/src/search" + "github.com/tminaorg/brzaguza/src/engines/_engines_test" ) -type TestCase struct { - query string - options engines.Options -} - func TestSearch(t *testing.T) { engineName := engines.Qwant // testing config - conf := config.Config{ - Engines: map[string]config.Engine{ - engineName.ToLower(): { - Enabled: true, - }, + conf := _engines_test.NewConfig(engineName) + + // test cases + tchar := [...]_engines_test.TestCaseHasAnyResults{{ + Query: "ping", + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, }, - } + }} - // enabled engines names - config.EnabledEngines = append(config.EnabledEngines, engineName) + tccr := [...]_engines_test.TestCaseContainsResults{{ + Query: "facebook", + ResultURL: []string{"facebook.com"}, + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} - // test cases - testCases := [...]TestCase{{ - query: "wikipedia", - options: engines.Options{ + tcrr := [...]_engines_test.TestCaseRankedResults{{ + Query: "wikipedia", + ResultURL: []string{"wikipedia."}, + Options: engines.Options{ MaxPages: 1, VisitPages: false, }, }} - // running tests - for _, tc := range testCases { - if results := search.PerformSearch(tc.query, tc.options, &conf); len(results) == 0 { - t.Errorf("Got no results for %v", tc.query) - } - } + _engines_test.CheckTestCases(tchar[:], tccr[:], tcrr[:], t, conf) } diff --git a/src/engines/startpage/startpage.go b/src/engines/startpage/startpage.go index de3b0fc6..1e6a8ce9 100644 --- a/src/engines/startpage/startpage.go +++ b/src/engines/startpage/startpage.go @@ -14,8 +14,6 @@ import ( "github.com/tminaorg/brzaguza/src/sedefaults" ) -const useSafeSearch bool = false - func Search(ctx context.Context, query string, relay *bucket.Relay, options engines.Options, settings config.Settings) error { if err := sedefaults.Prepare(Info.Name, &options, &settings, &Support, &Info, &ctx); err != nil { return err diff --git a/src/engines/startpage/startpage_test.go b/src/engines/startpage/startpage_test.go index 7e7b2fd4..ae7fb93b 100644 --- a/src/engines/startpage/startpage_test.go +++ b/src/engines/startpage/startpage_test.go @@ -3,44 +3,48 @@ package startpage_test import ( "testing" - "github.com/tminaorg/brzaguza/src/config" "github.com/tminaorg/brzaguza/src/engines" - "github.com/tminaorg/brzaguza/src/search" + "github.com/tminaorg/brzaguza/src/engines/_engines_test" ) -type TestCase struct { - query string - options engines.Options -} - func TestSearch(t *testing.T) { engineName := engines.Startpage // testing config - conf := config.Config{ - Engines: map[string]config.Engine{ - engineName.ToLower(): { - Enabled: true, - }, - }, - } - - // enabled engines names - config.EnabledEngines = append(config.EnabledEngines, engineName) + conf := _engines_test.NewConfig(engineName) // test cases - testCases := [...]TestCase{{ - query: "wikipedia", - options: engines.Options{ - MaxPages: 1, - VisitPages: false, - }, - }} - - // running tests - for _, tc := range testCases { - if results := search.PerformSearch(tc.query, tc.options, &conf); len(results) == 0 { - t.Errorf("Got no results for %v", tc.query) - } - } + tchar := [...]_engines_test.TestCaseHasAnyResults{} + tccr := [...]_engines_test.TestCaseContainsResults{} + tcrr := [...]_engines_test.TestCaseRankedResults{} + + /* + tchar := [...]_engines_test.TestCaseHasAnyResults{{ + Query: "ping", + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} + + tccr := [...]_engines_test.TestCaseContainsResults{{ + Query: "facebook", + ResultURL: []string{"facebook.com"}, + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} + + tcrr := [...]_engines_test.TestCaseRankedResults{{ + Query: "wikipedia", + ResultURL: []string{"wikipedia."}, + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} + */ + + _engines_test.CheckTestCases(tchar[:], tccr[:], tcrr[:], t, conf) } diff --git a/src/engines/swisscows/swisscows_test.go b/src/engines/swisscows/swisscows_test.go index b61094fe..264ee20c 100644 --- a/src/engines/swisscows/swisscows_test.go +++ b/src/engines/swisscows/swisscows_test.go @@ -3,44 +3,42 @@ package swisscows_test import ( "testing" - "github.com/tminaorg/brzaguza/src/config" "github.com/tminaorg/brzaguza/src/engines" - "github.com/tminaorg/brzaguza/src/search" + "github.com/tminaorg/brzaguza/src/engines/_engines_test" ) -type TestCase struct { - query string - options engines.Options -} - func TestSearch(t *testing.T) { engineName := engines.Swisscows // testing config - conf := config.Config{ - Engines: map[string]config.Engine{ - engineName.ToLower(): { - Enabled: true, - }, + conf := _engines_test.NewConfig(engineName) + + // test cases + tchar := [...]_engines_test.TestCaseHasAnyResults{{ + Query: "ping", + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, }, - } + }} - // enabled engines names - config.EnabledEngines = append(config.EnabledEngines, engineName) + tccr := [...]_engines_test.TestCaseContainsResults{{ + Query: "facebook", + ResultURL: []string{"facebook.com"}, + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} - // test cases - testCases := [...]TestCase{{ - query: "wikipedia", - options: engines.Options{ + tcrr := [...]_engines_test.TestCaseRankedResults{{ + Query: "wikipedia", + ResultURL: []string{"wikipedia."}, + Options: engines.Options{ MaxPages: 1, VisitPages: false, }, }} - // running tests - for _, tc := range testCases { - if results := search.PerformSearch(tc.query, tc.options, &conf); len(results) == 0 { - t.Errorf("Got no results for %v", tc.query) - } - } + _engines_test.CheckTestCases(tchar[:], tccr[:], tcrr[:], t, conf) } diff --git a/src/engines/yahoo/yahoo_test.go b/src/engines/yahoo/yahoo_test.go index 270fde42..31fa0ac6 100644 --- a/src/engines/yahoo/yahoo_test.go +++ b/src/engines/yahoo/yahoo_test.go @@ -3,44 +3,42 @@ package yahoo_test import ( "testing" - "github.com/tminaorg/brzaguza/src/config" "github.com/tminaorg/brzaguza/src/engines" - "github.com/tminaorg/brzaguza/src/search" + "github.com/tminaorg/brzaguza/src/engines/_engines_test" ) -type TestCase struct { - query string - options engines.Options -} - func TestSearch(t *testing.T) { engineName := engines.Yahoo // testing config - conf := config.Config{ - Engines: map[string]config.Engine{ - engineName.ToLower(): { - Enabled: true, - }, + conf := _engines_test.NewConfig(engineName) + + // test cases + tchar := [...]_engines_test.TestCaseHasAnyResults{{ + Query: "ping", + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, }, - } + }} - // enabled engines names - config.EnabledEngines = append(config.EnabledEngines, engineName) + tccr := [...]_engines_test.TestCaseContainsResults{{ + Query: "facebook", + ResultURL: []string{"facebook.com"}, + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} - // test cases - testCases := [...]TestCase{{ - query: "wikipedia", - options: engines.Options{ + tcrr := [...]_engines_test.TestCaseRankedResults{{ + Query: "wikipedia", + ResultURL: []string{"wikipedia."}, + Options: engines.Options{ MaxPages: 1, VisitPages: false, }, }} - // running tests - for _, tc := range testCases { - if results := search.PerformSearch(tc.query, tc.options, &conf); len(results) == 0 { - t.Errorf("Got no results for %v", tc.query) - } - } + _engines_test.CheckTestCases(tchar[:], tccr[:], tcrr[:], t, conf) } diff --git a/src/engines/yep/yep_test.go b/src/engines/yep/yep_test.go index 0625a516..a8cdc15b 100644 --- a/src/engines/yep/yep_test.go +++ b/src/engines/yep/yep_test.go @@ -3,44 +3,42 @@ package yep_test import ( "testing" - "github.com/tminaorg/brzaguza/src/config" "github.com/tminaorg/brzaguza/src/engines" - "github.com/tminaorg/brzaguza/src/search" + "github.com/tminaorg/brzaguza/src/engines/_engines_test" ) -type TestCase struct { - query string - options engines.Options -} - func TestSearch(t *testing.T) { engineName := engines.Yep // testing config - conf := config.Config{ - Engines: map[string]config.Engine{ - engineName.ToLower(): { - Enabled: true, - }, + conf := _engines_test.NewConfig(engineName) + + // test cases + tchar := [...]_engines_test.TestCaseHasAnyResults{{ + Query: "ping", + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, }, - } + }} - // enabled engines names - config.EnabledEngines = append(config.EnabledEngines, engineName) + tccr := [...]_engines_test.TestCaseContainsResults{{ + Query: "youtube", + ResultURL: []string{"youtube.com"}, + Options: engines.Options{ + MaxPages: 1, + VisitPages: false, + }, + }} - // test cases - testCases := [...]TestCase{{ - query: "wikipedia", - options: engines.Options{ + tcrr := [...]_engines_test.TestCaseRankedResults{{ + Query: "wikipedia", + ResultURL: []string{"wikipedia."}, + Options: engines.Options{ MaxPages: 1, VisitPages: false, }, }} - // running tests - for _, tc := range testCases { - if results := search.PerformSearch(tc.query, tc.options, &conf); len(results) == 0 { - t.Errorf("Got no results for %v", tc.query) - } - } + _engines_test.CheckTestCases(tchar[:], tccr[:], tcrr[:], t, conf) }