feat: testdir resolution
This commit is contained in:
@@ -9,8 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
TestDir string
|
||||
HasTestDir bool
|
||||
TestDir string
|
||||
}
|
||||
|
||||
type tomlConfig struct {
|
||||
@@ -21,11 +20,11 @@ type tomlMiroConfig struct {
|
||||
TestDir string `toml:"test_dir"`
|
||||
}
|
||||
|
||||
// ReadConfig reads miro.toml and reports whether [miro].test_dir was explicitly set.
|
||||
// ReadConfig reads miro.toml.
|
||||
func ReadConfig(path string) (Config, error) {
|
||||
var raw tomlConfig
|
||||
|
||||
meta, err := toml.DecodeFile(path, &raw)
|
||||
_, err := toml.DecodeFile(path, &raw)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return Config{}, err
|
||||
@@ -34,7 +33,6 @@ func ReadConfig(path string) (Config, error) {
|
||||
}
|
||||
|
||||
return Config{
|
||||
TestDir: raw.Miro.TestDir,
|
||||
HasTestDir: meta.IsDefined("miro", "test_dir"),
|
||||
TestDir: raw.Miro.TestDir,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -11,19 +11,16 @@ func TestReadConfig(t *testing.T) {
|
||||
name string
|
||||
content string
|
||||
wantDir string
|
||||
wantHasDir bool
|
||||
wantReadErr bool
|
||||
}{
|
||||
{
|
||||
name: "with test dir",
|
||||
content: "[miro]\ntest_dir = \"custom/suite\"\n",
|
||||
wantDir: "custom/suite",
|
||||
wantHasDir: true,
|
||||
name: "with test dir",
|
||||
content: "[miro]\ntest_dir = \"custom/suite\"\n",
|
||||
wantDir: "custom/suite",
|
||||
},
|
||||
{
|
||||
name: "without test dir",
|
||||
content: "[miro]\n",
|
||||
wantHasDir: false,
|
||||
name: "without test dir",
|
||||
content: "[miro]\n",
|
||||
},
|
||||
{
|
||||
name: "invalid toml",
|
||||
@@ -52,9 +49,6 @@ func TestReadConfig(t *testing.T) {
|
||||
if got.TestDir != tt.wantDir {
|
||||
t.Fatalf("ReadConfig() TestDir = %q, want %q", got.TestDir, tt.wantDir)
|
||||
}
|
||||
if got.HasTestDir != tt.wantHasDir {
|
||||
t.Fatalf("ReadConfig() HasTestDir = %v, want %v", got.HasTestDir, tt.wantHasDir)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user