middleware-manager/models/middleware_test.go
hhftechnologies 516a06a393 Add tests and atomicize service watcher flag
Add extensive unit tests across the codebase (api/errors, cache, many models tests, util/id_normalizer and others) to improve coverage and validate behavior. Replace ServiceWatcher.isRunning bool with atomic.Bool for safer concurrent access, update Start/Stop logic and related imports, and adjust service_watcher_test accordingly. Also update traefik_fetcher_test to use atomic counters for request counting and add minor import changes (sync/atomic).
2026-02-17 16:03:23 +05:30

34 lines
754 B
Go

package models
import (
"testing"
)
func TestMiddleware_ConfigMap(t *testing.T) {
t.Run("valid JSON", func(t *testing.T) {
m := Middleware{Config: `{"key":"value","num":42}`}
cfg, err := m.ConfigMap()
if err != nil {
t.Fatalf("ConfigMap() error = %v", err)
}
if cfg["key"] != "value" {
t.Errorf("cfg[key] = %v, want value", cfg["key"])
}
})
t.Run("invalid JSON", func(t *testing.T) {
m := Middleware{Config: `{invalid`}
_, err := m.ConfigMap()
if err == nil {
t.Error("ConfigMap() should return error for invalid JSON")
}
})
t.Run("empty string", func(t *testing.T) {
m := Middleware{Config: ""}
_, err := m.ConfigMap()
if err == nil {
t.Error("ConfigMap() should return error for empty string")
}
})
}