Skip to content

Commit

Permalink
more test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Wang <[email protected]>
  • Loading branch information
whynowy committed Jul 17, 2023
1 parent 295da39 commit dab415a
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/apis/numaflow/v1alpha1/pipeline_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,30 @@ func Test_FindVertexWithBuffer(t *testing.T) {
v := testPipeline.FindVertexWithBuffer(GenerateBufferName(testNamespace, testPipelineName, "p1", 0))
assert.NotNil(t, v)
}

func Test_GetSideInputManagerDeployments(t *testing.T) {
t.Run("side inputs not enabled", func(t *testing.T) {
deployments, err := testPipeline.GetSideInputManagerDeployments(testGetSideInputDeploymentReq)
assert.Nil(t, err)
assert.Equal(t, 0, len(deployments))
})

t.Run("side inputs enabled", func(t *testing.T) {
testObj := testPipeline.DeepCopy()
testObj.Spec.SideInputs = []SideInput{
{
Name: "side-input-1",
Container: &Container{
Image: "side-input-1",
},
Trigger: &SideInputTrigger{
Schedule: pointer.String("0 0 * * *"),
},
},
}
deployments, err := testObj.GetSideInputManagerDeployments(testGetSideInputDeploymentReq)
assert.Nil(t, err)
assert.Equal(t, 1, len(deployments))
assert.Equal(t, 2, len(deployments[0].Spec.Template.Spec.Containers))
})
}
94 changes: 94 additions & 0 deletions pkg/apis/numaflow/v1alpha1/side_input_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
Copyright 2022 The Numaproj Authors.
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 v1alpha1

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
imagePullNever = corev1.PullNever
testSideInput = &SideInput{
Name: "test-side-input",
Container: &Container{
Image: "test-image",
Env: []corev1.EnvVar{
{Name: "key1", Value: "value1"},
},
Command: []string{"test-command"},
Args: []string{"test-args"},
ImagePullPolicy: &imagePullNever,
},
Trigger: &SideInputTrigger{
Interval: &metav1.Duration{Duration: time.Duration(1 * time.Second)},
},
}

testGetSideInputDeploymentReq = GetSideInputDeploymentReq{
ISBSvcType: ISBSvcTypeJetStream,
Image: "test-image",
PullPolicy: corev1.PullAlways,
Env: []corev1.EnvVar{
{Name: "key2", Value: "value2"},
},
}
)

func Test_getUDContainer(t *testing.T) {
c := testSideInput.getUDContainer(testGetSideInputDeploymentReq)
assert.Equal(t, CtrUdSideInput, c.Name)
assert.Equal(t, testSideInput.Container.Image, c.Image)
assert.Equal(t, testSideInput.Container.Command, c.Command)
for _, env := range testSideInput.Container.Env {
assert.Contains(t, c.Env, env)
}
assert.Equal(t, imagePullNever, c.ImagePullPolicy)
}

func Test_getNumaContainer(t *testing.T) {
c, err := testSideInput.getNumaContainer(*testPipeline, testGetSideInputDeploymentReq)
assert.NoError(t, err)
assert.Equal(t, testSideInput.Container.Image, testGetSideInputDeploymentReq.Image)
for _, env := range testGetSideInputDeploymentReq.Env {
assert.Contains(t, c.Env, env)
}
assert.Equal(t, testGetSideInputDeploymentReq.PullPolicy, c.ImagePullPolicy)
assert.Equal(t, CtrMain, c.Name)
}

func Test_getInitContainer(t *testing.T) {
c := testSideInput.getInitContainer(*testPipeline, testGetSideInputDeploymentReq)
assert.Equal(t, testSideInput.Container.Image, testGetSideInputDeploymentReq.Image)
for _, env := range testGetSideInputDeploymentReq.Env {
assert.Contains(t, c.Env, env)
}
assert.Equal(t, testGetSideInputDeploymentReq.PullPolicy, c.ImagePullPolicy)
assert.Equal(t, CtrInit, c.Name)
}

func Test_getManagerDeploymentObj(t *testing.T) {
deploy, err := testSideInput.getManagerDeploymentObj(*testPipeline, testGetSideInputDeploymentReq)
assert.NoError(t, err)
assert.NotNil(t, deploy)
assert.Equal(t, 1, len(deploy.Spec.Template.Spec.InitContainers))
assert.Equal(t, 2, len(deploy.Spec.Template.Spec.Containers))
}

0 comments on commit dab415a

Please sign in to comment.