36 lines
986 B
Go
36 lines
986 B
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestExampleConfigAndSecrets(t *testing.T) {
|
|
t.Setenv("SXCHNGE_NOTIFICATIONS_PRODUCT_TOKEN", strings.Repeat("a", 32))
|
|
c, err := Load("../config.example.yml")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if c.Email.Driver != "resend" || c.Messaging.Driver != "NATS" || c.Database.Driver != "mongodb" {
|
|
t.Fatal("wrong driver configuration")
|
|
}
|
|
t.Setenv("SXCHNGE_NOTIFICATIONS_PRODUCT_TOKEN", "")
|
|
if _, err = Load("../config.example.yml"); err == nil {
|
|
t.Fatal("missing credentials accepted")
|
|
}
|
|
t.Setenv("SXCHNGE_NOTIFICATIONS_PRODUCT_TOKEN", strings.Repeat("a", 32))
|
|
data, err := os.ReadFile("../config.example.yml")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
path := filepath.Join(t.TempDir(), "config.yml")
|
|
if err = os.WriteFile(path, append(data, []byte("\n---\nunexpected: document\n")...), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err = Load(path); err == nil {
|
|
t.Fatal("extra YAML document accepted")
|
|
}
|
|
}
|