2024-07-26 20:02:43 +00:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-07-30 15:27:38 +00:00
|
|
|
"grain/config"
|
2024-07-26 20:02:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfigValidity(t *testing.T) {
|
2024-07-30 15:27:38 +00:00
|
|
|
config, err := config.LoadConfig("../config.yml")
|
2024-07-26 20:02:43 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error loading config: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check MongoDB settings
|
|
|
|
if config.MongoDB.URI == "" {
|
|
|
|
t.Error("MongoDB URI is required")
|
|
|
|
}
|
|
|
|
if config.MongoDB.Database == "" {
|
|
|
|
t.Error("MongoDB database name is required")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check Server settings
|
|
|
|
if config.Server.Port == "" {
|
|
|
|
t.Error("Server port is required")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check Rate Limit settings
|
|
|
|
if config.RateLimit.WsLimit == 0 {
|
|
|
|
t.Error("WebSocket limit is required")
|
|
|
|
}
|
|
|
|
if config.RateLimit.WsBurst == 0 {
|
|
|
|
t.Error("WebSocket burst is required")
|
|
|
|
}
|
|
|
|
if config.RateLimit.EventLimit == 0 {
|
|
|
|
t.Error("Event limit is required")
|
|
|
|
}
|
|
|
|
if config.RateLimit.EventBurst == 0 {
|
|
|
|
t.Error("Event burst is required")
|
|
|
|
}
|
|
|
|
if config.RateLimit.ReqLimit == 0 {
|
|
|
|
t.Error("REQ limit is required")
|
|
|
|
}
|
|
|
|
if config.RateLimit.ReqBurst == 0 {
|
|
|
|
t.Error("REQ burst is required")
|
|
|
|
}
|
2024-07-26 20:46:01 +00:00
|
|
|
if config.RateLimit.MaxEventSize == 0 {
|
|
|
|
t.Error("Global maximum event size is required")
|
|
|
|
}
|
2024-07-26 20:02:43 +00:00
|
|
|
|
|
|
|
// Check Category Limits
|
|
|
|
if len(config.RateLimit.CategoryLimits) == 0 {
|
|
|
|
t.Log("Warning: No category limits set")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check Kind Limits
|
|
|
|
if len(config.RateLimit.KindLimits) == 0 {
|
|
|
|
t.Log("Warning: No kind limits set")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate individual category limits
|
|
|
|
for category, limits := range config.RateLimit.CategoryLimits {
|
|
|
|
if limits.Limit == 0 {
|
|
|
|
t.Errorf("Limit is required for category: %s", category)
|
|
|
|
}
|
|
|
|
if limits.Burst == 0 {
|
|
|
|
t.Errorf("Burst is required for category: %s", category)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate individual kind limits
|
|
|
|
for _, kindLimit := range config.RateLimit.KindLimits {
|
|
|
|
if kindLimit.Limit == 0 {
|
|
|
|
t.Errorf("Limit is required for kind: %d", kindLimit.Kind)
|
|
|
|
}
|
|
|
|
if kindLimit.Burst == 0 {
|
|
|
|
t.Errorf("Burst is required for kind: %d", kindLimit.Kind)
|
|
|
|
}
|
|
|
|
}
|
2024-07-26 20:46:01 +00:00
|
|
|
|
|
|
|
// Validate kind size limits
|
|
|
|
for _, kindSizeLimit := range config.RateLimit.KindSizeLimits {
|
|
|
|
if kindSizeLimit.MaxSize == 0 {
|
|
|
|
t.Errorf("Maximum size is required for kind: %d", kindSizeLimit.Kind)
|
|
|
|
}
|
|
|
|
}
|
2024-07-26 20:02:43 +00:00
|
|
|
}
|