11/*
2- * Copyright (c) 2020, 2024 , Oracle and/or its affiliates.
2+ * Copyright (c) 2020, 2025 , Oracle and/or its affiliates.
33 * Licensed under the Universal Permissive License v 1.0 as shown at
44 * http://oss.oracle.com/licenses/upl.
55 */
@@ -9,22 +9,24 @@ package remote
99import (
1010 goctx "context"
1111 "fmt"
12+ "io"
13+ "strings"
14+ "testing"
15+ "time"
16+
1217 cohv1 "github.com/oracle/coherence-operator/api/v1"
1318 "github.com/oracle/coherence-operator/test/e2e/helper"
1419 "golang.org/x/net/context"
15- "io"
1620 appsv1 "k8s.io/api/apps/v1"
21+ "k8s.io/apimachinery/pkg/types"
1722 "k8s.io/utils/ptr"
1823 "sigs.k8s.io/testing_frameworks/integration"
19- "strings"
20- "testing"
21- "time"
2224
2325 . "github.com/onsi/gomega"
2426)
2527
2628// Test scaling up and down with different policies.
27- // This test is an example of using sub-tests to run the test with different test cases.
29+ // This test is an example of using subtests to run the test with different test cases.
2830func TestScaling (t * testing.T ) {
2931 // Ensure that everything is cleaned up after the test!
3032 testContext .CleanupAfterTest (t )
@@ -91,7 +93,7 @@ func TestScaleDownToZeroWithSuspendFalse(t *testing.T) {
9193}
9294
9395// If a deployment is scaled down to zero it should be deleted and just its parent Coherence resource should remain.
94- // This test scales down using the "kubectl scale --relicas =0" command
96+ // This test scales down using the "kubectl scale --replicas =0" command
9597func TestScaleDownToZeroUsingKubectl (t * testing.T ) {
9698 // Ensure that everything is cleaned up after the test!
9799 testContext .CleanupAfterTest (t )
@@ -138,7 +140,7 @@ var kubeCtlScaler = func(t *testing.T, d *cohv1.Coherence, replicas int32) error
138140}
139141
140142// Assert that a deployment can be created and scaled using the specified policy.
141- func assertScale (t * testing.T , id string , policy cohv1.ScalingPolicy , replicasStart , replicasScale int32 , scaler ScaleFunction ) {
143+ func assertScale (t * testing.T , id string , policy cohv1.ScalingPolicy , replicasStart , replicasScale int32 , scaler ScaleFunction ) types. NamespacedName {
142144 g := NewGomegaWithT (t )
143145
144146 testContext .CleanupAfterTest (t )
@@ -153,16 +155,24 @@ func assertScale(t *testing.T, id string, policy cohv1.ScalingPolicy, replicasSt
153155 // Give the deployment a unique name based on the test name
154156 deployment .SetName (fmt .Sprintf ("%s-%s" , deployment .GetName (), strings .ToLower (id )))
155157
156- // update the replica count and scaling policy
157- deployment .SetReplicas (replicasStart )
158+ // update the replica count if greater than or equal zero, otherwise do not set the replica count field
159+ var initialReplicas int32
160+ if replicasStart >= 0 {
161+ deployment .SetReplicas (replicasStart )
162+ initialReplicas = replicasStart
163+ } else {
164+ deployment .Spec .Replicas = nil
165+ initialReplicas = cohv1 .DefaultReplicas
166+ }
158167
168+ // update the scaling policy
159169 if deployment .Spec .Scaling == nil {
160170 deployment .Spec .Scaling = & cohv1.ScalingSpec {}
161171 }
162172 deployment .Spec .Scaling .Policy = & policy
163173
164174 // Do the canary test unless parallel scaling down
165- doCanary := replicasStart < replicasScale || policy != cohv1 .ParallelScaling
175+ doCanary := initialReplicas < replicasScale || policy != cohv1 .ParallelScaling
166176
167177 t .Logf ("assertScale() - doCanary=%t" , doCanary )
168178 t .Log ("assertScale() - Installing Coherence deployment..." )
@@ -186,6 +196,8 @@ func assertScale(t *testing.T, id string, policy cohv1.ScalingPolicy, replicasSt
186196 err = helper .CheckCanary (testContext , namespace , deployment .Name )
187197 g .Expect (err ).NotTo (HaveOccurred ())
188198 }
199+
200+ return types.NamespacedName {Namespace : deployment .Namespace , Name : deployment .Name }
189201}
190202
191203func assertScaleDownToZero (t * testing.T , id string , scaler ScaleFunction , suspend * bool ) {
0 commit comments