k3s/pkg/kubectl/scale_test.go

729 lines
20 KiB
Go
Raw Normal View History

2015-01-09 23:53:06 +00:00
/*
Copyright 2014 The Kubernetes Authors All rights reserved.
2015-01-09 23:53:06 +00:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kubectl
import (
"errors"
2015-01-09 23:53:06 +00:00
"testing"
2015-08-05 22:03:47 +00:00
"k8s.io/kubernetes/pkg/api"
kerrors "k8s.io/kubernetes/pkg/api/errors"
2015-10-09 22:04:41 +00:00
"k8s.io/kubernetes/pkg/apis/extensions"
2015-08-13 19:01:50 +00:00
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
2015-01-09 23:53:06 +00:00
)
type ErrorReplicationControllers struct {
testclient.FakeReplicationControllers
2015-09-16 15:32:59 +00:00
invalid bool
}
func (c *ErrorReplicationControllers) Update(controller *api.ReplicationController) (*api.ReplicationController, error) {
2015-09-16 15:32:59 +00:00
if c.invalid {
2015-12-10 18:32:29 +00:00
return nil, kerrors.NewInvalid(api.Kind(controller.Kind), controller.Name, nil)
2015-09-16 15:32:59 +00:00
}
return nil, errors.New("Replication controller update failure")
}
type ErrorReplicationControllerClient struct {
testclient.Fake
2015-09-16 15:32:59 +00:00
invalid bool
}
func (c *ErrorReplicationControllerClient) ReplicationControllers(namespace string) client.ReplicationControllerInterface {
2015-09-16 15:32:59 +00:00
return &ErrorReplicationControllers{testclient.FakeReplicationControllers{Fake: &c.Fake, Namespace: namespace}, c.invalid}
}
2015-05-21 21:10:25 +00:00
func TestReplicationControllerScaleRetry(t *testing.T) {
2015-09-16 15:32:59 +00:00
fake := &ErrorReplicationControllerClient{Fake: testclient.Fake{}, invalid: false}
scaler := ReplicationControllerScaler{fake}
2015-05-21 21:10:25 +00:00
preconditions := ScalePrecondition{-1, ""}
count := uint(3)
name := "foo"
namespace := "default"
2015-05-21 21:10:25 +00:00
scaleFunc := ScaleCondition(&scaler, &preconditions, namespace, name, count)
pass, err := scaleFunc()
if pass {
t.Errorf("Expected an update failure to return pass = false, got pass = %v", pass)
}
if err != nil {
t.Errorf("Did not expect an error on update failure, got %v", err)
}
2015-05-21 21:10:25 +00:00
preconditions = ScalePrecondition{3, ""}
scaleFunc = ScaleCondition(&scaler, &preconditions, namespace, name, count)
pass, err = scaleFunc()
if err == nil {
t.Errorf("Expected error on precondition failure")
}
}
func TestReplicationControllerScaleInvalid(t *testing.T) {
2015-09-16 15:32:59 +00:00
fake := &ErrorReplicationControllerClient{Fake: testclient.Fake{}, invalid: true}
scaler := ReplicationControllerScaler{fake}
preconditions := ScalePrecondition{-1, ""}
count := uint(3)
name := "foo"
namespace := "default"
scaleFunc := ScaleCondition(&scaler, &preconditions, namespace, name, count)
pass, err := scaleFunc()
if pass {
t.Errorf("Expected an update failure to return pass = false, got pass = %v", pass)
}
e, ok := err.(ScaleError)
if err == nil || !ok || e.FailureType != ScaleUpdateInvalidFailure {
t.Errorf("Expected error on invalid update failure, got %v", err)
}
}
2015-05-21 21:10:25 +00:00
func TestReplicationControllerScale(t *testing.T) {
fake := &testclient.Fake{}
2015-09-16 15:32:59 +00:00
scaler := ReplicationControllerScaler{fake}
2015-05-21 21:10:25 +00:00
preconditions := ScalePrecondition{-1, ""}
2015-01-09 23:53:06 +00:00
count := uint(3)
name := "foo"
2015-05-21 21:10:25 +00:00
scaler.Scale("default", name, count, &preconditions, nil, nil)
2015-01-09 23:53:06 +00:00
actions := fake.Actions()
if len(actions) != 2 {
t.Errorf("unexpected actions: %v, expected 2 actions (get, update)", actions)
2015-01-09 23:53:06 +00:00
}
2015-08-03 13:21:11 +00:00
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "replicationcontrollers" || action.GetName() != name {
t.Errorf("unexpected action: %v, expected get-replicationController %s", actions[0], name)
2015-01-09 23:53:06 +00:00
}
2015-08-03 13:21:11 +00:00
if action, ok := actions[1].(testclient.UpdateAction); !ok || action.GetResource() != "replicationcontrollers" || action.GetObject().(*api.ReplicationController).Spec.Replicas != int(count) {
t.Errorf("unexpected action %v, expected update-replicationController with replicas = %d", actions[1], count)
2015-01-09 23:53:06 +00:00
}
}
2015-05-21 21:10:25 +00:00
func TestReplicationControllerScaleFailsPreconditions(t *testing.T) {
fake := testclient.NewSimpleFake(&api.ReplicationController{
Spec: api.ReplicationControllerSpec{
Replicas: 10,
2015-01-09 23:53:06 +00:00
},
})
2015-09-16 15:32:59 +00:00
scaler := ReplicationControllerScaler{fake}
2015-05-21 21:10:25 +00:00
preconditions := ScalePrecondition{2, ""}
2015-01-09 23:53:06 +00:00
count := uint(3)
name := "foo"
2015-05-21 21:10:25 +00:00
scaler.Scale("default", name, count, &preconditions, nil, nil)
2015-01-09 23:53:06 +00:00
actions := fake.Actions()
if len(actions) != 1 {
2015-09-16 15:32:59 +00:00
t.Errorf("unexpected actions: %v, expected 1 action (get)", actions)
2015-01-09 23:53:06 +00:00
}
2015-08-03 13:21:11 +00:00
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "replicationcontrollers" || action.GetName() != name {
t.Errorf("unexpected action: %v, expected get-replicationController %s", actions[0], name)
2015-01-09 23:53:06 +00:00
}
}
2015-09-16 15:32:59 +00:00
func TestValidateReplicationController(t *testing.T) {
2015-01-09 23:53:06 +00:00
tests := []struct {
2015-05-21 21:10:25 +00:00
preconditions ScalePrecondition
2015-01-09 23:53:06 +00:00
controller api.ReplicationController
expectError bool
test string
}{
{
2015-05-21 21:10:25 +00:00
preconditions: ScalePrecondition{-1, ""},
2015-01-09 23:53:06 +00:00
expectError: false,
test: "defaults",
},
{
2015-05-21 21:10:25 +00:00
preconditions: ScalePrecondition{-1, ""},
2015-01-09 23:53:06 +00:00
controller: api.ReplicationController{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
Spec: api.ReplicationControllerSpec{
Replicas: 10,
},
},
expectError: false,
test: "defaults 2",
},
{
2015-05-21 21:10:25 +00:00
preconditions: ScalePrecondition{0, ""},
2015-01-09 23:53:06 +00:00
controller: api.ReplicationController{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
Spec: api.ReplicationControllerSpec{
Replicas: 0,
},
},
expectError: false,
test: "size matches",
},
{
2015-05-21 21:10:25 +00:00
preconditions: ScalePrecondition{-1, "foo"},
2015-01-09 23:53:06 +00:00
controller: api.ReplicationController{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
Spec: api.ReplicationControllerSpec{
Replicas: 10,
},
},
expectError: false,
test: "resource version matches",
},
{
2015-05-21 21:10:25 +00:00
preconditions: ScalePrecondition{10, "foo"},
2015-01-09 23:53:06 +00:00
controller: api.ReplicationController{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
Spec: api.ReplicationControllerSpec{
Replicas: 10,
},
},
expectError: false,
test: "both match",
},
{
2015-05-21 21:10:25 +00:00
preconditions: ScalePrecondition{10, "foo"},
2015-01-09 23:53:06 +00:00
controller: api.ReplicationController{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
Spec: api.ReplicationControllerSpec{
Replicas: 20,
},
},
expectError: true,
test: "size different",
},
{
2015-05-21 21:10:25 +00:00
preconditions: ScalePrecondition{10, "foo"},
2015-01-09 23:53:06 +00:00
controller: api.ReplicationController{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "bar",
},
Spec: api.ReplicationControllerSpec{
Replicas: 10,
},
},
expectError: true,
test: "version different",
},
{
2015-05-21 21:10:25 +00:00
preconditions: ScalePrecondition{10, "foo"},
2015-01-09 23:53:06 +00:00
controller: api.ReplicationController{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "bar",
},
Spec: api.ReplicationControllerSpec{
Replicas: 20,
},
},
expectError: true,
test: "both different",
},
}
for _, test := range tests {
2015-09-16 15:32:59 +00:00
err := test.preconditions.ValidateReplicationController(&test.controller)
if err != nil && !test.expectError {
t.Errorf("unexpected error: %v (%s)", err, test.test)
}
if err == nil && test.expectError {
t.Errorf("unexpected non-error: %v (%s)", err, test.test)
}
}
}
type ErrorJobs struct {
testclient.FakeJobs
invalid bool
}
func (c *ErrorJobs) Update(job *extensions.Job) (*extensions.Job, error) {
if c.invalid {
2015-12-10 18:32:29 +00:00
return nil, kerrors.NewInvalid(extensions.Kind(job.Kind), job.Name, nil)
}
return nil, errors.New("Job update failure")
}
func (c *ErrorJobs) Get(name string) (*extensions.Job, error) {
zero := 0
return &extensions.Job{
Spec: extensions.JobSpec{
Parallelism: &zero,
},
}, nil
}
type ErrorJobClient struct {
testclient.FakeExperimental
invalid bool
}
func (c *ErrorJobClient) Jobs(namespace string) client.JobInterface {
return &ErrorJobs{testclient.FakeJobs{Fake: &c.FakeExperimental, Namespace: namespace}, c.invalid}
}
2015-09-16 15:32:59 +00:00
func TestJobScaleRetry(t *testing.T) {
fake := &ErrorJobClient{FakeExperimental: testclient.FakeExperimental{}, invalid: false}
2015-09-16 15:32:59 +00:00
scaler := JobScaler{fake}
preconditions := ScalePrecondition{-1, ""}
count := uint(3)
name := "foo"
namespace := "default"
scaleFunc := ScaleCondition(&scaler, &preconditions, namespace, name, count)
pass, err := scaleFunc()
if pass != false {
t.Errorf("Expected an update failure to return pass = false, got pass = %v", pass)
}
if err != nil {
t.Errorf("Did not expect an error on update failure, got %v", err)
}
preconditions = ScalePrecondition{3, ""}
scaleFunc = ScaleCondition(&scaler, &preconditions, namespace, name, count)
pass, err = scaleFunc()
if err == nil {
t.Errorf("Expected error on precondition failure")
}
}
func TestJobScale(t *testing.T) {
fake := &testclient.FakeExperimental{Fake: &testclient.Fake{}}
2015-09-16 15:32:59 +00:00
scaler := JobScaler{fake}
preconditions := ScalePrecondition{-1, ""}
count := uint(3)
name := "foo"
scaler.Scale("default", name, count, &preconditions, nil, nil)
actions := fake.Actions()
if len(actions) != 2 {
t.Errorf("unexpected actions: %v, expected 2 actions (get, update)", actions)
}
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "jobs" || action.GetName() != name {
t.Errorf("unexpected action: %v, expected get-replicationController %s", actions[0], name)
}
2015-10-09 22:49:10 +00:00
if action, ok := actions[1].(testclient.UpdateAction); !ok || action.GetResource() != "jobs" || *action.GetObject().(*extensions.Job).Spec.Parallelism != int(count) {
2015-09-16 15:32:59 +00:00
t.Errorf("unexpected action %v, expected update-job with parallelism = %d", actions[1], count)
}
}
func TestJobScaleInvalid(t *testing.T) {
fake := &ErrorJobClient{FakeExperimental: testclient.FakeExperimental{}, invalid: true}
2015-09-16 15:32:59 +00:00
scaler := JobScaler{fake}
preconditions := ScalePrecondition{-1, ""}
count := uint(3)
name := "foo"
namespace := "default"
scaleFunc := ScaleCondition(&scaler, &preconditions, namespace, name, count)
pass, err := scaleFunc()
if pass {
t.Errorf("Expected an update failure to return pass = false, got pass = %v", pass)
}
e, ok := err.(ScaleError)
if err == nil || !ok || e.FailureType != ScaleUpdateInvalidFailure {
2015-09-16 15:32:59 +00:00
t.Errorf("Expected error on invalid update failure, got %v", err)
}
}
func TestJobScaleFailsPreconditions(t *testing.T) {
ten := 10
2015-10-09 22:49:10 +00:00
fake := testclient.NewSimpleFake(&extensions.Job{
Spec: extensions.JobSpec{
2015-09-16 15:32:59 +00:00
Parallelism: &ten,
},
})
scaler := JobScaler{&testclient.FakeExperimental{Fake: fake}}
2015-09-16 15:32:59 +00:00
preconditions := ScalePrecondition{2, ""}
count := uint(3)
name := "foo"
scaler.Scale("default", name, count, &preconditions, nil, nil)
actions := fake.Actions()
if len(actions) != 1 {
t.Errorf("unexpected actions: %v, expected 1 actions (get)", actions)
}
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "jobs" || action.GetName() != name {
t.Errorf("unexpected action: %v, expected get-job %s", actions[0], name)
}
}
func TestValidateJob(t *testing.T) {
zero, ten, twenty := 0, 10, 20
tests := []struct {
preconditions ScalePrecondition
2015-10-09 22:49:10 +00:00
job extensions.Job
2015-09-16 15:32:59 +00:00
expectError bool
test string
}{
{
preconditions: ScalePrecondition{-1, ""},
expectError: false,
test: "defaults",
},
{
preconditions: ScalePrecondition{-1, ""},
2015-10-09 22:49:10 +00:00
job: extensions.Job{
2015-09-16 15:32:59 +00:00
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
2015-10-09 22:49:10 +00:00
Spec: extensions.JobSpec{
2015-09-16 15:32:59 +00:00
Parallelism: &ten,
},
},
expectError: false,
test: "defaults 2",
},
{
preconditions: ScalePrecondition{0, ""},
2015-10-09 22:49:10 +00:00
job: extensions.Job{
2015-09-16 15:32:59 +00:00
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
2015-10-09 22:49:10 +00:00
Spec: extensions.JobSpec{
2015-09-16 15:32:59 +00:00
Parallelism: &zero,
},
},
expectError: false,
test: "size matches",
},
{
preconditions: ScalePrecondition{-1, "foo"},
2015-10-09 22:49:10 +00:00
job: extensions.Job{
2015-09-16 15:32:59 +00:00
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
2015-10-09 22:49:10 +00:00
Spec: extensions.JobSpec{
2015-09-16 15:32:59 +00:00
Parallelism: &ten,
},
},
expectError: false,
test: "resource version matches",
},
{
preconditions: ScalePrecondition{10, "foo"},
2015-10-09 22:49:10 +00:00
job: extensions.Job{
2015-09-16 15:32:59 +00:00
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
2015-10-09 22:49:10 +00:00
Spec: extensions.JobSpec{
2015-09-16 15:32:59 +00:00
Parallelism: &ten,
},
},
expectError: false,
test: "both match",
},
{
preconditions: ScalePrecondition{10, "foo"},
2015-10-09 22:49:10 +00:00
job: extensions.Job{
2015-09-16 15:32:59 +00:00
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
2015-10-09 22:49:10 +00:00
Spec: extensions.JobSpec{
2015-09-16 15:32:59 +00:00
Parallelism: &twenty,
},
},
expectError: true,
test: "size different",
},
{
preconditions: ScalePrecondition{10, "foo"},
2015-10-09 22:49:10 +00:00
job: extensions.Job{
2015-09-16 15:32:59 +00:00
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
},
expectError: true,
test: "parallelism nil",
},
{
preconditions: ScalePrecondition{10, "foo"},
2015-10-09 22:49:10 +00:00
job: extensions.Job{
2015-09-16 15:32:59 +00:00
ObjectMeta: api.ObjectMeta{
ResourceVersion: "bar",
},
2015-10-09 22:49:10 +00:00
Spec: extensions.JobSpec{
2015-09-16 15:32:59 +00:00
Parallelism: &ten,
},
},
expectError: true,
test: "version different",
},
{
preconditions: ScalePrecondition{10, "foo"},
2015-10-09 22:49:10 +00:00
job: extensions.Job{
2015-09-16 15:32:59 +00:00
ObjectMeta: api.ObjectMeta{
ResourceVersion: "bar",
},
2015-10-09 22:49:10 +00:00
Spec: extensions.JobSpec{
2015-09-16 15:32:59 +00:00
Parallelism: &twenty,
},
},
expectError: true,
test: "both different",
},
}
for _, test := range tests {
err := test.preconditions.ValidateJob(&test.job)
2015-01-09 23:53:06 +00:00
if err != nil && !test.expectError {
t.Errorf("unexpected error: %v (%s)", err, test.test)
}
if err == nil && test.expectError {
t.Errorf("unexpected non-error: %v (%s)", err, test.test)
}
}
}
type ErrorDeployments struct {
testclient.FakeDeployments
invalid bool
}
func (c *ErrorDeployments) Update(deployment *extensions.Deployment) (*extensions.Deployment, error) {
if c.invalid {
return nil, kerrors.NewInvalid(extensions.Kind(deployment.Kind), deployment.Name, nil)
}
return nil, errors.New("deployment update failure")
}
func (c *ErrorDeployments) Get(name string) (*extensions.Deployment, error) {
return &extensions.Deployment{
Spec: extensions.DeploymentSpec{
Replicas: 0,
},
}, nil
}
type ErrorDeploymentClient struct {
testclient.FakeExperimental
invalid bool
}
func (c *ErrorDeploymentClient) Deployments(namespace string) client.DeploymentInterface {
return &ErrorDeployments{testclient.FakeDeployments{Fake: &c.FakeExperimental, Namespace: namespace}, c.invalid}
}
func TestDeploymentScaleRetry(t *testing.T) {
fake := &ErrorDeploymentClient{FakeExperimental: testclient.FakeExperimental{Fake: &testclient.Fake{}}, invalid: false}
scaler := &DeploymentScaler{fake}
preconditions := &ScalePrecondition{-1, ""}
count := uint(3)
name := "foo"
namespace := "default"
scaleFunc := ScaleCondition(scaler, preconditions, namespace, name, count)
pass, err := scaleFunc()
if pass != false {
t.Errorf("Expected an update failure to return pass = false, got pass = %v", pass)
}
if err != nil {
t.Errorf("Did not expect an error on update failure, got %v", err)
}
preconditions = &ScalePrecondition{3, ""}
scaleFunc = ScaleCondition(scaler, preconditions, namespace, name, count)
pass, err = scaleFunc()
if err == nil {
t.Errorf("Expected error on precondition failure")
}
}
func TestDeploymentScale(t *testing.T) {
fake := &testclient.FakeExperimental{Fake: &testclient.Fake{}}
scaler := DeploymentScaler{fake}
preconditions := ScalePrecondition{-1, ""}
count := uint(3)
name := "foo"
scaler.Scale("default", name, count, &preconditions, nil, nil)
actions := fake.Actions()
if len(actions) != 2 {
t.Errorf("unexpected actions: %v, expected 2 actions (get, update)", actions)
}
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "deployments" || action.GetName() != name {
t.Errorf("unexpected action: %v, expected get-replicationController %s", actions[0], name)
}
if action, ok := actions[1].(testclient.UpdateAction); !ok || action.GetResource() != "deployments" || action.GetObject().(*extensions.Deployment).Spec.Replicas != int(count) {
t.Errorf("unexpected action %v, expected update-deployment with replicas = %d", actions[1], count)
}
}
func TestDeploymentScaleInvalid(t *testing.T) {
fake := &ErrorDeploymentClient{FakeExperimental: testclient.FakeExperimental{Fake: &testclient.Fake{}}, invalid: true}
scaler := DeploymentScaler{fake}
preconditions := ScalePrecondition{-1, ""}
count := uint(3)
name := "foo"
namespace := "default"
scaleFunc := ScaleCondition(&scaler, &preconditions, namespace, name, count)
pass, err := scaleFunc()
if pass {
t.Errorf("Expected an update failure to return pass = false, got pass = %v", pass)
}
e, ok := err.(ScaleError)
if err == nil || !ok || e.FailureType != ScaleUpdateInvalidFailure {
t.Errorf("Expected error on invalid update failure, got %v", err)
}
}
func TestDeploymentScaleFailsPreconditions(t *testing.T) {
fake := testclient.NewSimpleFake(&extensions.Deployment{
Spec: extensions.DeploymentSpec{
Replicas: 10,
},
})
scaler := DeploymentScaler{&testclient.FakeExperimental{Fake: fake}}
preconditions := ScalePrecondition{2, ""}
count := uint(3)
name := "foo"
scaler.Scale("default", name, count, &preconditions, nil, nil)
actions := fake.Actions()
if len(actions) != 1 {
t.Errorf("unexpected actions: %v, expected 1 actions (get)", actions)
}
if action, ok := actions[0].(testclient.GetAction); !ok || action.GetResource() != "deployments" || action.GetName() != name {
t.Errorf("unexpected action: %v, expected get-deployment %s", actions[0], name)
}
}
func TestValidateDeployment(t *testing.T) {
zero, ten, twenty := 0, 10, 20
tests := []struct {
preconditions ScalePrecondition
deployment extensions.Deployment
expectError bool
test string
}{
{
preconditions: ScalePrecondition{-1, ""},
expectError: false,
test: "defaults",
},
{
preconditions: ScalePrecondition{-1, ""},
deployment: extensions.Deployment{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
Spec: extensions.DeploymentSpec{
Replicas: ten,
},
},
expectError: false,
test: "defaults 2",
},
{
preconditions: ScalePrecondition{0, ""},
deployment: extensions.Deployment{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
Spec: extensions.DeploymentSpec{
Replicas: zero,
},
},
expectError: false,
test: "size matches",
},
{
preconditions: ScalePrecondition{-1, "foo"},
deployment: extensions.Deployment{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
Spec: extensions.DeploymentSpec{
Replicas: ten,
},
},
expectError: false,
test: "resource version matches",
},
{
preconditions: ScalePrecondition{10, "foo"},
deployment: extensions.Deployment{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
Spec: extensions.DeploymentSpec{
Replicas: ten,
},
},
expectError: false,
test: "both match",
},
{
preconditions: ScalePrecondition{10, "foo"},
deployment: extensions.Deployment{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
Spec: extensions.DeploymentSpec{
Replicas: twenty,
},
},
expectError: true,
test: "size different",
},
{
preconditions: ScalePrecondition{10, "foo"},
deployment: extensions.Deployment{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "foo",
},
},
expectError: true,
test: "no replicas",
},
{
preconditions: ScalePrecondition{10, "foo"},
deployment: extensions.Deployment{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "bar",
},
Spec: extensions.DeploymentSpec{
Replicas: ten,
},
},
expectError: true,
test: "version different",
},
{
preconditions: ScalePrecondition{10, "foo"},
deployment: extensions.Deployment{
ObjectMeta: api.ObjectMeta{
ResourceVersion: "bar",
},
Spec: extensions.DeploymentSpec{
Replicas: twenty,
},
},
expectError: true,
test: "both different",
},
}
for _, test := range tests {
err := test.preconditions.ValidateDeployment(&test.deployment)
if err != nil && !test.expectError {
t.Errorf("unexpected error: %v (%s)", err, test.test)
}
if err == nil && test.expectError {
t.Errorf("unexpected non-error: %v (%s)", err, test.test)
}
}
}