47 lines
1.8 KiB
Go
47 lines
1.8 KiB
Go
package domain
|
|
|
|
import "testing"
|
|
|
|
func TestCloneBackendCopiesDiagnosticMetadataAndProviderValues(t *testing.T) {
|
|
profile := "profile"
|
|
reachabilityEndpoint := "https://probe.example/health"
|
|
authKind := "openrouter_key"
|
|
authEndpoint := "https://probe.example/key"
|
|
backend := Backend{
|
|
ExtraParams: map[string]any{"nested": map[string]any{"value": "original"}},
|
|
SmokeTests: &BackendSmokeTestConfig{
|
|
DefaultProfile: &profile,
|
|
Reachability: &ReachabilityProbeConfig{Endpoint: &reachabilityEndpoint},
|
|
Authentication: &AuthenticationProbeConfig{
|
|
Kind: &authKind,
|
|
Endpoint: &authEndpoint,
|
|
},
|
|
},
|
|
}
|
|
|
|
cloned := CloneBackend(backend)
|
|
*cloned.SmokeTests.DefaultProfile = "changed"
|
|
*cloned.SmokeTests.Reachability.Endpoint = "changed"
|
|
*cloned.SmokeTests.Authentication.Kind = "changed"
|
|
*cloned.SmokeTests.Authentication.Endpoint = "changed"
|
|
cloned.ExtraParams["nested"].(map[string]any)["value"] = "changed"
|
|
|
|
if profile != "profile" || reachabilityEndpoint != "https://probe.example/health" ||
|
|
authKind != "openrouter_key" || authEndpoint != "https://probe.example/key" {
|
|
t.Fatal("cloned diagnostic metadata shared source pointers")
|
|
}
|
|
if got := backend.ExtraParams["nested"].(map[string]any)["value"]; got != "original" {
|
|
t.Fatalf("source provider parameter changed through clone: %v", got)
|
|
}
|
|
}
|
|
|
|
func TestCloneBackendPreservesProviderMapPresence(t *testing.T) {
|
|
if cloned := CloneBackend(Backend{}); cloned.ExtraParams != nil {
|
|
t.Fatalf("nil provider map became %#v", cloned.ExtraParams)
|
|
}
|
|
cloned := CloneBackend(Backend{ExtraParams: map[string]any{"empty": map[string]any{}, "null": nil}})
|
|
if cloned.ExtraParams == nil || cloned.ExtraParams["empty"].(map[string]any) == nil || cloned.ExtraParams["null"] != nil {
|
|
t.Fatalf("provider map presence changed: %#v", cloned.ExtraParams)
|
|
}
|
|
}
|