@@ -7,6 +7,12 @@ import (
77 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
88)
99
10+ func TestAIServiceDeepCopy_Nil (t * testing.T ) {
11+ var svc * AIService
12+ assert .Nil (t , svc .DeepCopy ())
13+ assert .Nil (t , svc .DeepCopyObject ())
14+ }
15+
1016func TestDeepCopyRoundtrip (t * testing.T ) {
1117 original := & AIService {
1218 ObjectMeta : metav1.ObjectMeta {
@@ -32,4 +38,142 @@ func TestDeepCopyRoundtrip(t *testing.T) {
3238 copied := original .DeepCopy ()
3339 assert .Equal (t , original , copied )
3440 assert .NotSame (t , original , copied )
41+ }
42+
43+ func TestAIServiceDeepCopy_WithAuth (t * testing.T ) {
44+ svc := & AIService {
45+ ObjectMeta : metav1.ObjectMeta {Name : "openai-gpt4" , Namespace : "default" },
46+ Spec : AIServiceSpec {
47+ Provider : "openai" ,
48+ Format : "openai" ,
49+ Model : "gpt-4o" ,
50+ Auth : AIServiceAuth {
51+ Type : "apiKey" ,
52+ Secret : "openai-secret" ,
53+ Key : "Authorization" ,
54+ Header : "api.openai.com" ,
55+ },
56+ Timeout : "30s" ,
57+ },
58+ }
59+ copied := svc .DeepCopy ()
60+ assert .Equal (t , svc .Spec .Auth .Type , copied .Spec .Auth .Type )
61+ assert .Equal (t , svc .Spec .Provider , copied .Spec .Provider )
62+ assert .NotSame (t , svc , copied )
63+ }
64+
65+ func TestAIServiceDeepCopy_WithObservability (t * testing.T ) {
66+ svc := & AIService {
67+ ObjectMeta : metav1.ObjectMeta {Name : "with-obs" , Namespace : "default" },
68+ Spec : AIServiceSpec {
69+ Provider : "anthropic" ,
70+ Model : "claude-3" ,
71+ Observability : AIObservabilityConfig {
72+ Langfuse : LangfuseConfig {
73+ Host : "https://cloud.langfuse.com" ,
74+ PublicKey : "pk-xxx" ,
75+ SecretKey : "sk-xxx" ,
76+ },
77+ OTel : OTelConfig {
78+ Endpoint : "http://otel-collector:4317" ,
79+ ServiceName : "ai-gateway" ,
80+ },
81+ },
82+ },
83+ }
84+ copied := svc .DeepCopy ()
85+ assert .Equal (t , svc .Spec .Observability .Langfuse .Host , copied .Spec .Observability .Langfuse .Host )
86+ assert .Equal (t , svc .Spec .Observability .OTel .Endpoint , copied .Spec .Observability .OTel .Endpoint )
87+ }
88+
89+ func TestAIServiceDeepCopy_WithRetry (t * testing.T ) {
90+ svc := & AIService {
91+ ObjectMeta : metav1.ObjectMeta {Name : "with-retry" , Namespace : "default" },
92+ Spec : AIServiceSpec {
93+ Provider : "openai" ,
94+ Model : "gpt-4o" ,
95+ Retry : AIRetryConfig {
96+ MaxRetries : 3 ,
97+ Backoff : "exponential" ,
98+ },
99+ },
100+ }
101+ copied := svc .DeepCopy ()
102+ assert .Equal (t , uint32 (3 ), copied .Spec .Retry .MaxRetries )
103+ }
104+
105+ func TestAIServiceListDeepCopy (t * testing.T ) {
106+ list := & AIServiceList {
107+ Items : []AIService {
108+ {ObjectMeta : metav1.ObjectMeta {Name : "svc1" , Namespace : "ns1" }, Spec : AIServiceSpec {Provider : "openai" , Model : "gpt-4o" }},
109+ {ObjectMeta : metav1.ObjectMeta {Name : "svc2" , Namespace : "ns2" }, Spec : AIServiceSpec {Provider : "anthropic" , Model : "claude-3" }},
110+ },
111+ }
112+ copied := list .DeepCopy ()
113+ assert .Equal (t , 2 , len (copied .Items ))
114+ assert .Equal (t , list .Items [0 ].Name , copied .Items [0 ].Name )
115+ }
116+
117+ func TestAIServiceListDeepCopy_Nil (t * testing.T ) {
118+ var list * AIServiceList
119+ assert .Nil (t , list .DeepCopy ())
120+ assert .Nil (t , list .DeepCopyObject ())
121+ }
122+
123+ func TestAIServiceDeepCopyInto (t * testing.T ) {
124+ src := & AIService {
125+ ObjectMeta : metav1.ObjectMeta {Name : "src" , Namespace : "ns" },
126+ Spec : AIServiceSpec {
127+ Provider : "openai" ,
128+ Model : "gpt-4o" ,
129+ Auth : AIServiceAuth {Type : "apiKey" , Secret : "s" , Key : "k" , Header : "h" },
130+ Timeout : "60s" ,
131+ Retry : AIRetryConfig {MaxRetries : 5 , Backoff : "linear" },
132+ },
133+ }
134+ dst := & AIService {}
135+ src .DeepCopyInto (dst )
136+ assert .Equal (t , "src" , dst .Name )
137+ assert .Equal (t , "openai" , dst .Spec .Provider )
138+ assert .Equal (t , uint32 (5 ), dst .Spec .Retry .MaxRetries )
139+ }
140+
141+ func TestAIServiceSpecDeepCopy (t * testing.T ) {
142+ spec := & AIServiceSpec {
143+ Provider : "anthropic" ,
144+ Format : "anthropic" ,
145+ Model : "claude-3" ,
146+ Auth : AIServiceAuth {Type : "apiKey" , Secret : "sec" },
147+ Timeout : "30s" ,
148+ Retry : AIRetryConfig {MaxRetries : 3 , Backoff : "exponential" },
149+ Observability : AIObservabilityConfig {
150+ Langfuse : LangfuseConfig {Host : "host" , PublicKey : "pk" , SecretKey : "sk" },
151+ OTel : OTelConfig {Endpoint : "ep" , ServiceName : "sn" },
152+ },
153+ }
154+ copied := spec .DeepCopy ()
155+ assert .Equal (t , spec .Provider , copied .Provider )
156+ assert .Equal (t , spec .Observability .Langfuse .Host , copied .Observability .Langfuse .Host )
157+ }
158+
159+ func TestAIServiceSpecDeepCopy_Nil (t * testing.T ) {
160+ var spec * AIServiceSpec
161+ assert .Nil (t , spec .DeepCopy ())
162+ }
163+
164+ func TestAIServiceStatusDeepCopy (t * testing.T ) {
165+ status := & AIServiceStatus {
166+ Conditions : []metav1.Condition {
167+ {Type : "Accepted" , Status : "True" , Reason : "Valid" , Message : "ok" },
168+ },
169+ }
170+ copied := status .DeepCopy ()
171+ assert .Equal (t , 1 , len (copied .Conditions ))
172+ assert .Equal (t , "Accepted" , copied .Conditions [0 ].Type )
173+ assert .NotSame (t , & status .Conditions , & copied .Conditions )
174+ }
175+
176+ func TestAIServiceStatusDeepCopy_Nil (t * testing.T ) {
177+ var status * AIServiceStatus
178+ assert .Nil (t , status .DeepCopy ())
35179}
0 commit comments