fix: make miro testdir resolution explicit based on config

This commit is contained in:
2026-03-18 12:48:09 +00:00
parent 3949ee98bc
commit 666219edbf
8 changed files with 342 additions and 187 deletions
+25 -6
View File
@@ -1,6 +1,7 @@
package config
import (
"bytes"
"errors"
"fmt"
"os"
@@ -13,10 +14,6 @@ type Config struct {
}
type tomlConfig struct {
Miro tomlMiroConfig `toml:"miro"`
}
type tomlMiroConfig struct {
TestDir string `toml:"test_dir"`
}
@@ -24,15 +21,37 @@ type tomlMiroConfig struct {
func ReadConfig(path string) (Config, error) {
var raw tomlConfig
_, err := toml.DecodeFile(path, &raw)
meta, err := toml.DecodeFile(path, &raw)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return Config{}, err
}
return Config{}, fmt.Errorf("failed to read %s: %v", path, err)
}
if !meta.IsDefined("test_dir") {
return Config{}, fmt.Errorf("failed to read %s: missing required test_dir", path)
}
if raw.TestDir == "" {
return Config{}, fmt.Errorf("failed to read %s: empty test_dir", path)
}
return Config{
TestDir: raw.Miro.TestDir,
TestDir: raw.TestDir,
}, nil
}
// WriteConfig writes miro.toml.
func WriteConfig(path string, cfg Config) error {
if cfg.TestDir == "" {
return errors.New("empty test_dir")
}
var buf bytes.Buffer
if err := toml.NewEncoder(&buf).Encode(tomlConfig{
TestDir: cfg.TestDir,
}); err != nil {
return fmt.Errorf("failed to encode %s: %v", path, err)
}
return os.WriteFile(path, buf.Bytes(), 0o644)
}