@@ -309,16 +309,15 @@ func TestValidateCreate(t *testing.T) {
309309 test .Expect (err ).ShouldNot (HaveOccurred (), "Expected no errors on call to ValidateCreate function" )
310310 })
311311
312- // Negative Test: Invalid RayCluster with EnableIngress set to true
313- invalidRayCluster := validRayCluster .DeepCopy ()
314-
315312 t .Run ("Negative: Expected errors on call to ValidateCreate function due to EnableIngress set to True" , func (t * testing.T ) {
313+ invalidRayCluster := validRayCluster .DeepCopy ()
316314 invalidRayCluster .Spec .HeadGroupSpec .EnableIngress = support .Ptr (true )
317315 _ , err := rcWebhook .ValidateCreate (test .Ctx (), runtime .Object (invalidRayCluster ))
318316 test .Expect (err ).Should (HaveOccurred (), "Expected errors on call to ValidateCreate function due to EnableIngress set to True" )
319317 })
320318
321319 t .Run ("Negative: Expected errors on call to ValidateCreate function due to manipulated OAuth Proxy Container" , func (t * testing.T ) {
320+ invalidRayCluster := validRayCluster .DeepCopy ()
322321 for i , headContainer := range invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .Containers {
323322 if headContainer .Name == oauthProxyContainerName {
324323 invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .Containers [i ].Args = []string {"--invalid-arg" }
@@ -330,6 +329,7 @@ func TestValidateCreate(t *testing.T) {
330329 })
331330
332331 t .Run ("Negative: Expected errors on call to ValidateCreate function due to manipulated OAuth Proxy Volume" , func (t * testing.T ) {
332+ invalidRayCluster := validRayCluster .DeepCopy ()
333333 for i , headVolume := range invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .Volumes {
334334 if headVolume .Name == oauthProxyVolumeName {
335335 invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .Volumes [i ].Secret .SecretName = "invalid-secret-name"
@@ -341,6 +341,7 @@ func TestValidateCreate(t *testing.T) {
341341 })
342342
343343 t .Run ("Negative: Expected errors on call to ValidateCreate function due to manipulated head group service account name" , func (t * testing.T ) {
344+ invalidRayCluster := validRayCluster .DeepCopy ()
344345 invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName = "invalid-service-account-name"
345346 _ , err = rcWebhook .ValidateCreate (test .Ctx (), runtime .Object (invalidRayCluster ))
346347 test .Expect (err ).Should (HaveOccurred (), "Expected errors on call to ValidateCreate function due to manipulated head group service account name" )
@@ -535,17 +536,15 @@ func TestValidateUpdate(t *testing.T) {
535536 test .Expect (err ).ShouldNot (HaveOccurred (), "Expected no errors on call to ValidateUpdate function" )
536537 })
537538
538- // Negative Test Cases
539- trueBool := true
540- invalidRayCluster := validRayCluster .DeepCopy ()
541-
542539 t .Run ("Negative: Expected errors on call to ValidateUpdate function due to EnableIngress set to True" , func (t * testing.T ) {
543- invalidRayCluster .Spec .HeadGroupSpec .EnableIngress = & trueBool
540+ invalidRayCluster := validRayCluster .DeepCopy ()
541+ invalidRayCluster .Spec .HeadGroupSpec .EnableIngress = support .Ptr (true )
544542 _ , err := rcWebhook .ValidateUpdate (test .Ctx (), runtime .Object (validRayCluster ), runtime .Object (invalidRayCluster ))
545543 test .Expect (err ).Should (HaveOccurred (), "Expected errors on call to ValidateUpdate function due to EnableIngress set to True" )
546544 })
547545
548546 t .Run ("Negative: Expected errors on call to ValidateUpdate function due to manipulated OAuth Proxy Container" , func (t * testing.T ) {
547+ invalidRayCluster := validRayCluster .DeepCopy ()
549548 for i , headContainer := range invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .Containers {
550549 if headContainer .Name == oauthProxyContainerName {
551550 invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .Containers [i ].Args = []string {"--invalid-arg" }
@@ -557,6 +556,7 @@ func TestValidateUpdate(t *testing.T) {
557556 })
558557
559558 t .Run ("Negative: Expected errors on call to ValidateUpdate function due to manipulated OAuth Proxy Volume" , func (t * testing.T ) {
559+ invalidRayCluster := validRayCluster .DeepCopy ()
560560 for i , headVolume := range invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .Volumes {
561561 if headVolume .Name == oauthProxyVolumeName {
562562 invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .Volumes [i ].Secret .SecretName = "invalid-secret-name"
@@ -568,12 +568,14 @@ func TestValidateUpdate(t *testing.T) {
568568 })
569569
570570 t .Run ("Negative: Expected errors on call to ValidateUpdate function due to manipulated head group service account name" , func (t * testing.T ) {
571+ invalidRayCluster := validRayCluster .DeepCopy ()
571572 invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName = "invalid-service-account-name"
572573 _ , err := rcWebhook .ValidateUpdate (test .Ctx (), runtime .Object (validRayCluster ), runtime .Object (invalidRayCluster ))
573574 test .Expect (err ).Should (HaveOccurred (), "Expected errors on call to ValidateUpdate function due to manipulated head group service account name" )
574575 })
575576
576577 t .Run ("Negative: Expected errors on call to ValidateUpdate function due to manipulated Init Container in the head group" , func (t * testing.T ) {
578+ invalidRayCluster := validRayCluster .DeepCopy ()
577579 for i , headInitContainer := range invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .InitContainers {
578580 if headInitContainer .Name == "create-cert" {
579581 invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .InitContainers [i ].Command = []string {"manipulated command" }
@@ -585,6 +587,7 @@ func TestValidateUpdate(t *testing.T) {
585587 })
586588
587589 t .Run ("Negative: Expected errors on call to ValidateUpdate function due to manipulated Init Container in the worker group" , func (t * testing.T ) {
590+ invalidRayCluster := validRayCluster .DeepCopy ()
588591 for _ , workerGroup := range invalidRayCluster .Spec .WorkerGroupSpecs {
589592 for i , workerInitContainer := range workerGroup .Template .Spec .InitContainers {
590593 if workerInitContainer .Name == "create-cert" {
@@ -598,6 +601,7 @@ func TestValidateUpdate(t *testing.T) {
598601 })
599602
600603 t .Run ("Negative: Expected errors on call to ValidateUpdate function due to manipulated Volume in the head group" , func (t * testing.T ) {
604+ invalidRayCluster := validRayCluster .DeepCopy ()
601605 for i , headVolume := range invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .Volumes {
602606 if headVolume .Name == "ca-vol" {
603607 invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .Volumes [i ].Secret .SecretName = "invalid-secret-name"
@@ -609,6 +613,7 @@ func TestValidateUpdate(t *testing.T) {
609613 })
610614
611615 t .Run ("Negative: Expected errors on call to ValidateUpdate function due to manipulated Volume in the worker group" , func (t * testing.T ) {
616+ invalidRayCluster := validRayCluster .DeepCopy ()
612617 for _ , workerGroup := range invalidRayCluster .Spec .WorkerGroupSpecs {
613618 for i , workerVolume := range workerGroup .Template .Spec .Volumes {
614619 if workerVolume .Name == "ca-vol" {
@@ -622,6 +627,7 @@ func TestValidateUpdate(t *testing.T) {
622627 })
623628
624629 t .Run ("Negative: Expected errors on call to ValidateUpdate function due to manipulated env vars in the head group" , func (t * testing.T ) {
630+ invalidRayCluster := validRayCluster .DeepCopy ()
625631 for i , headEnvVar := range invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .Containers [0 ].Env {
626632 if headEnvVar .Name == "RAY_USE_TLS" {
627633 invalidRayCluster .Spec .HeadGroupSpec .Template .Spec .Containers [0 ].Env [i ].Value = "invalid-value"
@@ -633,6 +639,7 @@ func TestValidateUpdate(t *testing.T) {
633639 })
634640
635641 t .Run ("Negative: Expected errors on call to ValidateUpdate function due to manipulated env vars in the worker group" , func (t * testing.T ) {
642+ invalidRayCluster := validRayCluster .DeepCopy ()
636643 for _ , workerGroup := range invalidRayCluster .Spec .WorkerGroupSpecs {
637644 for i , workerEnvVar := range workerGroup .Template .Spec .Containers [0 ].Env {
638645 if workerEnvVar .Name == "RAY_USE_TLS" {
0 commit comments