@@ -6,17 +6,15 @@ import (
6
6
"strconv"
7
7
"testing"
8
8
9
+ "k8s.io/apimachinery/pkg/api/errors"
10
+ "k8s.io/apimachinery/pkg/runtime/schema"
9
11
kapi "k8s.io/kubernetes/pkg/apis/core"
12
+ "k8s.io/kubernetes/pkg/kubectl"
10
13
11
14
appsapi "github.com/openshift/origin/pkg/apps/apis/apps"
12
15
appstest "github.com/openshift/origin/pkg/apps/apis/apps/test"
13
16
"github.com/openshift/origin/pkg/apps/strategy"
14
17
appsutil "github.com/openshift/origin/pkg/apps/util"
15
- cmdtest "github.com/openshift/origin/pkg/apps/util/test"
16
-
17
- // install all APIs
18
- _ "github.com/openshift/origin/pkg/api/install"
19
- _ "k8s.io/kubernetes/pkg/apis/core/install"
20
18
)
21
19
22
20
func TestDeployer_getDeploymentFail (t * testing.T ) {
@@ -32,7 +30,7 @@ func TestDeployer_getDeploymentFail(t *testing.T) {
32
30
t .Fatal ("unexpected call" )
33
31
return nil , nil
34
32
},
35
- scaler : & cmdtest. FakeScaler {},
33
+ scaler : & FakeScaler {},
36
34
}
37
35
38
36
err := deployer .Deploy ("namespace" , "name" )
@@ -146,7 +144,7 @@ func TestDeployer_deployScenarios(t *testing.T) {
146
144
var actualFrom , actualTo * kapi.ReplicationController
147
145
var actualDesired int32
148
146
to := findDeployment (s .toVersion )
149
- scaler := & cmdtest. FakeScaler {}
147
+ scaler := & FakeScaler {}
150
148
151
149
deployer := & Deployer {
152
150
out : & bytes.Buffer {},
@@ -228,3 +226,41 @@ type testStrategy struct {
228
226
func (t * testStrategy ) Deploy (from * kapi.ReplicationController , to * kapi.ReplicationController , desiredReplicas int ) error {
229
227
return t .deployFunc (from , to , desiredReplicas )
230
228
}
229
+
230
+ type FakeScaler struct {
231
+ Events []ScaleEvent
232
+ }
233
+
234
+ type ScaleEvent struct {
235
+ Name string
236
+ Size uint
237
+ }
238
+
239
+ func (t * FakeScaler ) Scale (namespace , name string , newSize uint , preconditions * kubectl.ScalePrecondition , retry , wait * kubectl.RetryParams , resource schema.GroupResource ) error {
240
+ t .Events = append (t .Events , ScaleEvent {name , newSize })
241
+ return nil
242
+ }
243
+
244
+ func (t * FakeScaler ) ScaleSimple (namespace , name string , preconditions * kubectl.ScalePrecondition , newSize uint , resource schema.GroupResource ) (string , error ) {
245
+ return "" , fmt .Errorf ("unexpected call to ScaleSimple" )
246
+ }
247
+
248
+ type FakeLaggedScaler struct {
249
+ Events []ScaleEvent
250
+ RetryCount int
251
+ }
252
+
253
+ func (t * FakeLaggedScaler ) Scale (namespace , name string , newSize uint , preconditions * kubectl.ScalePrecondition , retry , wait * kubectl.RetryParams , resource schema.GroupResource ) error {
254
+ if t .RetryCount != 2 {
255
+ t .RetryCount += 1
256
+ // This is faking a real error from the
257
+ // "k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle" package.
258
+ return errors .NewForbidden (resource , name , fmt .Errorf ("%s: not yet ready to handle request" , name ))
259
+ }
260
+ t .Events = append (t .Events , ScaleEvent {name , newSize })
261
+ return nil
262
+ }
263
+
264
+ func (t * FakeLaggedScaler ) ScaleSimple (namespace , name string , preconditions * kubectl.ScalePrecondition , newSize uint , resource schema.GroupResource ) (string , error ) {
265
+ return "" , nil
266
+ }
0 commit comments