...
1 package validate
2
3 import (
4 "testing"
5
6 devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
7
8 "github.com/redhat-developer/odo/pkg/util"
9 )
10
11 var buildGroup = devfilev1.BuildCommandGroupKind
12
13 func TestValidateCommand(t *testing.T) {
14
15 tests := []struct {
16 name string
17 command devfilev1.Command
18 wantErr bool
19 }{
20 {
21 name: "valid Exec Command",
22 command: devfilev1.Command{
23 Id: "somecommand",
24 CommandUnion: devfilev1.CommandUnion{
25 Exec: &devfilev1.ExecCommand{},
26 },
27 },
28 wantErr: false,
29 },
30 {
31 name: "invalid odo Command",
32 command: devfilev1.Command{
33 Id: "invalid-odo-command",
34 CommandUnion: devfilev1.CommandUnion{
35 Custom: &devfilev1.CustomCommand{
36 CommandClass: "cmd-class",
37 },
38 },
39 },
40 wantErr: true,
41 },
42 {
43 name: "valid Apply Command",
44 command: devfilev1.Command{
45 Id: "my-apply-command",
46 CommandUnion: devfilev1.CommandUnion{
47 Apply: &devfilev1.ApplyCommand{},
48 },
49 },
50 wantErr: false,
51 },
52 {
53 name: "valid Composite Command",
54 command: devfilev1.Command{
55 Id: "composite1",
56 CommandUnion: devfilev1.CommandUnion{
57 Composite: &devfilev1.CompositeCommand{
58 LabeledCommand: devfilev1.LabeledCommand{
59 BaseCommand: devfilev1.BaseCommand{
60 Group: &devfilev1.CommandGroup{Kind: buildGroup, IsDefault: util.GetBool(true)},
61 },
62 },
63 },
64 },
65 },
66 wantErr: false,
67 },
68 }
69 for _, tt := range tests {
70 t.Run(tt.name, func(t *testing.T) {
71 err := validateCommand(tt.command)
72 if !tt.wantErr == (err != nil) {
73 t.Errorf("TestValidateCommand unexpected error: %v", err)
74 return
75 }
76 })
77 }
78
79 }
80
View as plain text