54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
|
|
"go.yaml.in/yaml/v3"
|
|
)
|
|
|
|
// ecmallServices is the aggregate registry of pkgs/ecmall. Keep it in sync with
|
|
// the services table in internal/service.
|
|
var ecmallServices = []string{"address", "ads", "cms", "feedback", "fts", "initial", "logs", "mgt", "mall", "market", "order", "passport", "sender", "wallet"}
|
|
|
|
func TestEcmallDevConfig(t *testing.T) {
|
|
data, err := os.ReadFile(filepath.Join("..", "..", "etc", "default_dev.yaml"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var cfg SrvConfig
|
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(cfg.Services) == 0 {
|
|
t.Fatal("services must not be empty")
|
|
}
|
|
if cfg.Server.GRPC.Port == "" || cfg.Server.HTTP.Port == "" || cfg.Server.GRPC.Port == cfg.Server.HTTP.Port {
|
|
t.Fatal("separate gRPC and HTTP ports are required")
|
|
}
|
|
if cfg.Authorization.Key == "" || cfg.Authorization.Expire <= 0 {
|
|
t.Fatal("authorization key and expiration are required")
|
|
}
|
|
keyLength := len(cfg.Authorization.Key)
|
|
if keyLength != 16 && keyLength != 24 && keyLength != 32 {
|
|
t.Fatal("authorization key must be compatible with the JWT issuer")
|
|
}
|
|
if cfg.Fts == nil || cfg.Mgt == nil || cfg.Passport == nil || cfg.Sender == nil || cfg.Wallet == nil {
|
|
t.Fatal("service-specific configuration is incomplete")
|
|
}
|
|
|
|
enabled := make([]string, 0, len(cfg.Services))
|
|
for _, service := range cfg.Services {
|
|
enabled = append(enabled, strings.ToLower(strings.TrimSpace(service)))
|
|
}
|
|
sort.Strings(enabled)
|
|
expected := append([]string(nil), ecmallServices...)
|
|
sort.Strings(expected)
|
|
if strings.Join(enabled, ",") != strings.Join(expected, ",") {
|
|
t.Fatalf("ecmall must only enable %v, got %v", expected, enabled)
|
|
}
|
|
}
|