Skip to content

Commit

Permalink
Require dir for command
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Aug 20, 2024
1 parent 968d3f3 commit 801a59c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
5 changes: 4 additions & 1 deletion internal/configload/configload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 12 additions & 3 deletions internal/configload/configload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func FuzzLoadContent(f *testing.F) {
file string
db string
expected *config.Config
err error
err string
}{
{
file: "command.yml",
Expand All @@ -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 {
Expand Down
20 changes: 14 additions & 6 deletions internal/configload/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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.
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions internal/configload/testdata/command_nodir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
runner: command
params:
tests: []

results: {}

0 comments on commit 801a59c

Please sign in to comment.