Skip to content

Commit

Permalink
minor: refactor to test with multiple replicas (#6183)
Browse files Browse the repository at this point in the history
  • Loading branch information
SupriyaKasten authored and Ilya Kislenko committed Jul 31, 2019
1 parent 687ab93 commit c5df8fa
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ func (s *ControllerSuite) SetUpSuite(c *C) {
_, err = s.crCli.Profiles(s.namespace).Create(p)
c.Assert(err, IsNil)

ss := testutil.NewTestStatefulSet()
ss := testutil.NewTestStatefulSet(1)
ss, err = s.cli.AppsV1().StatefulSets(s.namespace).Create(ss)
c.Assert(err, IsNil)
s.ss = ss

d := testutil.NewTestDeployment()
d := testutil.NewTestDeployment(1)
d, err = s.cli.AppsV1().Deployments(s.namespace).Create(d)
c.Assert(err, IsNil)
s.deployment = d
Expand Down
4 changes: 2 additions & 2 deletions pkg/function/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func newLocationDeleteBlueprint() *crv1alpha1.Blueprint {

func (s *DataSuite) TestBackupRestoreDeleteData(c *C) {
ctx := context.Background()
ss, err := s.cli.AppsV1().StatefulSets(s.namespace).Create(testutil.NewTestStatefulSet())
ss, err := s.cli.AppsV1().StatefulSets(s.namespace).Create(testutil.NewTestStatefulSet(1))
c.Assert(err, IsNil)
err = kube.WaitOnStatefulSetReady(ctx, s.cli, ss.GetNamespace(), ss.GetName())
c.Assert(err, IsNil)
Expand Down Expand Up @@ -236,7 +236,7 @@ func (s *DataSuite) TestBackupRestoreDeleteData(c *C) {

func (s *DataSuite) TestBackupRestoreDataWithSnapshotID(c *C) {
ctx := context.Background()
ss, err := s.cli.AppsV1().StatefulSets(s.namespace).Create(testutil.NewTestStatefulSet())
ss, err := s.cli.AppsV1().StatefulSets(s.namespace).Create(testutil.NewTestStatefulSet(1))
c.Assert(err, IsNil)
err = kube.WaitOnStatefulSetReady(ctx, s.cli, ss.GetNamespace(), ss.GetName())
c.Assert(err, IsNil)
Expand Down
4 changes: 2 additions & 2 deletions pkg/function/kube_exec_all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func newExecAllBlueprint(kind string) *crv1alpha1.Blueprint {

func (s *KubeExecAllTest) TestKubeExecAllDeployment(c *C) {
ctx := context.Background()
d := testutil.NewTestDeployment()
d := testutil.NewTestDeployment(1)
d, err := s.cli.AppsV1().Deployments(s.namespace).Create(d)
c.Assert(err, IsNil)

Expand Down Expand Up @@ -123,7 +123,7 @@ func (s *KubeExecAllTest) TestKubeExecAllDeployment(c *C) {

func (s *KubeExecAllTest) TestKubeExecAllStatefulSet(c *C) {
ctx := context.Background()
ss := testutil.NewTestStatefulSet()
ss := testutil.NewTestStatefulSet(1)
ss, err := s.cli.AppsV1().StatefulSets(s.namespace).Create(ss)
c.Assert(err, IsNil)

Expand Down
4 changes: 2 additions & 2 deletions pkg/function/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func newScaleBlueprint(kind string) *crv1alpha1.Blueprint {

func (s *ScaleSuite) TestScaleDeployment(c *C) {
ctx := context.Background()
d := testutil.NewTestDeployment()
d := testutil.NewTestDeployment(1)
d.Spec.Template.Spec.Containers[0].Lifecycle = &v1.Lifecycle{
PreStop: &v1.Handler{
Exec: &v1.ExecAction{
Expand Down Expand Up @@ -161,7 +161,7 @@ func (s *ScaleSuite) TestScaleDeployment(c *C) {

func (s *ScaleSuite) TestScaleStatefulSet(c *C) {
ctx := context.Background()
ss := testutil.NewTestStatefulSet()
ss := testutil.NewTestStatefulSet(1)
ss.Spec.Template.Spec.Containers[0].Lifecycle = &v1.Lifecycle{
PreStop: &v1.Handler{
Exec: &v1.ExecAction{
Expand Down
6 changes: 2 additions & 4 deletions pkg/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func NewTestNamespace() *v1.Namespace {
}

// NewTestDeployment function returns a pointer to a new Deployment test object
func NewTestDeployment() *appsv1.Deployment {
var replicas int32 = 1
func NewTestDeployment(replicas int32) *appsv1.Deployment {
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-deployment-",
Expand All @@ -53,8 +52,7 @@ func NewTestDeployment() *appsv1.Deployment {
}

// NewTestStatefulSet function returns a pointer to a new StatefulSet test object
func NewTestStatefulSet() *appsv1.StatefulSet {
var replicas int32 = 1
func NewTestStatefulSet(replicas int32) *appsv1.StatefulSet {
return &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-statefulset-",
Expand Down
4 changes: 2 additions & 2 deletions pkg/testutil/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ func (s *TestUtilSuite) TestDeployment(c *C) {
c.Assert(err, IsNil)
}()

d := NewTestDeployment()
d := NewTestDeployment(1)
d, err = cli.AppsV1().Deployments(ns.GetName()).Create(d)
c.Assert(err, IsNil)
defer func() {
err = cli.AppsV1().Deployments(ns.GetName()).Delete(d.GetName(), nil)
c.Assert(err, IsNil)
}()

ss := NewTestStatefulSet()
ss := NewTestStatefulSet(1)
ss, err = cli.AppsV1().StatefulSets(ns.GetName()).Create(ss)
c.Assert(err, IsNil)
defer func() {
Expand Down

0 comments on commit c5df8fa

Please sign in to comment.