Skip to content

Commit 1adb1d5

Browse files
committed
return error in update apis if the particular element does not exist
Signed-off-by: Stephanie <yangcao@redhat.com>
1 parent ec1e90d commit 1adb1d5

File tree

14 files changed

+231
-152
lines changed

14 files changed

+231
-152
lines changed

pkg/devfile/generator/generators_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestGetContainers(t *testing.T) {
5252
wantErr bool
5353
}{
5454
{
55-
name: "Case 1: Container with default project root",
55+
name: "Container with default project root",
5656
containerComponents: []v1.Component{
5757
{
5858
Name: containerNames[0],
@@ -87,7 +87,7 @@ func TestGetContainers(t *testing.T) {
8787
},
8888
},
8989
{
90-
name: "Case 2: Container with source mapping",
90+
name: "Container with source mapping",
9191
containerComponents: []v1.Component{
9292
{
9393
Name: containerNames[0],
@@ -123,7 +123,7 @@ func TestGetContainers(t *testing.T) {
123123
},
124124
},
125125
{
126-
name: "Case 3: Container with no mount source",
126+
name: "Container with no mount source",
127127
containerComponents: []v1.Component{
128128
{
129129
Name: containerNames[0],
@@ -141,7 +141,7 @@ func TestGetContainers(t *testing.T) {
141141
wantContainerImage: containerImages[0],
142142
},
143143
{
144-
name: "Case 4: Filter containers",
144+
name: "Filter containers",
145145
containerComponents: []v1.Component{
146146
{
147147
Name: containerNames[0],

pkg/devfile/generator/utils_test.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestConvertEnvs(t *testing.T) {
2929
want []corev1.EnvVar
3030
}{
3131
{
32-
name: "Case 1: One env var",
32+
name: "One env var",
3333
envVars: []v1.EnvVar{
3434
{
3535
Name: envVarsNames[0],
@@ -44,7 +44,7 @@ func TestConvertEnvs(t *testing.T) {
4444
},
4545
},
4646
{
47-
name: "Case 2: Multiple env vars",
47+
name: "Multiple env vars",
4848
envVars: []v1.EnvVar{
4949
{
5050
Name: envVarsNames[0],
@@ -75,7 +75,7 @@ func TestConvertEnvs(t *testing.T) {
7575
},
7676
},
7777
{
78-
name: "Case 3: No env vars",
78+
name: "No env vars",
7979
envVars: []v1.EnvVar{},
8080
want: []corev1.EnvVar{},
8181
},
@@ -100,7 +100,7 @@ func TestConvertPorts(t *testing.T) {
100100
want []corev1.ContainerPort
101101
}{
102102
{
103-
name: "Case 1: One Endpoint",
103+
name: "One Endpoint",
104104
endpoints: []v1.Endpoint{
105105
{
106106
Name: endpointsNames[0],
@@ -116,7 +116,7 @@ func TestConvertPorts(t *testing.T) {
116116
},
117117
},
118118
{
119-
name: "Case 2: Multiple endpoints",
119+
name: "Multiple endpoints",
120120
endpoints: []v1.Endpoint{
121121
{
122122
Name: endpointsNames[0],
@@ -141,7 +141,7 @@ func TestConvertPorts(t *testing.T) {
141141
},
142142
},
143143
{
144-
name: "Case 3: No endpoints",
144+
name: "No endpoints",
145145
endpoints: []v1.Endpoint{},
146146
want: []corev1.ContainerPort{},
147147
},
@@ -169,7 +169,7 @@ func TestGetResourceReqs(t *testing.T) {
169169
want corev1.ResourceRequirements
170170
}{
171171
{
172-
name: "Case 1: One Endpoint",
172+
name: "One Endpoint",
173173
component: v1.Component{
174174
Name: "testcomponent",
175175
ComponentUnion: v1.ComponentUnion{
@@ -187,12 +187,12 @@ func TestGetResourceReqs(t *testing.T) {
187187
},
188188
},
189189
{
190-
name: "Case 2: Empty Component",
190+
name: "Empty Component",
191191
component: v1.Component{},
192192
want: corev1.ResourceRequirements{},
193193
},
194194
{
195-
name: "Case 3: Valid container, but empty memoryLimit",
195+
name: "Valid container, but empty memoryLimit",
196196
component: v1.Component{
197197
Name: "testcomponent",
198198
ComponentUnion: v1.ComponentUnion{
@@ -225,12 +225,12 @@ func TestAddSyncRootFolder(t *testing.T) {
225225
wantSyncRootFolder string
226226
}{
227227
{
228-
name: "Case 1: Valid Source Mapping",
228+
name: "Valid Source Mapping",
229229
sourceMapping: "/mypath",
230230
wantSyncRootFolder: "/mypath",
231231
},
232232
{
233-
name: "Case 2: No Source Mapping",
233+
name: "No Source Mapping",
234234
sourceMapping: "",
235235
wantSyncRootFolder: DevfileSourceVolumeMount,
236236
},
@@ -268,13 +268,13 @@ func TestAddSyncFolder(t *testing.T) {
268268
wantErr bool
269269
}{
270270
{
271-
name: "Case 1: No projects",
271+
name: "No projects",
272272
projects: []v1.Project{},
273273
want: sourceVolumePath,
274274
wantErr: false,
275275
},
276276
{
277-
name: "Case 2: One project",
277+
name: "One project",
278278
projects: []v1.Project{
279279
{
280280
Name: projectNames[0],
@@ -291,7 +291,7 @@ func TestAddSyncFolder(t *testing.T) {
291291
wantErr: false,
292292
},
293293
{
294-
name: "Case 3: Multiple projects",
294+
name: "Multiple projects",
295295
projects: []v1.Project{
296296
{
297297
Name: projectNames[0],
@@ -326,7 +326,7 @@ func TestAddSyncFolder(t *testing.T) {
326326
wantErr: false,
327327
},
328328
{
329-
name: "Case 4: Clone path set",
329+
name: "Clone path set",
330330
projects: []v1.Project{
331331
{
332332
ClonePath: projectClonePath,
@@ -342,7 +342,7 @@ func TestAddSyncFolder(t *testing.T) {
342342
wantErr: false,
343343
},
344344
{
345-
name: "Case 5: Invalid clone path, set with absolute path",
345+
name: "Invalid clone path, set with absolute path",
346346
projects: []v1.Project{
347347
{
348348
ClonePath: invalidClonePaths[0],
@@ -360,7 +360,7 @@ func TestAddSyncFolder(t *testing.T) {
360360
wantErr: true,
361361
},
362362
{
363-
name: "Case 6: Invalid clone path, starts with ..",
363+
name: "Invalid clone path, starts with ..",
364364
projects: []v1.Project{
365365
{
366366
ClonePath: invalidClonePaths[1],
@@ -378,7 +378,7 @@ func TestAddSyncFolder(t *testing.T) {
378378
wantErr: true,
379379
},
380380
{
381-
name: "Case 7: Invalid clone path, contains ..",
381+
name: "Invalid clone path, contains ..",
382382
projects: []v1.Project{
383383
{
384384
ClonePath: invalidClonePaths[2],
@@ -427,7 +427,7 @@ func TestGetContainer(t *testing.T) {
427427
ports []corev1.ContainerPort
428428
}{
429429
{
430-
name: "Case 1: Empty container params",
430+
name: "Empty container params",
431431
containerName: "",
432432
image: "",
433433
isPrivileged: false,
@@ -438,7 +438,7 @@ func TestGetContainer(t *testing.T) {
438438
ports: []corev1.ContainerPort{},
439439
},
440440
{
441-
name: "Case 2: Valid container params",
441+
name: "Valid container params",
442442
containerName: "container1",
443443
image: "quay.io/eclipse/che-java8-maven:nightly",
444444
isPrivileged: true,
@@ -624,7 +624,7 @@ func TestGetServiceSpec(t *testing.T) {
624624
wantErr bool
625625
}{
626626
{
627-
name: "Case 1: multiple endpoints share the same port",
627+
name: "multiple endpoints share the same port",
628628
containerComponents: []v1.Component{
629629
{
630630
Name: "testcontainer1",
@@ -655,7 +655,7 @@ func TestGetServiceSpec(t *testing.T) {
655655
wantErr: false,
656656
},
657657
{
658-
name: "Case 2: multiple endpoints have different ports",
658+
name: "multiple endpoints have different ports",
659659
containerComponents: []v1.Component{
660660
{
661661
Name: "testcontainer1",
@@ -693,7 +693,7 @@ func TestGetServiceSpec(t *testing.T) {
693693
wantErr: false,
694694
},
695695
{
696-
name: "Case 3: filter components",
696+
name: "filter components",
697697
containerComponents: []v1.Component{
698698
{
699699
Name: "testcontainer1",
@@ -802,7 +802,7 @@ func TestGetPortExposure(t *testing.T) {
802802
wantErr bool
803803
}{
804804
{
805-
name: "Case 1: devfile has single container with single endpoint",
805+
name: "devfile has single container with single endpoint",
806806
wantMap: map[int]v1.EndpointExposure{
807807
8080: v1.PublicEndpointExposure,
808808
},
@@ -827,7 +827,7 @@ func TestGetPortExposure(t *testing.T) {
827827
},
828828
},
829829
{
830-
name: "Case 2: devfile no endpoints",
830+
name: "devfile no endpoints",
831831
wantMap: map[int]v1.EndpointExposure{},
832832
containerComponents: []v1.Component{
833833
{
@@ -843,7 +843,7 @@ func TestGetPortExposure(t *testing.T) {
843843
},
844844
},
845845
{
846-
name: "Case 3: devfile has multiple endpoints with same port, 1 public and 1 internal, should assign public",
846+
name: "devfile has multiple endpoints with same port, 1 public and 1 internal, should assign public",
847847
wantMap: map[int]v1.EndpointExposure{
848848
8080: v1.PublicEndpointExposure,
849849
},
@@ -873,7 +873,7 @@ func TestGetPortExposure(t *testing.T) {
873873
},
874874
},
875875
{
876-
name: "Case 4: devfile has multiple endpoints with same port, 1 public and 1 none, should assign public",
876+
name: "devfile has multiple endpoints with same port, 1 public and 1 none, should assign public",
877877
wantMap: map[int]v1.EndpointExposure{
878878
8080: v1.PublicEndpointExposure,
879879
},
@@ -903,7 +903,7 @@ func TestGetPortExposure(t *testing.T) {
903903
},
904904
},
905905
{
906-
name: "Case 5: devfile has multiple endpoints with same port, 1 internal and 1 none, should assign internal",
906+
name: "devfile has multiple endpoints with same port, 1 internal and 1 none, should assign internal",
907907
wantMap: map[int]v1.EndpointExposure{
908908
8080: v1.InternalEndpointExposure,
909909
},
@@ -933,7 +933,7 @@ func TestGetPortExposure(t *testing.T) {
933933
},
934934
},
935935
{
936-
name: "Case 6: devfile has multiple endpoints with different port",
936+
name: "devfile has multiple endpoints with different port",
937937
wantMap: map[int]v1.EndpointExposure{
938938
8080: v1.PublicEndpointExposure,
939939
9090: v1.InternalEndpointExposure,
@@ -984,7 +984,7 @@ func TestGetPortExposure(t *testing.T) {
984984
},
985985
},
986986
{
987-
name: "Case 7: Filter components",
987+
name: "Filter components",
988988
wantMap: map[int]v1.EndpointExposure{
989989
8080: v1.PublicEndpointExposure,
990990
3000: v1.NoneEndpointExposure,
@@ -1043,7 +1043,7 @@ func TestGetPortExposure(t *testing.T) {
10431043
},
10441044
},
10451045
{
1046-
name: "Case 8: Wrong filter components",
1046+
name: "Wrong filter components",
10471047
wantMap: map[int]v1.EndpointExposure{},
10481048
containerComponents: []v1.Component{
10491049
{
@@ -1159,7 +1159,7 @@ func TestGetRouteSpec(t *testing.T) {
11591159
parameter RouteSpecParams
11601160
}{
11611161
{
1162-
name: "Case 1: insecure route",
1162+
name: "insecure route",
11631163
parameter: RouteSpecParams{
11641164
ServiceName: "service1",
11651165
PortNumber: intstr.IntOrString{
@@ -1170,7 +1170,7 @@ func TestGetRouteSpec(t *testing.T) {
11701170
},
11711171
},
11721172
{
1173-
name: "Case 2: secure route",
1173+
name: "secure route",
11741174
parameter: RouteSpecParams{
11751175
ServiceName: "service1",
11761176
PortNumber: intstr.IntOrString{
@@ -1215,12 +1215,12 @@ func TestGetPVCSpec(t *testing.T) {
12151215
wantErr bool
12161216
}{
12171217
{
1218-
name: "Case 1: Valid resource size",
1218+
name: "Valid resource size",
12191219
size: "1Gi",
12201220
wantErr: false,
12211221
},
12221222
{
1223-
name: "Case 2: Resource size missing",
1223+
name: "Resource size missing",
12241224
size: "",
12251225
wantErr: true,
12261226
},
@@ -1270,13 +1270,13 @@ func TestGetBuildConfigSpec(t *testing.T) {
12701270
buildStrategy buildv1.BuildStrategy
12711271
}{
12721272
{
1273-
name: "Case 1: Get a Source Strategy Build Config",
1273+
name: "Get a Source Strategy Build Config",
12741274
GitURL: "url",
12751275
GitRef: "ref",
12761276
buildStrategy: GetSourceBuildStrategy(image, namespace),
12771277
},
12781278
{
1279-
name: "Case 2: Get a Docker Strategy Build Config",
1279+
name: "Get a Docker Strategy Build Config",
12801280
GitURL: "url",
12811281
GitRef: "ref",
12821282
ContextDir: "./",

pkg/devfile/parser/configurables_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestAddAndRemoveEnvVars(t *testing.T) {
2424
wantDevFile DevfileObj
2525
}{
2626
{
27-
name: "case 1: add and remove env vars",
27+
name: "add and remove env vars",
2828
listToAdd: []v1.EnvVar{
2929
{
3030
Name: "DATABASE_PASSWORD",

pkg/devfile/parser/data/interface.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ type DevfileData interface {
2525
// component related methods
2626
GetComponents(common.DevfileOptions) ([]v1.Component, error)
2727
AddComponents(components []v1.Component) error
28-
UpdateComponent(component v1.Component)
28+
UpdateComponent(component v1.Component) error
2929
DeleteComponent(name string) error
3030

3131
// project related methods
3232
GetProjects(common.DevfileOptions) ([]v1.Project, error)
3333
AddProjects(projects []v1.Project) error
34-
UpdateProject(project v1.Project)
34+
UpdateProject(project v1.Project) error
3535
DeleteProject(name string) error
3636

3737
// starter projects related commands
3838
GetStarterProjects(common.DevfileOptions) ([]v1.StarterProject, error)
3939
AddStarterProjects(projects []v1.StarterProject) error
40-
UpdateStarterProject(project v1.StarterProject)
40+
UpdateStarterProject(project v1.StarterProject) error
4141
DeleteStarterProject(name string) error
4242

4343
// command related methods
4444
GetCommands(common.DevfileOptions) ([]v1.Command, error)
4545
AddCommands(commands []v1.Command) error
46-
UpdateCommand(command v1.Command)
46+
UpdateCommand(command v1.Command) error
4747
DeleteCommand(id string) error
4848

4949
// volume mount related methods

0 commit comments

Comments
 (0)