mirror of
https://github.com/hhftechnology/middleware-manager.git
synced 2026-07-14 10:28:23 +00:00
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).
34 lines
754 B
Go
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")
|
|
}
|
|
})
|
|
}
|