1 package component
2
3 import (
4 "context"
5 "testing"
6
7 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
8 "github.com/devfile/library/v2/pkg/devfile/parser"
9 "github.com/devfile/library/v2/pkg/devfile/parser/data"
10 "github.com/golang/mock/gomock"
11 "github.com/redhat-developer/odo/pkg/config"
12 envcontext "github.com/redhat-developer/odo/pkg/config/context"
13 "github.com/redhat-developer/odo/pkg/configAutomount"
14 "github.com/redhat-developer/odo/pkg/devfile/image"
15 "github.com/redhat-developer/odo/pkg/exec"
16 "github.com/redhat-developer/odo/pkg/kclient"
17 "github.com/redhat-developer/odo/pkg/libdevfile"
18 odocontext "github.com/redhat-developer/odo/pkg/odo/context"
19 "github.com/redhat-developer/odo/pkg/platform"
20 "github.com/redhat-developer/odo/pkg/podman"
21 "github.com/redhat-developer/odo/pkg/testingutil/filesystem"
22 "github.com/sethvargo/go-envconfig"
23 batchv1 "k8s.io/api/batch/v1"
24 "k8s.io/utils/pointer"
25 )
26
27 var (
28
29
30 containerComponent = v1alpha2.Component{
31 Name: "my-container",
32 ComponentUnion: v1alpha2.ComponentUnion{
33 Container: &v1alpha2.ContainerComponent{
34 Container: v1alpha2.Container{
35 Image: "my-image",
36 },
37 Endpoints: []v1alpha2.Endpoint{
38 {
39 Name: "http",
40 TargetPort: 8080,
41 },
42 {
43 Name: "debug",
44 TargetPort: 5858,
45 },
46 },
47 },
48 },
49 }
50
51 kubernetesComponent = v1alpha2.Component{
52 Name: "my-kubernetes",
53 ComponentUnion: v1alpha2.ComponentUnion{
54 Kubernetes: &v1alpha2.KubernetesComponent{
55 K8sLikeComponent: v1alpha2.K8sLikeComponent{
56 K8sLikeComponentLocation: v1alpha2.K8sLikeComponentLocation{
57 Inlined: `spec: {}`,
58 },
59 },
60 },
61 },
62 }
63
64 openshiftComponent = v1alpha2.Component{
65 Name: "my-openshift",
66 ComponentUnion: v1alpha2.ComponentUnion{
67 Openshift: &v1alpha2.OpenshiftComponent{
68 K8sLikeComponent: v1alpha2.K8sLikeComponent{
69 K8sLikeComponentLocation: v1alpha2.K8sLikeComponentLocation{
70 Inlined: `spec: {}`,
71 },
72 },
73 },
74 },
75 }
76
77 imageComponent = v1alpha2.Component{
78 Name: "my-image",
79 ComponentUnion: v1alpha2.ComponentUnion{
80 Image: &v1alpha2.ImageComponent{
81 Image: v1alpha2.Image{
82 ImageName: "golang",
83 },
84 },
85 },
86 }
87
88
89
90 execOnContainer = v1alpha2.Command{
91 Id: "my-exec-on-container",
92 CommandUnion: v1alpha2.CommandUnion{
93 Exec: &v1alpha2.ExecCommand{
94 CommandLine: "go build main.go",
95 Component: "my-container",
96 },
97 },
98 }
99
100 applyKubernetes = v1alpha2.Command{
101 Id: "my-apply-kubernetes",
102 CommandUnion: v1alpha2.CommandUnion{
103 Apply: &v1alpha2.ApplyCommand{
104 Component: "my-kubernetes",
105 },
106 },
107 }
108 applyOpenshift = v1alpha2.Command{
109 Id: "my-apply-openshift",
110 CommandUnion: v1alpha2.CommandUnion{
111 Apply: &v1alpha2.ApplyCommand{
112 Component: "my-openshift",
113 },
114 },
115 }
116
117 applyImage = v1alpha2.Command{
118 Id: "my-apply-image",
119 CommandUnion: v1alpha2.CommandUnion{
120 Apply: &v1alpha2.ApplyCommand{
121 Component: "my-image",
122 },
123 },
124 }
125 )
126
127 func CommandWithKind(command v1alpha2.Command, kind v1alpha2.CommandGroupKind, isDefault *bool) v1alpha2.Command {
128 group := &v1alpha2.CommandGroup{
129 Kind: kind,
130 IsDefault: isDefault,
131 }
132
133 if command.Exec != nil {
134 command.Exec.Group = group
135 }
136
137 if command.Apply != nil {
138 command.Apply.Group = group
139 }
140
141 if command.Composite != nil {
142 command.Composite.Group = group
143 }
144
145 return command
146 }
147
148 func TestHandler(t *testing.T) {
149
150 appName := "app"
151 componentName := "componentName"
152
153 tests := []struct {
154 name string
155 podName string
156 msg string
157 show bool
158 componentExists bool
159
160 devfileObjDeploy func() parser.DevfileObj
161 devfileObjBuild func() parser.DevfileObj
162 devfileObjRun func() parser.DevfileObj
163 DevfileObjPostStart func() parser.DevfileObj
164 DevfileObjPreStop func() parser.DevfileObj
165
166 platformClient func(ctrl *gomock.Controller) platform.Client
167 execClient func(ctrl *gomock.Controller) exec.Client
168 configAutomountClient func(ctrl *gomock.Controller) configAutomount.Client
169 imageBackend func(ctrl *gomock.Controller) image.Backend
170 env map[string]string
171 wantErr bool
172 }{
173 {
174 name: "Devfile with Apply Kubernetes command on cluster",
175 devfileObjDeploy: func() parser.DevfileObj {
176 devfileData, err := data.NewDevfileData("2.1.0")
177 if err != nil {
178 t.Error(err)
179 }
180 devfileData.SetSchemaVersion("2.1.0")
181 _ = devfileData.AddComponents([]v1alpha2.Component{
182 kubernetesComponent,
183 })
184 _ = devfileData.AddCommands([]v1alpha2.Command{
185 CommandWithKind(applyKubernetes, v1alpha2.DeployCommandGroupKind, pointer.Bool(true)),
186 })
187
188 devfileObj := parser.DevfileObj{
189 Data: devfileData,
190 }
191 return devfileObj
192 },
193 devfileObjBuild: func() parser.DevfileObj {
194 devfileData, err := data.NewDevfileData("2.1.0")
195 if err != nil {
196 t.Error(err)
197 }
198 devfileData.SetSchemaVersion("2.1.0")
199 _ = devfileData.AddComponents([]v1alpha2.Component{
200 kubernetesComponent,
201 })
202 _ = devfileData.AddCommands([]v1alpha2.Command{
203 CommandWithKind(applyKubernetes, v1alpha2.BuildCommandGroupKind, pointer.Bool(true)),
204 })
205
206 devfileObj := parser.DevfileObj{
207 Data: devfileData,
208 }
209 return devfileObj
210 },
211 devfileObjRun: func() parser.DevfileObj {
212 devfileData, err := data.NewDevfileData("2.1.0")
213 if err != nil {
214 t.Error(err)
215 }
216 devfileData.SetSchemaVersion("2.1.0")
217 _ = devfileData.AddComponents([]v1alpha2.Component{
218 kubernetesComponent,
219 })
220 _ = devfileData.AddCommands([]v1alpha2.Command{
221 CommandWithKind(applyKubernetes, v1alpha2.RunCommandGroupKind, pointer.Bool(true)),
222 })
223
224 devfileObj := parser.DevfileObj{
225 Data: devfileData,
226 }
227 return devfileObj
228 },
229 DevfileObjPostStart: func() parser.DevfileObj {
230 devfileData, err := data.NewDevfileData("2.1.0")
231 if err != nil {
232 t.Error(err)
233 }
234 devfileData.SetSchemaVersion("2.1.0")
235 _ = devfileData.AddComponents([]v1alpha2.Component{
236 kubernetesComponent,
237 })
238 _ = devfileData.AddCommands([]v1alpha2.Command{
239 applyKubernetes,
240 })
241 _ = devfileData.AddEvents(v1alpha2.Events{
242 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
243 PostStart: []string{applyKubernetes.Id},
244 },
245 })
246 devfileObj := parser.DevfileObj{
247 Data: devfileData,
248 }
249 return devfileObj
250 },
251 DevfileObjPreStop: func() parser.DevfileObj {
252 devfileData, err := data.NewDevfileData("2.1.0")
253 if err != nil {
254 t.Error(err)
255 }
256 devfileData.SetSchemaVersion("2.1.0")
257 _ = devfileData.AddComponents([]v1alpha2.Component{
258 kubernetesComponent,
259 })
260 _ = devfileData.AddCommands([]v1alpha2.Command{
261 applyKubernetes,
262 })
263 _ = devfileData.AddEvents(v1alpha2.Events{
264 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
265 PreStop: []string{applyKubernetes.Id},
266 },
267 })
268 devfileObj := parser.DevfileObj{
269 Data: devfileData,
270 }
271 return devfileObj
272 },
273 platformClient: func(ctrl *gomock.Controller) platform.Client {
274 client := kclient.NewMockClientInterface(ctrl)
275
276
277 client.EXPECT().GetRestMappingFromUnstructured(gomock.Any())
278 client.EXPECT().IsServiceBindingSupported()
279 client.EXPECT().PatchDynamicResource(gomock.Any())
280
281 return client
282 },
283 execClient: func(ctrl *gomock.Controller) exec.Client {
284 client := exec.NewMockClient(ctrl)
285 return client
286 },
287 configAutomountClient: func(ctrl *gomock.Controller) configAutomount.Client {
288 return nil
289 },
290 imageBackend: func(ctrl *gomock.Controller) image.Backend {
291 return nil
292 },
293 },
294 {
295 name: "Devfile with Apply Kubernetes command on podman",
296 devfileObjDeploy: func() parser.DevfileObj {
297 devfileData, err := data.NewDevfileData("2.1.0")
298 if err != nil {
299 t.Error(err)
300 }
301 devfileData.SetSchemaVersion("2.1.0")
302 _ = devfileData.AddComponents([]v1alpha2.Component{
303 kubernetesComponent,
304 })
305 _ = devfileData.AddCommands([]v1alpha2.Command{
306 CommandWithKind(applyKubernetes, v1alpha2.DeployCommandGroupKind, pointer.Bool(true)),
307 })
308
309 devfileObj := parser.DevfileObj{
310 Data: devfileData,
311 }
312 return devfileObj
313 },
314 devfileObjBuild: func() parser.DevfileObj {
315 devfileData, err := data.NewDevfileData("2.1.0")
316 if err != nil {
317 t.Error(err)
318 }
319 devfileData.SetSchemaVersion("2.1.0")
320 _ = devfileData.AddComponents([]v1alpha2.Component{
321 kubernetesComponent,
322 })
323 _ = devfileData.AddCommands([]v1alpha2.Command{
324 CommandWithKind(applyKubernetes, v1alpha2.BuildCommandGroupKind, pointer.Bool(true)),
325 })
326
327 devfileObj := parser.DevfileObj{
328 Data: devfileData,
329 }
330 return devfileObj
331 },
332 devfileObjRun: func() parser.DevfileObj {
333 devfileData, err := data.NewDevfileData("2.1.0")
334 if err != nil {
335 t.Error(err)
336 }
337 devfileData.SetSchemaVersion("2.1.0")
338 _ = devfileData.AddComponents([]v1alpha2.Component{
339 kubernetesComponent,
340 })
341 _ = devfileData.AddCommands([]v1alpha2.Command{
342 CommandWithKind(applyKubernetes, v1alpha2.RunCommandGroupKind, pointer.Bool(true)),
343 })
344
345 devfileObj := parser.DevfileObj{
346 Data: devfileData,
347 }
348 return devfileObj
349 },
350 DevfileObjPostStart: func() parser.DevfileObj {
351 devfileData, err := data.NewDevfileData("2.1.0")
352 if err != nil {
353 t.Error(err)
354 }
355 devfileData.SetSchemaVersion("2.1.0")
356 _ = devfileData.AddComponents([]v1alpha2.Component{
357 kubernetesComponent,
358 })
359 _ = devfileData.AddCommands([]v1alpha2.Command{
360 applyKubernetes,
361 })
362 _ = devfileData.AddEvents(v1alpha2.Events{
363 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
364 PostStart: []string{applyKubernetes.Id},
365 },
366 })
367
368 devfileObj := parser.DevfileObj{
369 Data: devfileData,
370 }
371 return devfileObj
372 },
373 DevfileObjPreStop: func() parser.DevfileObj {
374 devfileData, err := data.NewDevfileData("2.1.0")
375 if err != nil {
376 t.Error(err)
377 }
378 devfileData.SetSchemaVersion("2.1.0")
379 _ = devfileData.AddComponents([]v1alpha2.Component{
380 kubernetesComponent,
381 })
382 _ = devfileData.AddCommands([]v1alpha2.Command{
383 applyKubernetes,
384 })
385 _ = devfileData.AddEvents(v1alpha2.Events{
386 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
387 PreStop: []string{applyKubernetes.Id},
388 },
389 })
390
391 devfileObj := parser.DevfileObj{
392 Data: devfileData,
393 }
394 return devfileObj
395 },
396 platformClient: func(ctrl *gomock.Controller) platform.Client {
397 client := podman.NewMockClient(ctrl)
398
399 return client
400 },
401 execClient: func(ctrl *gomock.Controller) exec.Client {
402 client := exec.NewMockClient(ctrl)
403 return client
404 },
405 configAutomountClient: func(ctrl *gomock.Controller) configAutomount.Client {
406 return nil
407 },
408 imageBackend: func(ctrl *gomock.Controller) image.Backend {
409 return nil
410
411 },
412 wantErr: false,
413 },
414
415 {
416 name: "Devfile with Apply Openshift command on cluster",
417 devfileObjDeploy: func() parser.DevfileObj {
418 devfileData, err := data.NewDevfileData("2.1.0")
419 if err != nil {
420 t.Error(err)
421 }
422 devfileData.SetSchemaVersion("2.1.0")
423 _ = devfileData.AddComponents([]v1alpha2.Component{
424 openshiftComponent,
425 })
426 _ = devfileData.AddCommands([]v1alpha2.Command{
427 CommandWithKind(applyOpenshift, v1alpha2.DeployCommandGroupKind, pointer.Bool(true)),
428 })
429
430 devfileObj := parser.DevfileObj{
431 Data: devfileData,
432 }
433 return devfileObj
434 },
435 devfileObjBuild: func() parser.DevfileObj {
436 devfileData, err := data.NewDevfileData("2.1.0")
437 if err != nil {
438 t.Error(err)
439 }
440 devfileData.SetSchemaVersion("2.1.0")
441 _ = devfileData.AddComponents([]v1alpha2.Component{
442 openshiftComponent,
443 })
444 _ = devfileData.AddCommands([]v1alpha2.Command{
445 CommandWithKind(applyOpenshift, v1alpha2.BuildCommandGroupKind, pointer.Bool(true)),
446 })
447
448 devfileObj := parser.DevfileObj{
449 Data: devfileData,
450 }
451 return devfileObj
452 },
453 devfileObjRun: func() parser.DevfileObj {
454 devfileData, err := data.NewDevfileData("2.1.0")
455 if err != nil {
456 t.Error(err)
457 }
458 devfileData.SetSchemaVersion("2.1.0")
459 _ = devfileData.AddComponents([]v1alpha2.Component{
460 openshiftComponent,
461 })
462 _ = devfileData.AddCommands([]v1alpha2.Command{
463 CommandWithKind(applyOpenshift, v1alpha2.RunCommandGroupKind, pointer.Bool(true)),
464 })
465
466 devfileObj := parser.DevfileObj{
467 Data: devfileData,
468 }
469 return devfileObj
470 },
471 DevfileObjPostStart: func() parser.DevfileObj {
472 devfileData, err := data.NewDevfileData("2.1.0")
473 if err != nil {
474 t.Error(err)
475 }
476 devfileData.SetSchemaVersion("2.1.0")
477 _ = devfileData.AddComponents([]v1alpha2.Component{
478 openshiftComponent,
479 })
480 _ = devfileData.AddCommands([]v1alpha2.Command{
481 applyOpenshift,
482 })
483 _ = devfileData.AddEvents(v1alpha2.Events{
484 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
485 PostStart: []string{applyOpenshift.Id},
486 },
487 })
488
489 devfileObj := parser.DevfileObj{
490 Data: devfileData,
491 }
492 return devfileObj
493 },
494 DevfileObjPreStop: func() parser.DevfileObj {
495 devfileData, err := data.NewDevfileData("2.1.0")
496 if err != nil {
497 t.Error(err)
498 }
499 devfileData.SetSchemaVersion("2.1.0")
500 _ = devfileData.AddComponents([]v1alpha2.Component{
501 openshiftComponent,
502 })
503 _ = devfileData.AddCommands([]v1alpha2.Command{
504 applyOpenshift,
505 })
506 _ = devfileData.AddEvents(v1alpha2.Events{
507 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
508 PreStop: []string{applyOpenshift.Id},
509 },
510 })
511
512 devfileObj := parser.DevfileObj{
513 Data: devfileData,
514 }
515 return devfileObj
516 },
517 platformClient: func(ctrl *gomock.Controller) platform.Client {
518 client := kclient.NewMockClientInterface(ctrl)
519
520
521 client.EXPECT().GetRestMappingFromUnstructured(gomock.Any())
522 client.EXPECT().IsServiceBindingSupported()
523 client.EXPECT().PatchDynamicResource(gomock.Any())
524
525 return client
526 },
527 execClient: func(ctrl *gomock.Controller) exec.Client {
528 client := exec.NewMockClient(ctrl)
529 return client
530 },
531 configAutomountClient: func(ctrl *gomock.Controller) configAutomount.Client {
532 return nil
533 },
534 imageBackend: func(ctrl *gomock.Controller) image.Backend {
535 return nil
536
537 },
538 },
539 {
540 name: "Devfile with Apply Openshift command on podman",
541 devfileObjDeploy: func() parser.DevfileObj {
542 devfileData, err := data.NewDevfileData("2.1.0")
543 if err != nil {
544 t.Error(err)
545 }
546 devfileData.SetSchemaVersion("2.1.0")
547 _ = devfileData.AddComponents([]v1alpha2.Component{
548 openshiftComponent,
549 })
550 _ = devfileData.AddCommands([]v1alpha2.Command{
551 CommandWithKind(applyOpenshift, v1alpha2.DeployCommandGroupKind, pointer.Bool(true)),
552 })
553
554 devfileObj := parser.DevfileObj{
555 Data: devfileData,
556 }
557 return devfileObj
558 },
559 devfileObjBuild: func() parser.DevfileObj {
560 devfileData, err := data.NewDevfileData("2.1.0")
561 if err != nil {
562 t.Error(err)
563 }
564 devfileData.SetSchemaVersion("2.1.0")
565 _ = devfileData.AddComponents([]v1alpha2.Component{
566 openshiftComponent,
567 })
568 _ = devfileData.AddCommands([]v1alpha2.Command{
569 CommandWithKind(applyOpenshift, v1alpha2.BuildCommandGroupKind, pointer.Bool(true)),
570 })
571
572 devfileObj := parser.DevfileObj{
573 Data: devfileData,
574 }
575 return devfileObj
576 },
577 devfileObjRun: func() parser.DevfileObj {
578 devfileData, err := data.NewDevfileData("2.1.0")
579 if err != nil {
580 t.Error(err)
581 }
582 devfileData.SetSchemaVersion("2.1.0")
583 _ = devfileData.AddComponents([]v1alpha2.Component{
584 openshiftComponent,
585 })
586 _ = devfileData.AddCommands([]v1alpha2.Command{
587 CommandWithKind(applyOpenshift, v1alpha2.RunCommandGroupKind, pointer.Bool(true)),
588 })
589
590 devfileObj := parser.DevfileObj{
591 Data: devfileData,
592 }
593 return devfileObj
594 },
595 DevfileObjPostStart: func() parser.DevfileObj {
596 devfileData, err := data.NewDevfileData("2.1.0")
597 if err != nil {
598 t.Error(err)
599 }
600 devfileData.SetSchemaVersion("2.1.0")
601 _ = devfileData.AddComponents([]v1alpha2.Component{
602 openshiftComponent,
603 })
604 _ = devfileData.AddCommands([]v1alpha2.Command{
605 applyOpenshift,
606 })
607 _ = devfileData.AddEvents(v1alpha2.Events{
608 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
609 PostStart: []string{applyOpenshift.Id},
610 },
611 })
612
613 devfileObj := parser.DevfileObj{
614 Data: devfileData,
615 }
616 return devfileObj
617 },
618 DevfileObjPreStop: func() parser.DevfileObj {
619 devfileData, err := data.NewDevfileData("2.1.0")
620 if err != nil {
621 t.Error(err)
622 }
623 devfileData.SetSchemaVersion("2.1.0")
624 _ = devfileData.AddComponents([]v1alpha2.Component{
625 openshiftComponent,
626 })
627 _ = devfileData.AddCommands([]v1alpha2.Command{
628 applyOpenshift,
629 })
630 _ = devfileData.AddEvents(v1alpha2.Events{
631 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
632 PreStop: []string{applyOpenshift.Id},
633 },
634 })
635
636 devfileObj := parser.DevfileObj{
637 Data: devfileData,
638 }
639 return devfileObj
640 },
641 platformClient: func(ctrl *gomock.Controller) platform.Client {
642 client := podman.NewMockClient(ctrl)
643
644 return client
645 },
646 execClient: func(ctrl *gomock.Controller) exec.Client {
647 client := exec.NewMockClient(ctrl)
648 return client
649 },
650 configAutomountClient: func(ctrl *gomock.Controller) configAutomount.Client {
651 return nil
652 },
653 imageBackend: func(ctrl *gomock.Controller) image.Backend {
654 return nil
655
656 },
657 wantErr: false,
658 },
659
660 {
661 name: "Devfile with Apply Image command on cluster",
662 devfileObjDeploy: func() parser.DevfileObj {
663 devfileData, err := data.NewDevfileData("2.1.0")
664 if err != nil {
665 t.Error(err)
666 }
667 devfileData.SetSchemaVersion("2.1.0")
668 _ = devfileData.AddComponents([]v1alpha2.Component{
669 imageComponent,
670 })
671 _ = devfileData.AddCommands([]v1alpha2.Command{
672 CommandWithKind(applyImage, v1alpha2.DeployCommandGroupKind, pointer.Bool(true)),
673 })
674
675 devfileObj := parser.DevfileObj{
676 Data: devfileData,
677 }
678 return devfileObj
679 },
680 devfileObjBuild: func() parser.DevfileObj {
681 devfileData, err := data.NewDevfileData("2.1.0")
682 if err != nil {
683 t.Error(err)
684 }
685 devfileData.SetSchemaVersion("2.1.0")
686 _ = devfileData.AddComponents([]v1alpha2.Component{
687 imageComponent,
688 })
689 _ = devfileData.AddCommands([]v1alpha2.Command{
690 CommandWithKind(applyImage, v1alpha2.BuildCommandGroupKind, pointer.Bool(true)),
691 })
692
693 devfileObj := parser.DevfileObj{
694 Data: devfileData,
695 }
696 return devfileObj
697 },
698 devfileObjRun: func() parser.DevfileObj {
699 devfileData, err := data.NewDevfileData("2.1.0")
700 if err != nil {
701 t.Error(err)
702 }
703 devfileData.SetSchemaVersion("2.1.0")
704 _ = devfileData.AddComponents([]v1alpha2.Component{
705 imageComponent,
706 })
707 _ = devfileData.AddCommands([]v1alpha2.Command{
708 CommandWithKind(applyImage, v1alpha2.RunCommandGroupKind, pointer.Bool(true)),
709 })
710
711 devfileObj := parser.DevfileObj{
712 Data: devfileData,
713 }
714 return devfileObj
715 },
716 DevfileObjPostStart: func() parser.DevfileObj {
717 devfileData, err := data.NewDevfileData("2.1.0")
718 if err != nil {
719 t.Error(err)
720 }
721 devfileData.SetSchemaVersion("2.1.0")
722 _ = devfileData.AddComponents([]v1alpha2.Component{
723 imageComponent,
724 })
725 _ = devfileData.AddCommands([]v1alpha2.Command{
726 applyImage,
727 })
728 _ = devfileData.AddEvents(v1alpha2.Events{
729 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
730 PostStart: []string{applyImage.Id},
731 },
732 })
733
734 devfileObj := parser.DevfileObj{
735 Data: devfileData,
736 }
737 return devfileObj
738 },
739 DevfileObjPreStop: func() parser.DevfileObj {
740 devfileData, err := data.NewDevfileData("2.1.0")
741 if err != nil {
742 t.Error(err)
743 }
744 devfileData.SetSchemaVersion("2.1.0")
745 _ = devfileData.AddComponents([]v1alpha2.Component{
746 imageComponent,
747 })
748 _ = devfileData.AddCommands([]v1alpha2.Command{
749 applyImage,
750 })
751 _ = devfileData.AddEvents(v1alpha2.Events{
752 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
753 PreStop: []string{applyImage.Id},
754 },
755 })
756
757 devfileObj := parser.DevfileObj{
758 Data: devfileData,
759 }
760 return devfileObj
761 },
762 platformClient: func(ctrl *gomock.Controller) platform.Client {
763 client := kclient.NewMockClientInterface(ctrl)
764 return client
765 },
766 execClient: func(ctrl *gomock.Controller) exec.Client {
767 client := exec.NewMockClient(ctrl)
768 return client
769 },
770 configAutomountClient: func(ctrl *gomock.Controller) configAutomount.Client {
771 return nil
772 },
773 imageBackend: func(ctrl *gomock.Controller) image.Backend {
774 client := image.NewMockBackend(ctrl)
775 client.EXPECT().Build(gomock.Any(), gomock.Any(), gomock.Any())
776 client.EXPECT().Push("golang")
777 return client
778
779 },
780 },
781 {
782 name: "Devfile with Apply Image command on podman",
783 devfileObjDeploy: func() parser.DevfileObj {
784 devfileData, err := data.NewDevfileData("2.1.0")
785 if err != nil {
786 t.Error(err)
787 }
788 devfileData.SetSchemaVersion("2.1.0")
789 _ = devfileData.AddComponents([]v1alpha2.Component{
790 imageComponent,
791 })
792 _ = devfileData.AddCommands([]v1alpha2.Command{
793 CommandWithKind(applyImage, v1alpha2.DeployCommandGroupKind, pointer.Bool(true)),
794 })
795
796 devfileObj := parser.DevfileObj{
797 Data: devfileData,
798 }
799 return devfileObj
800 },
801 devfileObjBuild: func() parser.DevfileObj {
802 devfileData, err := data.NewDevfileData("2.1.0")
803 if err != nil {
804 t.Error(err)
805 }
806 devfileData.SetSchemaVersion("2.1.0")
807 _ = devfileData.AddComponents([]v1alpha2.Component{
808 imageComponent,
809 })
810 _ = devfileData.AddCommands([]v1alpha2.Command{
811 CommandWithKind(applyImage, v1alpha2.BuildCommandGroupKind, pointer.Bool(true)),
812 })
813
814 devfileObj := parser.DevfileObj{
815 Data: devfileData,
816 }
817 return devfileObj
818 },
819 devfileObjRun: func() parser.DevfileObj {
820 devfileData, err := data.NewDevfileData("2.1.0")
821 if err != nil {
822 t.Error(err)
823 }
824 devfileData.SetSchemaVersion("2.1.0")
825 _ = devfileData.AddComponents([]v1alpha2.Component{
826 imageComponent,
827 })
828 _ = devfileData.AddCommands([]v1alpha2.Command{
829 CommandWithKind(applyImage, v1alpha2.RunCommandGroupKind, pointer.Bool(true)),
830 })
831
832 devfileObj := parser.DevfileObj{
833 Data: devfileData,
834 }
835 return devfileObj
836 },
837 DevfileObjPostStart: func() parser.DevfileObj {
838 devfileData, err := data.NewDevfileData("2.1.0")
839 if err != nil {
840 t.Error(err)
841 }
842 devfileData.SetSchemaVersion("2.1.0")
843 _ = devfileData.AddComponents([]v1alpha2.Component{
844 imageComponent,
845 })
846 _ = devfileData.AddCommands([]v1alpha2.Command{
847 applyImage,
848 })
849 _ = devfileData.AddEvents(v1alpha2.Events{
850 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
851 PostStart: []string{applyImage.Id},
852 },
853 })
854
855 devfileObj := parser.DevfileObj{
856 Data: devfileData,
857 }
858 return devfileObj
859 },
860 DevfileObjPreStop: func() parser.DevfileObj {
861 devfileData, err := data.NewDevfileData("2.1.0")
862 if err != nil {
863 t.Error(err)
864 }
865 devfileData.SetSchemaVersion("2.1.0")
866 _ = devfileData.AddComponents([]v1alpha2.Component{
867 imageComponent,
868 })
869 _ = devfileData.AddCommands([]v1alpha2.Command{
870 applyImage,
871 })
872 _ = devfileData.AddEvents(v1alpha2.Events{
873 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
874 PreStop: []string{applyImage.Id},
875 },
876 })
877
878 devfileObj := parser.DevfileObj{
879 Data: devfileData,
880 }
881 return devfileObj
882 },
883 platformClient: func(ctrl *gomock.Controller) platform.Client {
884 client := podman.NewMockClient(ctrl)
885 return client
886 },
887 execClient: func(ctrl *gomock.Controller) exec.Client {
888 client := exec.NewMockClient(ctrl)
889 return client
890 },
891 configAutomountClient: func(ctrl *gomock.Controller) configAutomount.Client {
892 return nil
893 },
894 imageBackend: func(ctrl *gomock.Controller) image.Backend {
895 client := image.NewMockBackend(ctrl)
896 client.EXPECT().Build(gomock.Any(), gomock.Any(), gomock.Any())
897 client.EXPECT().Push("golang")
898 return client
899
900 },
901 wantErr: false,
902 },
903
904 {
905 name: "Devfile with Apply Image command on cluster and push disabled",
906 devfileObjDeploy: func() parser.DevfileObj {
907 devfileData, err := data.NewDevfileData("2.1.0")
908 if err != nil {
909 t.Error(err)
910 }
911 devfileData.SetSchemaVersion("2.1.0")
912 _ = devfileData.AddComponents([]v1alpha2.Component{
913 imageComponent,
914 })
915 _ = devfileData.AddCommands([]v1alpha2.Command{
916 CommandWithKind(applyImage, v1alpha2.DeployCommandGroupKind, pointer.Bool(true)),
917 })
918
919 devfileObj := parser.DevfileObj{
920 Data: devfileData,
921 }
922 return devfileObj
923 },
924 devfileObjBuild: func() parser.DevfileObj {
925 devfileData, err := data.NewDevfileData("2.1.0")
926 if err != nil {
927 t.Error(err)
928 }
929 devfileData.SetSchemaVersion("2.1.0")
930 _ = devfileData.AddComponents([]v1alpha2.Component{
931 imageComponent,
932 })
933 _ = devfileData.AddCommands([]v1alpha2.Command{
934 CommandWithKind(applyImage, v1alpha2.BuildCommandGroupKind, pointer.Bool(true)),
935 })
936
937 devfileObj := parser.DevfileObj{
938 Data: devfileData,
939 }
940 return devfileObj
941 },
942 devfileObjRun: func() parser.DevfileObj {
943 devfileData, err := data.NewDevfileData("2.1.0")
944 if err != nil {
945 t.Error(err)
946 }
947 devfileData.SetSchemaVersion("2.1.0")
948 _ = devfileData.AddComponents([]v1alpha2.Component{
949 imageComponent,
950 })
951 _ = devfileData.AddCommands([]v1alpha2.Command{
952 CommandWithKind(applyImage, v1alpha2.RunCommandGroupKind, pointer.Bool(true)),
953 })
954
955 devfileObj := parser.DevfileObj{
956 Data: devfileData,
957 }
958 return devfileObj
959 },
960 DevfileObjPostStart: func() parser.DevfileObj {
961 devfileData, err := data.NewDevfileData("2.1.0")
962 if err != nil {
963 t.Error(err)
964 }
965 devfileData.SetSchemaVersion("2.1.0")
966 _ = devfileData.AddComponents([]v1alpha2.Component{
967 imageComponent,
968 })
969 _ = devfileData.AddCommands([]v1alpha2.Command{
970 applyImage,
971 })
972 _ = devfileData.AddEvents(v1alpha2.Events{
973 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
974 PostStart: []string{applyImage.Id},
975 },
976 })
977
978 devfileObj := parser.DevfileObj{
979 Data: devfileData,
980 }
981 return devfileObj
982 },
983 DevfileObjPreStop: func() parser.DevfileObj {
984 devfileData, err := data.NewDevfileData("2.1.0")
985 if err != nil {
986 t.Error(err)
987 }
988 devfileData.SetSchemaVersion("2.1.0")
989 _ = devfileData.AddComponents([]v1alpha2.Component{
990 imageComponent,
991 })
992 _ = devfileData.AddCommands([]v1alpha2.Command{
993 applyImage,
994 })
995 _ = devfileData.AddEvents(v1alpha2.Events{
996 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
997 PreStop: []string{applyImage.Id},
998 },
999 })
1000
1001 devfileObj := parser.DevfileObj{
1002 Data: devfileData,
1003 }
1004 return devfileObj
1005 },
1006 platformClient: func(ctrl *gomock.Controller) platform.Client {
1007 client := kclient.NewMockClientInterface(ctrl)
1008 return client
1009 },
1010 execClient: func(ctrl *gomock.Controller) exec.Client {
1011 client := exec.NewMockClient(ctrl)
1012 return client
1013 },
1014 configAutomountClient: func(ctrl *gomock.Controller) configAutomount.Client {
1015 return nil
1016 },
1017 imageBackend: func(ctrl *gomock.Controller) image.Backend {
1018 client := image.NewMockBackend(ctrl)
1019 client.EXPECT().Build(gomock.Any(), gomock.Any(), gomock.Any())
1020 return client
1021
1022 },
1023 env: map[string]string{
1024 "ODO_PUSH_IMAGES": "false",
1025 },
1026 },
1027 {
1028 name: "Devfile with Apply Image command on podman and push disabled",
1029 devfileObjDeploy: func() parser.DevfileObj {
1030 devfileData, err := data.NewDevfileData("2.1.0")
1031 if err != nil {
1032 t.Error(err)
1033 }
1034 devfileData.SetSchemaVersion("2.1.0")
1035 _ = devfileData.AddComponents([]v1alpha2.Component{
1036 imageComponent,
1037 })
1038 _ = devfileData.AddCommands([]v1alpha2.Command{
1039 CommandWithKind(applyImage, v1alpha2.DeployCommandGroupKind, pointer.Bool(true)),
1040 })
1041
1042 devfileObj := parser.DevfileObj{
1043 Data: devfileData,
1044 }
1045 return devfileObj
1046 },
1047 devfileObjBuild: func() parser.DevfileObj {
1048 devfileData, err := data.NewDevfileData("2.1.0")
1049 if err != nil {
1050 t.Error(err)
1051 }
1052 devfileData.SetSchemaVersion("2.1.0")
1053 _ = devfileData.AddComponents([]v1alpha2.Component{
1054 imageComponent,
1055 })
1056 _ = devfileData.AddCommands([]v1alpha2.Command{
1057 CommandWithKind(applyImage, v1alpha2.BuildCommandGroupKind, pointer.Bool(true)),
1058 })
1059
1060 devfileObj := parser.DevfileObj{
1061 Data: devfileData,
1062 }
1063 return devfileObj
1064 },
1065 devfileObjRun: func() parser.DevfileObj {
1066 devfileData, err := data.NewDevfileData("2.1.0")
1067 if err != nil {
1068 t.Error(err)
1069 }
1070 devfileData.SetSchemaVersion("2.1.0")
1071 _ = devfileData.AddComponents([]v1alpha2.Component{
1072 imageComponent,
1073 })
1074 _ = devfileData.AddCommands([]v1alpha2.Command{
1075 CommandWithKind(applyImage, v1alpha2.RunCommandGroupKind, pointer.Bool(true)),
1076 })
1077
1078 devfileObj := parser.DevfileObj{
1079 Data: devfileData,
1080 }
1081 return devfileObj
1082 },
1083 DevfileObjPostStart: func() parser.DevfileObj {
1084 devfileData, err := data.NewDevfileData("2.1.0")
1085 if err != nil {
1086 t.Error(err)
1087 }
1088 devfileData.SetSchemaVersion("2.1.0")
1089 _ = devfileData.AddComponents([]v1alpha2.Component{
1090 imageComponent,
1091 })
1092 _ = devfileData.AddCommands([]v1alpha2.Command{
1093 applyImage,
1094 })
1095 _ = devfileData.AddEvents(v1alpha2.Events{
1096 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
1097 PostStart: []string{applyImage.Id},
1098 },
1099 })
1100
1101 devfileObj := parser.DevfileObj{
1102 Data: devfileData,
1103 }
1104 return devfileObj
1105 },
1106 DevfileObjPreStop: func() parser.DevfileObj {
1107 devfileData, err := data.NewDevfileData("2.1.0")
1108 if err != nil {
1109 t.Error(err)
1110 }
1111 devfileData.SetSchemaVersion("2.1.0")
1112 _ = devfileData.AddComponents([]v1alpha2.Component{
1113 imageComponent,
1114 })
1115 _ = devfileData.AddCommands([]v1alpha2.Command{
1116 applyImage,
1117 })
1118 _ = devfileData.AddEvents(v1alpha2.Events{
1119 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
1120 PreStop: []string{applyImage.Id},
1121 },
1122 })
1123
1124 devfileObj := parser.DevfileObj{
1125 Data: devfileData,
1126 }
1127 return devfileObj
1128 },
1129 platformClient: func(ctrl *gomock.Controller) platform.Client {
1130 client := podman.NewMockClient(ctrl)
1131 return client
1132 },
1133 execClient: func(ctrl *gomock.Controller) exec.Client {
1134 client := exec.NewMockClient(ctrl)
1135 return client
1136 },
1137 configAutomountClient: func(ctrl *gomock.Controller) configAutomount.Client {
1138 return nil
1139 },
1140 imageBackend: func(ctrl *gomock.Controller) image.Backend {
1141 client := image.NewMockBackend(ctrl)
1142 client.EXPECT().Build(gomock.Any(), gomock.Any(), gomock.Any())
1143 return client
1144
1145 },
1146 env: map[string]string{
1147 "ODO_PUSH_IMAGES": "false",
1148 },
1149 },
1150
1151 {
1152 name: "Devfile with Exec on Container command on cluster",
1153 devfileObjDeploy: func() parser.DevfileObj {
1154 devfileData, err := data.NewDevfileData("2.1.0")
1155 if err != nil {
1156 t.Error(err)
1157 }
1158 devfileData.SetSchemaVersion("2.1.0")
1159 _ = devfileData.AddComponents([]v1alpha2.Component{
1160 containerComponent,
1161 })
1162 _ = devfileData.AddCommands([]v1alpha2.Command{
1163 CommandWithKind(execOnContainer, v1alpha2.DeployCommandGroupKind, pointer.Bool(true)),
1164 })
1165
1166 devfileObj := parser.DevfileObj{
1167 Data: devfileData,
1168 }
1169 return devfileObj
1170 },
1171 devfileObjBuild: func() parser.DevfileObj {
1172 devfileData, err := data.NewDevfileData("2.1.0")
1173 if err != nil {
1174 t.Error(err)
1175 }
1176 devfileData.SetSchemaVersion("2.1.0")
1177 _ = devfileData.AddComponents([]v1alpha2.Component{
1178 containerComponent,
1179 })
1180 _ = devfileData.AddCommands([]v1alpha2.Command{
1181 CommandWithKind(execOnContainer, v1alpha2.BuildCommandGroupKind, pointer.Bool(true)),
1182 })
1183
1184 devfileObj := parser.DevfileObj{
1185 Data: devfileData,
1186 }
1187 return devfileObj
1188 },
1189 devfileObjRun: func() parser.DevfileObj {
1190 devfileData, err := data.NewDevfileData("2.1.0")
1191 if err != nil {
1192 t.Error(err)
1193 }
1194 devfileData.SetSchemaVersion("2.1.0")
1195 _ = devfileData.AddComponents([]v1alpha2.Component{
1196 containerComponent,
1197 })
1198 _ = devfileData.AddCommands([]v1alpha2.Command{
1199 CommandWithKind(execOnContainer, v1alpha2.RunCommandGroupKind, pointer.Bool(true)),
1200 })
1201
1202 devfileObj := parser.DevfileObj{
1203 Data: devfileData,
1204 }
1205 return devfileObj
1206 },
1207 DevfileObjPostStart: func() parser.DevfileObj {
1208 devfileData, err := data.NewDevfileData("2.1.0")
1209 if err != nil {
1210 t.Error(err)
1211 }
1212 devfileData.SetSchemaVersion("2.1.0")
1213 _ = devfileData.AddComponents([]v1alpha2.Component{
1214 containerComponent,
1215 })
1216 _ = devfileData.AddCommands([]v1alpha2.Command{
1217 execOnContainer,
1218 })
1219 _ = devfileData.AddEvents(v1alpha2.Events{
1220 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
1221 PostStart: []string{execOnContainer.Id},
1222 },
1223 })
1224
1225 devfileObj := parser.DevfileObj{
1226 Data: devfileData,
1227 }
1228 return devfileObj
1229 },
1230 DevfileObjPreStop: func() parser.DevfileObj {
1231 devfileData, err := data.NewDevfileData("2.1.0")
1232 if err != nil {
1233 t.Error(err)
1234 }
1235 devfileData.SetSchemaVersion("2.1.0")
1236 _ = devfileData.AddComponents([]v1alpha2.Component{
1237 containerComponent,
1238 })
1239 _ = devfileData.AddCommands([]v1alpha2.Command{
1240 execOnContainer,
1241 })
1242 _ = devfileData.AddEvents(v1alpha2.Events{
1243 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
1244 PreStop: []string{execOnContainer.Id},
1245 },
1246 })
1247
1248 devfileObj := parser.DevfileObj{
1249 Data: devfileData,
1250 }
1251 return devfileObj
1252 },
1253 platformClient: func(ctrl *gomock.Controller) platform.Client {
1254 client := kclient.NewMockClientInterface(ctrl)
1255 client.EXPECT().GetCurrentNamespacePolicy()
1256 client.EXPECT().ListJobs(gomock.Any()).Return(&batchv1.JobList{}, nil)
1257 createdJob := batchv1.Job{}
1258 createdJob.SetName("job")
1259 client.EXPECT().CreateJob(gomock.Any(), gomock.Any()).Return(&createdJob, nil)
1260 client.EXPECT().WaitForJobToComplete(gomock.Any())
1261 client.EXPECT().DeleteJob("job")
1262 return client
1263 },
1264 execClient: func(ctrl *gomock.Controller) exec.Client {
1265 client := exec.NewMockClient(ctrl)
1266 return client
1267 },
1268 configAutomountClient: func(ctrl *gomock.Controller) configAutomount.Client {
1269 client := configAutomount.NewMockClient(ctrl)
1270 client.EXPECT().GetAutomountingVolumes()
1271 return client
1272 },
1273 imageBackend: func(ctrl *gomock.Controller) image.Backend {
1274 return nil
1275
1276 },
1277 },
1278 {
1279 name: "Devfile with Exec on Container command on podman",
1280 devfileObjDeploy: func() parser.DevfileObj {
1281 devfileData, err := data.NewDevfileData("2.1.0")
1282 if err != nil {
1283 t.Error(err)
1284 }
1285 devfileData.SetSchemaVersion("2.1.0")
1286 _ = devfileData.AddComponents([]v1alpha2.Component{
1287 containerComponent,
1288 })
1289 _ = devfileData.AddCommands([]v1alpha2.Command{
1290 CommandWithKind(execOnContainer, v1alpha2.DeployCommandGroupKind, pointer.Bool(true)),
1291 })
1292
1293 devfileObj := parser.DevfileObj{
1294 Data: devfileData,
1295 }
1296 return devfileObj
1297 },
1298 devfileObjBuild: func() parser.DevfileObj {
1299 devfileData, err := data.NewDevfileData("2.1.0")
1300 if err != nil {
1301 t.Error(err)
1302 }
1303 devfileData.SetSchemaVersion("2.1.0")
1304 _ = devfileData.AddComponents([]v1alpha2.Component{
1305 containerComponent,
1306 })
1307 _ = devfileData.AddCommands([]v1alpha2.Command{
1308 CommandWithKind(execOnContainer, v1alpha2.BuildCommandGroupKind, pointer.Bool(true)),
1309 })
1310
1311 devfileObj := parser.DevfileObj{
1312 Data: devfileData,
1313 }
1314 return devfileObj
1315 },
1316 devfileObjRun: func() parser.DevfileObj {
1317 devfileData, err := data.NewDevfileData("2.1.0")
1318 if err != nil {
1319 t.Error(err)
1320 }
1321 devfileData.SetSchemaVersion("2.1.0")
1322 _ = devfileData.AddComponents([]v1alpha2.Component{
1323 containerComponent,
1324 })
1325 _ = devfileData.AddCommands([]v1alpha2.Command{
1326 CommandWithKind(execOnContainer, v1alpha2.RunCommandGroupKind, pointer.Bool(true)),
1327 })
1328
1329 devfileObj := parser.DevfileObj{
1330 Data: devfileData,
1331 }
1332 return devfileObj
1333 },
1334 DevfileObjPostStart: func() parser.DevfileObj {
1335 devfileData, err := data.NewDevfileData("2.1.0")
1336 if err != nil {
1337 t.Error(err)
1338 }
1339 devfileData.SetSchemaVersion("2.1.0")
1340 _ = devfileData.AddComponents([]v1alpha2.Component{
1341 containerComponent,
1342 })
1343 _ = devfileData.AddCommands([]v1alpha2.Command{
1344 execOnContainer,
1345 })
1346 _ = devfileData.AddEvents(v1alpha2.Events{
1347 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
1348 PostStart: []string{execOnContainer.Id},
1349 },
1350 })
1351
1352 devfileObj := parser.DevfileObj{
1353 Data: devfileData,
1354 }
1355 return devfileObj
1356 },
1357 DevfileObjPreStop: func() parser.DevfileObj {
1358 devfileData, err := data.NewDevfileData("2.1.0")
1359 if err != nil {
1360 t.Error(err)
1361 }
1362 devfileData.SetSchemaVersion("2.1.0")
1363 _ = devfileData.AddComponents([]v1alpha2.Component{
1364 containerComponent,
1365 })
1366 _ = devfileData.AddCommands([]v1alpha2.Command{
1367 execOnContainer,
1368 })
1369 _ = devfileData.AddEvents(v1alpha2.Events{
1370 DevWorkspaceEvents: v1alpha2.DevWorkspaceEvents{
1371 PreStop: []string{execOnContainer.Id},
1372 },
1373 })
1374
1375 devfileObj := parser.DevfileObj{
1376 Data: devfileData,
1377 }
1378 return devfileObj
1379 },
1380 platformClient: func(ctrl *gomock.Controller) platform.Client {
1381 client := podman.NewMockClient(ctrl)
1382
1383 return client
1384 },
1385 execClient: func(ctrl *gomock.Controller) exec.Client {
1386 client := exec.NewMockClient(ctrl)
1387 return client
1388 },
1389 configAutomountClient: func(ctrl *gomock.Controller) configAutomount.Client {
1390 client := configAutomount.NewMockClient(ctrl)
1391 return client
1392 },
1393 imageBackend: func(ctrl *gomock.Controller) image.Backend {
1394 return nil
1395 },
1396 },
1397 }
1398 for _, tt := range tests {
1399 t.Run(tt.name, func(t *testing.T) {
1400 {
1401 ctrl := gomock.NewController(t)
1402 ctx := context.Background()
1403 ctx = odocontext.WithDevfilePath(ctx, "/devfile.yaml")
1404 ctx = odocontext.WithApplication(ctx, appName)
1405 ctx = odocontext.WithComponentName(ctx, componentName)
1406 envConfig, err := config.GetConfigurationWith(envconfig.MapLookuper(tt.env))
1407 if err != nil {
1408 t.Error("error reading config")
1409 }
1410 ctx = envcontext.WithEnvConfig(ctx, *envConfig)
1411 devfileObj := tt.devfileObjDeploy()
1412 cmdHandler := &runHandler{
1413 ctx: ctx,
1414 fs: filesystem.NewFakeFs(),
1415 execClient: tt.execClient(ctrl),
1416 platformClient: tt.platformClient(ctrl),
1417 configAutomountClient: tt.configAutomountClient(ctrl),
1418 imageBackend: tt.imageBackend(ctrl),
1419 devfile: devfileObj,
1420 }
1421 err = libdevfile.Deploy(ctx, devfileObj, cmdHandler)
1422 if (err != nil) != tt.wantErr {
1423 t.Errorf("Err expected %v, got %v", tt.wantErr, err)
1424 }
1425 }
1426 {
1427 ctrl := gomock.NewController(t)
1428 ctx := context.Background()
1429 ctx = odocontext.WithDevfilePath(ctx, "/devfile.yaml")
1430 ctx = odocontext.WithApplication(ctx, appName)
1431 ctx = odocontext.WithComponentName(ctx, componentName)
1432 envConfig, err := config.GetConfigurationWith(envconfig.MapLookuper(tt.env))
1433 if err != nil {
1434 t.Error("error reading config")
1435 }
1436 ctx = envcontext.WithEnvConfig(ctx, *envConfig)
1437 devfileObj := tt.devfileObjBuild()
1438 cmdHandler := &runHandler{
1439 ctx: ctx,
1440 fs: filesystem.NewFakeFs(),
1441 execClient: tt.execClient(ctrl),
1442 platformClient: tt.platformClient(ctrl),
1443 configAutomountClient: tt.configAutomountClient(ctrl),
1444 imageBackend: tt.imageBackend(ctrl),
1445 devfile: devfileObj,
1446 }
1447 err = libdevfile.Build(ctx, devfileObj, "", cmdHandler)
1448 if (err != nil) != tt.wantErr {
1449 t.Errorf("Err expected %v, got %v", tt.wantErr, err)
1450 }
1451 }
1452 {
1453 ctrl := gomock.NewController(t)
1454 ctx := context.Background()
1455 ctx = odocontext.WithDevfilePath(ctx, "/devfile.yaml")
1456 ctx = odocontext.WithApplication(ctx, appName)
1457 ctx = odocontext.WithComponentName(ctx, componentName)
1458 envConfig, err := config.GetConfigurationWith(envconfig.MapLookuper(tt.env))
1459 if err != nil {
1460 t.Error("error reading config")
1461 }
1462 ctx = envcontext.WithEnvConfig(ctx, *envConfig)
1463 devfileObj := tt.devfileObjRun()
1464 cmdHandler := &runHandler{
1465 ctx: ctx,
1466 fs: filesystem.NewFakeFs(),
1467 execClient: tt.execClient(ctrl),
1468 platformClient: tt.platformClient(ctrl),
1469 configAutomountClient: tt.configAutomountClient(ctrl),
1470 imageBackend: tt.imageBackend(ctrl),
1471 devfile: devfileObj,
1472 }
1473 err = libdevfile.ExecuteCommandByNameAndKind(ctx, devfileObj, "", v1alpha2.RunCommandGroupKind, cmdHandler, false)
1474 if (err != nil) != tt.wantErr {
1475 t.Errorf("Err expected %v, got %v", tt.wantErr, err)
1476 }
1477 }
1478 {
1479 ctrl := gomock.NewController(t)
1480 ctx := context.Background()
1481 ctx = odocontext.WithDevfilePath(ctx, "/devfile.yaml")
1482 ctx = odocontext.WithApplication(ctx, appName)
1483 ctx = odocontext.WithComponentName(ctx, componentName)
1484 envConfig, err := config.GetConfigurationWith(envconfig.MapLookuper(tt.env))
1485 if err != nil {
1486 t.Error("error reading config")
1487 }
1488 ctx = envcontext.WithEnvConfig(ctx, *envConfig)
1489 devfileObj := tt.DevfileObjPostStart()
1490 cmdHandler := &runHandler{
1491 ctx: ctx,
1492 fs: filesystem.NewFakeFs(),
1493 execClient: tt.execClient(ctrl),
1494 platformClient: tt.platformClient(ctrl),
1495 configAutomountClient: tt.configAutomountClient(ctrl),
1496 imageBackend: tt.imageBackend(ctrl),
1497 devfile: devfileObj,
1498 }
1499 err = libdevfile.ExecPostStartEvents(ctx, devfileObj, cmdHandler)
1500 if (err != nil) != tt.wantErr {
1501 t.Errorf("Err expected %v, got %v", tt.wantErr, err)
1502 }
1503 }
1504 {
1505 ctrl := gomock.NewController(t)
1506 ctx := context.Background()
1507 ctx = odocontext.WithDevfilePath(ctx, "/devfile.yaml")
1508 ctx = odocontext.WithApplication(ctx, appName)
1509 ctx = odocontext.WithComponentName(ctx, componentName)
1510 envConfig, err := config.GetConfigurationWith(envconfig.MapLookuper(tt.env))
1511 if err != nil {
1512 t.Error("error reading config")
1513 }
1514 ctx = envcontext.WithEnvConfig(ctx, *envConfig)
1515 devfileObj := tt.DevfileObjPreStop()
1516 cmdHandler := &runHandler{
1517 ctx: ctx,
1518 fs: filesystem.NewFakeFs(),
1519 execClient: tt.execClient(ctrl),
1520 platformClient: tt.platformClient(ctrl),
1521 configAutomountClient: tt.configAutomountClient(ctrl),
1522 imageBackend: tt.imageBackend(ctrl),
1523 devfile: devfileObj,
1524 }
1525 err = libdevfile.ExecPreStopEvents(ctx, devfileObj, cmdHandler)
1526 if (err != nil) != tt.wantErr {
1527 t.Errorf("Err expected %v, got %v", tt.wantErr, err)
1528 }
1529 }
1530 })
1531 }
1532 }
1533
View as plain text