60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestApplyFTPSLetsEncryptDefaults(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
cfg := Config{FTPSLEDomain: "files.example.com"}
|
|
applyFTPSLetsEncryptDefaults(&cfg)
|
|
if cfg.FTPSCertFile != "/etc/letsencrypt/live/files.example.com/fullchain.pem" {
|
|
t.Fatalf("unexpected cert path: %q", cfg.FTPSCertFile)
|
|
}
|
|
if cfg.FTPSKeyFile != "/etc/letsencrypt/live/files.example.com/privkey.pem" {
|
|
t.Fatalf("unexpected key path: %q", cfg.FTPSKeyFile)
|
|
}
|
|
}
|
|
|
|
func TestApplyFTPSLetsEncryptDefaultsCustomDirAndPreserveManual(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
cfg := Config{
|
|
FTPSLEDomain: "files.example.com",
|
|
FTPSLEDir: "/var/lib/acme/live",
|
|
FTPSCertFile: "/custom/cert.pem",
|
|
}
|
|
applyFTPSLetsEncryptDefaults(&cfg)
|
|
if cfg.FTPSCertFile != "/custom/cert.pem" {
|
|
t.Fatalf("manual cert should be preserved, got %q", cfg.FTPSCertFile)
|
|
}
|
|
if cfg.FTPSKeyFile != "/var/lib/acme/live/files.example.com/privkey.pem" {
|
|
t.Fatalf("unexpected key path: %q", cfg.FTPSKeyFile)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeOCRLangs(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
in string
|
|
want string
|
|
}{
|
|
{name: "default on empty", in: "", want: "eng+osd"},
|
|
{name: "comma separated", in: "eng, rus, deu", want: "eng+rus+deu"},
|
|
{name: "plus separated", in: "eng+osd+rus", want: "eng+osd+rus"},
|
|
{name: "dedupe and lowercase", in: "ENG + rus + eng", want: "eng+rus"},
|
|
{name: "drops invalid tokens", in: "eng+ru-RU+osd", want: "eng+osd"},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
tc := tc
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
if got := normalizeOCRLangs(tc.in); got != tc.want {
|
|
t.Fatalf("normalizeOCRLangs(%q) = %q, want %q", tc.in, got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|