diff --git a/internal/configload/configload.go b/internal/configload/configload.go index 4c29b4ce..9ea31482 100644 --- a/internal/configload/configload.go +++ b/internal/configload/configload.go @@ -159,7 +159,10 @@ func loadContent(content, db string) (*config.Config, error) { return nil, fmt.Errorf("failed to decode runner parameters: %w", err) } - params := p.convert() + params, err := p.convert() + if err != nil { + return nil, fmt.Errorf("failed to convert runner parameters: %w", err) + } res := pc.Results[db] if res == nil { diff --git a/internal/configload/configload_test.go b/internal/configload/configload_test.go index 3cb1d707..5ee37515 100644 --- a/internal/configload/configload_test.go +++ b/internal/configload/configload_test.go @@ -29,7 +29,7 @@ func FuzzLoadContent(f *testing.F) { file string db string expected *config.Config - err error + err string }{ { file: "command.yml", @@ -55,15 +55,24 @@ func FuzzLoadContent(f *testing.F) { }, }, }, + { + file: "command_nodir.yml", + db: "ferretdb-postgresql", + err: "failed to convert runner parameters: dir is required", + }, } { b, err := os.ReadFile(filepath.Join("testdata", tc.file)) require.NoError(f, err, "file = %s", tc.file) actual, err := loadContent(string(b), tc.db) - if tc.err == nil { + if tc.err == "" { + require.NoError(f, err, "file = %s", tc.file) + require.NotNil(f, actual, "file = %s", tc.file) require.Equal(f, tc.expected, actual, "file = %s", tc.file) } else { - require.Equal(f, tc.err, err, "file = %s", tc.file) + require.Error(f, err, "file = %s", tc.file) + require.EqualError(f, err, tc.err, "file = %s", tc.file) + require.Nil(f, actual, "file = %s", tc.file) } for db := range DBs { diff --git a/internal/configload/runner.go b/internal/configload/runner.go index 34fa877a..0a01b7c8 100644 --- a/internal/configload/runner.go +++ b/internal/configload/runner.go @@ -14,13 +14,17 @@ package configload -import "github.com/FerretDB/dance/internal/config" +import ( + "fmt" + + "github.com/FerretDB/dance/internal/config" +) // runnerParams is common interface for runner parameters. // //sumtype:decl type runnerParams interface { - convert() config.RunnerParams // seal for sumtype + convert() (config.RunnerParams, error) // seal for sumtype } // runnerParamsCommand represents `command` runner parameters in the project configuration YAML file. @@ -34,7 +38,11 @@ type runnerParamsCommand struct { } // convert implements [runnerParams] interface. -func (rp *runnerParamsCommand) convert() config.RunnerParams { +func (rp *runnerParamsCommand) convert() (config.RunnerParams, error) { + if rp.Dir == "" { + return nil, fmt.Errorf("dir is required") + } + res := &config.RunnerParamsCommand{ Dir: rp.Dir, Setup: rp.Setup, @@ -47,7 +55,7 @@ func (rp *runnerParamsCommand) convert() config.RunnerParams { }) } - return res + return res, nil } // runnerParamsGoTest represents `gotest` runner parameters in the project configuration YAML file. @@ -56,10 +64,10 @@ type runnerParamsGoTest struct { } // convert implements [runnerParams] interface. -func (rp *runnerParamsGoTest) convert() config.RunnerParams { +func (rp *runnerParamsGoTest) convert() (config.RunnerParams, error) { return &config.RunnerParamsGoTest{ Args: rp.Args, - } + }, nil } // check interfaces diff --git a/internal/configload/testdata/command_nodir.yml b/internal/configload/testdata/command_nodir.yml new file mode 100644 index 00000000..a6924070 --- /dev/null +++ b/internal/configload/testdata/command_nodir.yml @@ -0,0 +1,6 @@ +--- +runner: command +params: + tests: [] + +results: {}