Skip to content

Commit

Permalink
fix: removed fixtures module
Browse files Browse the repository at this point in the history
  • Loading branch information
lansfy committed Sep 14, 2024
1 parent 44052bc commit e37fc44
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 73 deletions.
33 changes: 0 additions & 33 deletions fixtures/loader.go

This file was deleted.

32 changes: 21 additions & 11 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" {
Expand Down
43 changes: 14 additions & 29 deletions runner/runner_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"))
Expand All @@ -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) {
Expand Down

0 comments on commit e37fc44

Please sign in to comment.