Skip to content

Commit

Permalink
Add suggested test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <[email protected]>
  • Loading branch information
valaparthvi committed Jan 5, 2023
1 parent a71988e commit ae3d5d1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
38 changes: 31 additions & 7 deletions pkg/devfile/generator/generators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,8 +1078,9 @@ func TestGetDeployment(t *testing.T) {
name string
containerComponents []v1.Component
deploymentParams DeploymentParams
expected appsv1.Deployment
expected *appsv1.Deployment
attributes attributes.Attributes
wantErr bool
}{
{
// Currently dedicatedPod can only filter out annotations
Expand Down Expand Up @@ -1111,7 +1112,7 @@ func TestGetDeployment(t *testing.T) {
Containers: containers,
Replicas: pointer.Int32Ptr(1),
},
expected: appsv1.Deployment{
expected: &appsv1.Deployment{
ObjectMeta: objectMetaDedicatedPod,
Spec: appsv1.DeploymentSpec{
Strategy: appsv1.DeploymentStrategy{
Expand Down Expand Up @@ -1157,7 +1158,7 @@ func TestGetDeployment(t *testing.T) {
},
Containers: containers,
},
expected: appsv1.Deployment{
expected: &appsv1.Deployment{
ObjectMeta: objectMeta,
Spec: appsv1.DeploymentSpec{
Strategy: appsv1.DeploymentStrategy{
Expand Down Expand Up @@ -1205,7 +1206,7 @@ func TestGetDeployment(t *testing.T) {
},
Containers: containers,
},
expected: appsv1.Deployment{
expected: &appsv1.Deployment{
ObjectMeta: objectMeta,
Spec: appsv1.DeploymentSpec{
Strategy: appsv1.DeploymentStrategy{
Expand All @@ -1224,6 +1225,29 @@ func TestGetDeployment(t *testing.T) {
},
},
},
{
name: "pod has an invalid pod-overrides attribute that throws error",
containerComponents: []v1.Component{
testingutil.GenerateDummyContainerComponent("container2", nil, nil, nil, v1.Annotation{
Deployment: map[string]string{
"key2": "value2",
},
}, nil),
},
attributes: attributes.Attributes{
PodOverridesAttribute: apiext.JSON{Raw: []byte("{\"spec\": \"serviceAccountName\": \"new-service-account\"}}")},
},
deploymentParams: DeploymentParams{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"preserved-key": "preserved-value",
},
},
Containers: containers,
},
expected: nil,
wantErr: trueBool,
},
}

for _, tt := range tests {
Expand All @@ -1247,10 +1271,10 @@ func TestGetDeployment(t *testing.T) {
}
deploy, err := GetDeployment(devObj, tt.deploymentParams)
// Checks for unexpected error cases
if err != nil {
t.Errorf("TestGetDeployment(): unexpected error %v", err)
if !tt.wantErr == (err != nil) {
t.Errorf("TestGetDeployment(): unexpected error %v, wantErr %v", err, tt.wantErr)
}
assert.Equal(t, tt.expected, *deploy, "TestGetDeployment(): The two values should be the same.")
assert.Equal(t, tt.expected, deploy, "TestGetDeployment(): The two values should be the same.")

})
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/devfile/generator/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,27 @@ func Test_applyPodOverrides(t *testing.T) {
}(),
wantErr: false,
},
{
name: "Should override field as defined inside pod-overrides container level attribute",
args: args{
components: []v1.Component{
func() v1.Component {
container := devfileContainer
container.Attributes = attributes.Attributes{
PodOverridesAttribute: apiextensionsv1.JSON{Raw: []byte("{\"spec\": {\"schedulerName\": \"stork\"}}")},
}
return container
}(),
},
podTemplateSpec: &defaultPodSpec,
},
want: func() *corev1.PodTemplateSpec {
podSpec := defaultPodSpec
podSpec.Spec.SchedulerName = "stork"
return &podSpec
}(),
wantErr: false,
},
{
name: "Should override fields as defined inside pod-overrides attribute at devfile and container level",
args: args{
Expand Down

0 comments on commit ae3d5d1

Please sign in to comment.