app-init
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResolvePathsMakesLogAbsolute(t *testing.T) {
|
||||
path := writeTempConfig(t, `
|
||||
local_auth:
|
||||
username: root
|
||||
password: x
|
||||
tunnel:
|
||||
url: "https://example.invalid/?token=t"
|
||||
remote:
|
||||
host: mysql
|
||||
username: root
|
||||
password: x
|
||||
options:
|
||||
log_file: logs/tunnel.log
|
||||
`)
|
||||
cfg, err := Load(path, Overrides{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg.ResolvePaths()
|
||||
want := filepath.Join(filepath.Dir(path), "logs", "tunnel.log")
|
||||
if cfg.LogFile != want {
|
||||
t.Fatalf("LogFile=%s want %s", cfg.LogFile, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveConfigPathPrefersExisting(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
p := filepath.Join(dir, "config.yaml")
|
||||
if err := os.WriteFile(p, []byte("x"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := ResolveConfigPath(p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != p && got != filepath.Clean(p) {
|
||||
// Abs may change separators on Windows
|
||||
if filepath.Clean(got) != filepath.Clean(p) {
|
||||
t.Fatalf("got %s", got)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user