...
1 package libdevfile
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
11 "github.com/redhat-developer/odo/pkg/libdevfile/generator"
12 )
13
14 func Test_applyCommand_Execute(t *testing.T) {
15
16 command1 := generator.GetApplyCommand(generator.ApplyCommandParams{
17 Id: "command1",
18 Component: "component",
19 })
20 component := generator.GetContainerComponent(generator.ContainerComponentParams{
21 Name: "component",
22 })
23 component1 := generator.GetContainerComponent(generator.ContainerComponentParams{
24 Name: "component1",
25 })
26 component2 := generator.GetContainerComponent(generator.ContainerComponentParams{
27 Name: "component2",
28 })
29
30 type fields struct {
31 command v1alpha2.Command
32 devfileObj func() parser.DevfileObj
33 }
34 tests := []struct {
35 name string
36 fields fields
37 wantErr bool
38 }{
39 {
40 name: "execute an apply command",
41 fields: fields{
42 command: command1,
43 devfileObj: func() parser.DevfileObj {
44 data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
45 _ = data.AddCommands([]v1alpha2.Command{command1})
46 _ = data.AddComponents([]v1alpha2.Component{component, component1, component2})
47 return parser.DevfileObj{
48 Data: data,
49 }
50 },
51 },
52 },
53
54 }
55 for _, tt := range tests {
56 t.Run(tt.name, func(t *testing.T) {
57 o := &applyCommand{
58 command: tt.fields.command,
59 devfileObj: tt.fields.devfileObj(),
60 }
61
62 if err := o.Execute(context.Background(), nil, nil); (err != nil) != tt.wantErr {
63 t.Errorf("applyCommand.Execute() error = %v, wantErr %v", err, tt.wantErr)
64 }
65 })
66 }
67 }
68
View as plain text