|
7 | 7 |
|
8 | 8 | "github.com/agentic-layer/agent-runtime-operator/internal/equality"
|
9 | 9 | corev1 "k8s.io/api/core/v1"
|
| 10 | + "k8s.io/apimachinery/pkg/util/intstr" |
10 | 11 | )
|
11 | 12 |
|
12 | 13 | // A helper function to easily get a pointer to a bool, as required by the 'Optional' field.
|
@@ -220,3 +221,151 @@ func TestEnvFromEqual(t *testing.T) {
|
220 | 221 | })
|
221 | 222 | }
|
222 | 223 | }
|
| 224 | + |
| 225 | +func TestProbesEqual(t *testing.T) { |
| 226 | + testCases := []struct { |
| 227 | + name string |
| 228 | + a *corev1.Probe |
| 229 | + b *corev1.Probe |
| 230 | + want bool |
| 231 | + }{ |
| 232 | + { |
| 233 | + name: "should be equal for both nil", |
| 234 | + a: nil, |
| 235 | + b: nil, |
| 236 | + want: true, |
| 237 | + }, |
| 238 | + { |
| 239 | + name: "should not be equal for one nil", |
| 240 | + a: nil, |
| 241 | + b: &corev1.Probe{InitialDelaySeconds: 10}, |
| 242 | + want: false, |
| 243 | + }, |
| 244 | + { |
| 245 | + name: "should not be equal for other nil", |
| 246 | + a: &corev1.Probe{InitialDelaySeconds: 10}, |
| 247 | + b: nil, |
| 248 | + want: false, |
| 249 | + }, |
| 250 | + { |
| 251 | + name: "should be equal for identical HTTP probes", |
| 252 | + a: &corev1.Probe{ |
| 253 | + ProbeHandler: corev1.ProbeHandler{ |
| 254 | + HTTPGet: &corev1.HTTPGetAction{ |
| 255 | + Path: "/health", |
| 256 | + Port: intstr.FromInt(8000), |
| 257 | + }, |
| 258 | + }, |
| 259 | + InitialDelaySeconds: 10, |
| 260 | + PeriodSeconds: 5, |
| 261 | + }, |
| 262 | + b: &corev1.Probe{ |
| 263 | + ProbeHandler: corev1.ProbeHandler{ |
| 264 | + HTTPGet: &corev1.HTTPGetAction{ |
| 265 | + Path: "/health", |
| 266 | + Port: intstr.FromInt(8000), |
| 267 | + }, |
| 268 | + }, |
| 269 | + InitialDelaySeconds: 10, |
| 270 | + PeriodSeconds: 5, |
| 271 | + }, |
| 272 | + want: true, |
| 273 | + }, |
| 274 | + { |
| 275 | + name: "should be equal for identical TCP probes", |
| 276 | + a: &corev1.Probe{ |
| 277 | + ProbeHandler: corev1.ProbeHandler{ |
| 278 | + TCPSocket: &corev1.TCPSocketAction{ |
| 279 | + Port: intstr.FromInt(8000), |
| 280 | + }, |
| 281 | + }, |
| 282 | + InitialDelaySeconds: 10, |
| 283 | + }, |
| 284 | + b: &corev1.Probe{ |
| 285 | + ProbeHandler: corev1.ProbeHandler{ |
| 286 | + TCPSocket: &corev1.TCPSocketAction{ |
| 287 | + Port: intstr.FromInt(8000), |
| 288 | + }, |
| 289 | + }, |
| 290 | + InitialDelaySeconds: 10, |
| 291 | + }, |
| 292 | + want: true, |
| 293 | + }, |
| 294 | + { |
| 295 | + name: "should not be equal for different HTTP paths", |
| 296 | + a: &corev1.Probe{ |
| 297 | + ProbeHandler: corev1.ProbeHandler{ |
| 298 | + HTTPGet: &corev1.HTTPGetAction{ |
| 299 | + Path: "/health", |
| 300 | + Port: intstr.FromInt(8000), |
| 301 | + }, |
| 302 | + }, |
| 303 | + }, |
| 304 | + b: &corev1.Probe{ |
| 305 | + ProbeHandler: corev1.ProbeHandler{ |
| 306 | + HTTPGet: &corev1.HTTPGetAction{ |
| 307 | + Path: "/readiness", |
| 308 | + Port: intstr.FromInt(8000), |
| 309 | + }, |
| 310 | + }, |
| 311 | + }, |
| 312 | + want: false, |
| 313 | + }, |
| 314 | + { |
| 315 | + name: "should not be equal for different ports", |
| 316 | + a: &corev1.Probe{ |
| 317 | + ProbeHandler: corev1.ProbeHandler{ |
| 318 | + TCPSocket: &corev1.TCPSocketAction{ |
| 319 | + Port: intstr.FromInt(8000), |
| 320 | + }, |
| 321 | + }, |
| 322 | + }, |
| 323 | + b: &corev1.Probe{ |
| 324 | + ProbeHandler: corev1.ProbeHandler{ |
| 325 | + TCPSocket: &corev1.TCPSocketAction{ |
| 326 | + Port: intstr.FromInt(3000), |
| 327 | + }, |
| 328 | + }, |
| 329 | + }, |
| 330 | + want: false, |
| 331 | + }, |
| 332 | + { |
| 333 | + name: "should not be equal for different probe types", |
| 334 | + a: &corev1.Probe{ |
| 335 | + ProbeHandler: corev1.ProbeHandler{ |
| 336 | + HTTPGet: &corev1.HTTPGetAction{ |
| 337 | + Path: "/health", |
| 338 | + Port: intstr.FromInt(8000), |
| 339 | + }, |
| 340 | + }, |
| 341 | + }, |
| 342 | + b: &corev1.Probe{ |
| 343 | + ProbeHandler: corev1.ProbeHandler{ |
| 344 | + TCPSocket: &corev1.TCPSocketAction{ |
| 345 | + Port: intstr.FromInt(8000), |
| 346 | + }, |
| 347 | + }, |
| 348 | + }, |
| 349 | + want: false, |
| 350 | + }, |
| 351 | + { |
| 352 | + name: "should not be equal for different timing settings", |
| 353 | + a: &corev1.Probe{ |
| 354 | + InitialDelaySeconds: 10, |
| 355 | + }, |
| 356 | + b: &corev1.Probe{ |
| 357 | + InitialDelaySeconds: 15, |
| 358 | + }, |
| 359 | + want: false, |
| 360 | + }, |
| 361 | + } |
| 362 | + |
| 363 | + for _, tc := range testCases { |
| 364 | + t.Run(tc.name, func(t *testing.T) { |
| 365 | + got := equality.ProbesEqual(tc.a, tc.b) |
| 366 | + if got != tc.want { |
| 367 | + t.Errorf("ProbesEqual() = %v, want %v", got, tc.want) |
| 368 | + } |
| 369 | + }) |
| 370 | + } |
| 371 | +} |
0 commit comments