From e37fc446ec037463c4e3d87e9c12f002c2cbb637 Mon Sep 17 00:00:00 2001 From: lansfy <5764541+lansfy@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:59:48 -0700 Subject: [PATCH] fix: removed fixtures module --- fixtures/loader.go | 33 ------------------------------ runner/runner.go | 32 ++++++++++++++++++++---------- runner/runner_testing.go | 43 +++++++++++++--------------------------- 3 files changed, 35 insertions(+), 73 deletions(-) delete mode 100644 fixtures/loader.go diff --git a/fixtures/loader.go b/fixtures/loader.go deleted file mode 100644 index 2d239c7..0000000 --- a/fixtures/loader.go +++ /dev/null @@ -1,33 +0,0 @@ -package fixtures - -import ( - "fmt" - - "github.com/lansfy/gonkex/storage" -) - -type Loader interface { - Load(names []string) error -} - -func NewLoader(location string, storages []storage.StorageInterface) Loader { - return &loaderImpl{ - location: location, - storages: storages, - } -} - -type loaderImpl struct { - location string - storages []storage.StorageInterface -} - -func (l *loaderImpl) Load(names []string) error { - for _, s := range l.storages { - err := s.LoadFixtures(l.location, names) - if err != nil { - return fmt.Errorf("load fixtures: %w", err) - } - } - return nil -} diff --git a/runner/runner.go b/runner/runner.go index 79342fb..27eab6e 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -11,21 +11,22 @@ import ( "github.com/lansfy/gonkex/checker" "github.com/lansfy/gonkex/cmd_runner" - "github.com/lansfy/gonkex/fixtures" "github.com/lansfy/gonkex/mocks" "github.com/lansfy/gonkex/models" "github.com/lansfy/gonkex/output" + "github.com/lansfy/gonkex/storage" "github.com/lansfy/gonkex/testloader" "github.com/lansfy/gonkex/variables" ) type Config struct { - Host string - FixturesLoader fixtures.Loader - Mocks *mocks.Mocks - MocksLoader *mocks.Loader - Variables *variables.Variables - HTTPProxyURL *url.URL + Host string + FixturesDir string + Storages []storage.StorageInterface + Mocks *mocks.Mocks + MocksLoader *mocks.Loader + Variables *variables.Variables + HTTPProxyURL *url.URL } type ( @@ -124,10 +125,9 @@ func (r *Runner) executeTest(v models.TestInterface) (*models.Result, error) { r.config.Variables.Load(v.GetCombinedVariables()) v = r.config.Variables.Apply(v) - if r.config.FixturesLoader != nil && v.Fixtures() != nil { - if err := r.config.FixturesLoader.Load(v.Fixtures()); err != nil { - return nil, fmt.Errorf("unable to load fixtures [%s], error:\n%s", strings.Join(v.Fixtures(), ", "), err) - } + err := loadFixtures(r.config.FixturesDir, r.config.Storages, v.Fixtures()) + if err != nil { + return nil, fmt.Errorf("unable to load fixtures [%s], error:\n%s", strings.Join(v.Fixtures(), ", "), err) } // reset mocks @@ -242,6 +242,16 @@ func (r *Runner) setVariablesFromResponse(t models.TestInterface, contentType, b return nil } +func loadFixtures(location string, storages []storage.StorageInterface, names []string) error { + for _, s := range storages { + err := s.LoadFixtures(location, names) + if err != nil { + return fmt.Errorf("load fixtures: %w", err) + } + } + return nil +} + func checkHasFocused(tests []models.TestInterface) bool { for _, test := range tests { if test.GetStatus() == "focus" { diff --git a/runner/runner_testing.go b/runner/runner_testing.go index 91a8b15..25fca73 100644 --- a/runner/runner_testing.go +++ b/runner/runner_testing.go @@ -15,7 +15,6 @@ import ( "github.com/lansfy/gonkex/checker/response_body" "github.com/lansfy/gonkex/checker/response_db" "github.com/lansfy/gonkex/checker/response_header" - "github.com/lansfy/gonkex/fixtures" "github.com/lansfy/gonkex/mocks" "github.com/lansfy/gonkex/models" "github.com/lansfy/gonkex/output" @@ -62,8 +61,6 @@ func RunWithTesting(t *testing.T, server *httptest.Server, opts *RunWithTestingO } } - fixturesLoader := fixtures.NewLoader(opts.FixturesDir, opts.Storages) - var proxyURL *url.URL if os.Getenv("HTTP_PROXY") != "" { httpURL, err := url.Parse(os.Getenv("HTTP_PROXY")) @@ -73,43 +70,31 @@ func RunWithTesting(t *testing.T, server *httptest.Server, opts *RunWithTestingO proxyURL = httpURL } - runner := initRunner(t, server, opts, mocksLoader, fixturesLoader, proxyURL) - - addOutputs(runner, opts) - addCheckers(runner, opts) - - err := runner.Run() - if err != nil { - t.Fatal(err) - } -} - -func initRunner( - t *testing.T, - server *httptest.Server, - opts *RunWithTestingOpts, - mocksLoader *mocks.Loader, - fixturesLoader fixtures.Loader, - proxyURL *url.URL, -) *Runner { yamlLoader := yaml_file.NewLoader(opts.TestsDir) yamlLoader.SetFileFilter(os.Getenv("GONKEX_FILE_FILTER")) handler := testingHandler{t} runner := New( &Config{ - Host: server.URL, - Mocks: opts.Mocks, - MocksLoader: mocksLoader, - FixturesLoader: fixturesLoader, - Variables: variables.New(), - HTTPProxyURL: proxyURL, + Host: server.URL, + Mocks: opts.Mocks, + FixturesDir: opts.FixturesDir, + Storages: opts.Storages, + MocksLoader: mocksLoader, + Variables: variables.New(), + HTTPProxyURL: proxyURL, }, yamlLoader, handler.HandleTest, ) - return runner + addOutputs(runner, opts) + addCheckers(runner, opts) + + err := runner.Run() + if err != nil { + t.Fatal(err) + } } func addOutputs(runner *Runner, opts *RunWithTestingOpts) {