34 lines
763 B
Go
34 lines
763 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadDefaultsWhenMissing(t *testing.T) {
|
|
cfg, err := Load("does-not-exist.toml")
|
|
if err != nil {
|
|
t.Fatalf("Load returned error: %v", err)
|
|
}
|
|
if cfg.OSC.Host != "127.0.0.1" || cfg.OSC.Port != 9001 {
|
|
t.Fatalf("unexpected defaults: %+v", cfg.OSC)
|
|
}
|
|
}
|
|
|
|
func TestLoadOSCValues(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "config.toml")
|
|
if err := os.WriteFile(path, []byte("[osc]\nhost = \"0.0.0.0\"\nport = 9002\n"), 0o600); err != nil {
|
|
t.Fatalf("WriteFile: %v", err)
|
|
}
|
|
cfg, err := Load(path)
|
|
if err != nil {
|
|
t.Fatalf("Load returned error: %v", err)
|
|
}
|
|
if cfg.OSC.Host != "0.0.0.0" || cfg.OSC.Port != 9002 {
|
|
t.Fatalf("unexpected values: %+v", cfg.OSC)
|
|
}
|
|
}
|
|
|