65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadValid(t *testing.T) {
|
|
content := `
|
|
[server]
|
|
listen_addr = ":8443"
|
|
tls_cert = "cert.pem"
|
|
tls_key = "key.pem"
|
|
|
|
[database]
|
|
path = "test.db"
|
|
|
|
[mcias]
|
|
server_url = "https://mcias.example.com"
|
|
`
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "test.toml")
|
|
_ = os.WriteFile(path, []byte(content), 0600)
|
|
|
|
cfg, err := Load(path)
|
|
if err != nil {
|
|
t.Fatalf("Load: %v", err)
|
|
}
|
|
if cfg.Server.ListenAddr != ":8443" {
|
|
t.Errorf("ListenAddr: got %q", cfg.Server.ListenAddr)
|
|
}
|
|
if cfg.Seal.Argon2Time != 3 {
|
|
t.Errorf("Argon2Time default: got %d, want 3", cfg.Seal.Argon2Time)
|
|
}
|
|
if cfg.Seal.Argon2Memory != 128*1024 {
|
|
t.Errorf("Argon2Memory default: got %d", cfg.Seal.Argon2Memory)
|
|
}
|
|
if cfg.Log.Level != "info" {
|
|
t.Errorf("Log.Level default: got %q", cfg.Log.Level)
|
|
}
|
|
}
|
|
|
|
func TestLoadMissingRequired(t *testing.T) {
|
|
content := `
|
|
[server]
|
|
listen_addr = ":8443"
|
|
`
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "test.toml")
|
|
_ = os.WriteFile(path, []byte(content), 0600)
|
|
|
|
_, err := Load(path)
|
|
if err == nil {
|
|
t.Fatal("expected error for missing required fields")
|
|
}
|
|
}
|
|
|
|
func TestLoadMissingFile(t *testing.T) {
|
|
_, err := Load("/nonexistent/path.toml")
|
|
if err == nil {
|
|
t.Fatal("expected error for missing file")
|
|
}
|
|
}
|