Skip to content

Commit

Permalink
move deployer test mock to point of use
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Jul 3, 2018
1 parent 5e37cde commit c7556f4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 54 deletions.
47 changes: 0 additions & 47 deletions pkg/apps/util/test/support.go

This file was deleted.

50 changes: 43 additions & 7 deletions pkg/cmd/infra/deployer/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import (
"strconv"
"testing"

"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
kapi "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/kubectl"

appsapi "github.com/openshift/origin/pkg/apps/apis/apps"
appstest "github.com/openshift/origin/pkg/apps/apis/apps/test"
"github.com/openshift/origin/pkg/apps/strategy"
appsutil "github.com/openshift/origin/pkg/apps/util"
cmdtest "github.com/openshift/origin/pkg/apps/util/test"

// install all APIs
_ "github.com/openshift/origin/pkg/api/install"
_ "k8s.io/kubernetes/pkg/apis/core/install"
)

func TestDeployer_getDeploymentFail(t *testing.T) {
Expand All @@ -32,7 +30,7 @@ func TestDeployer_getDeploymentFail(t *testing.T) {
t.Fatal("unexpected call")
return nil, nil
},
scaler: &cmdtest.FakeScaler{},
scaler: &FakeScaler{},
}

err := deployer.Deploy("namespace", "name")
Expand Down Expand Up @@ -146,7 +144,7 @@ func TestDeployer_deployScenarios(t *testing.T) {
var actualFrom, actualTo *kapi.ReplicationController
var actualDesired int32
to := findDeployment(s.toVersion)
scaler := &cmdtest.FakeScaler{}
scaler := &FakeScaler{}

deployer := &Deployer{
out: &bytes.Buffer{},
Expand Down Expand Up @@ -228,3 +226,41 @@ type testStrategy struct {
func (t *testStrategy) Deploy(from *kapi.ReplicationController, to *kapi.ReplicationController, desiredReplicas int) error {
return t.deployFunc(from, to, desiredReplicas)
}

type FakeScaler struct {
Events []ScaleEvent
}

type ScaleEvent struct {
Name string
Size uint
}

func (t *FakeScaler) Scale(namespace, name string, newSize uint, preconditions *kubectl.ScalePrecondition, retry, wait *kubectl.RetryParams, resource schema.GroupResource) error {
t.Events = append(t.Events, ScaleEvent{name, newSize})
return nil
}

func (t *FakeScaler) ScaleSimple(namespace, name string, preconditions *kubectl.ScalePrecondition, newSize uint, resource schema.GroupResource) (string, error) {
return "", fmt.Errorf("unexpected call to ScaleSimple")
}

type FakeLaggedScaler struct {
Events []ScaleEvent
RetryCount int
}

func (t *FakeLaggedScaler) Scale(namespace, name string, newSize uint, preconditions *kubectl.ScalePrecondition, retry, wait *kubectl.RetryParams, resource schema.GroupResource) error {
if t.RetryCount != 2 {
t.RetryCount += 1
// This is faking a real error from the
// "k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle" package.
return errors.NewForbidden(resource, name, fmt.Errorf("%s: not yet ready to handle request", name))
}
t.Events = append(t.Events, ScaleEvent{name, newSize})
return nil
}

func (t *FakeLaggedScaler) ScaleSimple(namespace, name string, preconditions *kubectl.ScalePrecondition, newSize uint, resource schema.GroupResource) (string, error) {
return "", nil
}

0 comments on commit c7556f4

Please sign in to comment.