Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <pvala@redhat.com>
  • Loading branch information
valaparthvi committed Dec 8, 2022
1 parent 243b038 commit 16a439f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
5 changes: 2 additions & 3 deletions pkg/devfile/generator/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,12 @@ func GetDeployment(devfileObj parser.DevfileObj, deployParams DeploymentParams)
Containers: deployParams.Containers,
Volumes: deployParams.Volumes,
}

globalAttributes, err := devfileObj.Data.GetAttributes()
if err != nil {
return nil, err
}
components, err := devfileObj.Data.GetDevfileContainerComponents(common.DevfileOptions{
FilterByName: "",
})
components, err := devfileObj.Data.GetDevfileContainerComponents(common.DevfileOptions{})
if err != nil {
return nil, err
}
Expand Down
63 changes: 58 additions & 5 deletions pkg/devfile/generator/generators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ package generator

import (
"fmt"
apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"reflect"
"strings"
"testing"

"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"
"reflect"
"strings"
"testing"

v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/api/v2/pkg/attributes"
Expand Down Expand Up @@ -1077,6 +1079,7 @@ func TestGetDeployment(t *testing.T) {
containerComponents []v1.Component
deploymentParams DeploymentParams
expected appsv1.Deployment
attributes attributes.Attributes
}{
{
// Currently dedicatedPod can only filter out annotations
Expand Down Expand Up @@ -1172,6 +1175,55 @@ func TestGetDeployment(t *testing.T) {
},
},
},
{
name: "pod should have pod-overrides attribute",
containerComponents: []v1.Component{
testingutil.GenerateDummyContainerComponent("container1", nil, []v1.Endpoint{
{
Name: "http-8080",
TargetPort: 8080,
},
}, nil, v1.Annotation{
Deployment: map[string]string{
"key1": "value1",
},
}, nil),
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: appsv1.Deployment{
ObjectMeta: objectMeta,
Spec: appsv1.DeploymentSpec{
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RecreateDeploymentStrategyType,
},
Selector: &metav1.LabelSelector{
MatchLabels: nil,
},
Template: corev1.PodTemplateSpec{
ObjectMeta: objectMeta,
Spec: corev1.PodSpec{
Containers: containers,
ServiceAccountName: "new-service-account",
},
},
},
},
},
}

for _, tt := range tests {
Expand All @@ -1186,8 +1238,9 @@ func TestGetDeployment(t *testing.T) {
},
}
// set up the mock data
mockGetComponents := mockDevfileData.EXPECT().GetComponents(options)
mockGetComponents.Return(tt.containerComponents, nil).AnyTimes()
mockDevfileData.EXPECT().GetAttributes().Return(tt.attributes, nil).AnyTimes()
mockDevfileData.EXPECT().GetDevfileContainerComponents(common.DevfileOptions{}).Return(tt.containerComponents, nil).AnyTimes()
mockDevfileData.EXPECT().GetComponents(options).Return(tt.containerComponents, nil).AnyTimes()

devObj := parser.DevfileObj{
Data: mockDevfileData,
Expand Down
1 change: 1 addition & 0 deletions pkg/devfile/generator/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func getPodTemplateSpec(globalAttributes attributes.Attributes, components []v1.
if err != nil {
return nil, err
}
patchedPodTemplateSpec.ObjectMeta = podTemplateSpecParams.ObjectMeta
podTemplateSpec = patchedPodTemplateSpec
}

Expand Down

0 comments on commit 16a439f

Please sign in to comment.