1
1
package variables
2
2
3
3
import (
4
+ "reflect"
4
5
"testing"
5
6
6
7
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
@@ -30,6 +31,13 @@ func TestValidateAndReplaceExecCommand(t *testing.T) {
30
31
variableFile : "test-fixtures/variables/variables-notreferenced.yaml" ,
31
32
wantErr : true ,
32
33
},
34
+ {
35
+ name : "Not an exec command" ,
36
+ testFile : "test-fixtures/components/volume.yaml" ,
37
+ outputFile : "test-fixtures/components/volume.yaml" ,
38
+ variableFile : "test-fixtures/variables/variables-notreferenced.yaml" ,
39
+ wantErr : false ,
40
+ },
33
41
}
34
42
for _ , tt := range tests {
35
43
t .Run (tt .name , func (t * testing.T ) {
@@ -39,7 +47,12 @@ func TestValidateAndReplaceExecCommand(t *testing.T) {
39
47
testVariable := make (map [string ]string )
40
48
readFileToStruct (t , tt .variableFile , & testVariable )
41
49
42
- err := validateAndReplaceForExecCommand (testVariable , & testExecCommand )
50
+ var err error
51
+ if reflect .DeepEqual (testExecCommand , v1alpha2.ExecCommand {}) {
52
+ err = validateAndReplaceForExecCommand (testVariable , nil )
53
+ } else {
54
+ err = validateAndReplaceForExecCommand (testVariable , & testExecCommand )
55
+ }
43
56
_ , ok := err .(* InvalidKeysError )
44
57
if tt .wantErr && ! ok {
45
58
t .Errorf ("Expected InvalidKeysError error from test but got %+v" , err )
@@ -77,6 +90,13 @@ func TestValidateAndReplaceCompositeCommand(t *testing.T) {
77
90
variableFile : "test-fixtures/variables/variables-notreferenced.yaml" ,
78
91
wantErr : true ,
79
92
},
93
+ {
94
+ name : "Not a composite command" ,
95
+ testFile : "test-fixtures/components/volume.yaml" ,
96
+ outputFile : "test-fixtures/components/volume.yaml" ,
97
+ variableFile : "test-fixtures/variables/variables-notreferenced.yaml" ,
98
+ wantErr : false ,
99
+ },
80
100
}
81
101
for _ , tt := range tests {
82
102
t .Run (tt .name , func (t * testing.T ) {
@@ -86,7 +106,12 @@ func TestValidateAndReplaceCompositeCommand(t *testing.T) {
86
106
testVariable := make (map [string ]string )
87
107
readFileToStruct (t , tt .variableFile , & testVariable )
88
108
89
- err := validateAndReplaceForCompositeCommand (testVariable , & testCompositeCommand )
109
+ var err error
110
+ if reflect .DeepEqual (testCompositeCommand , v1alpha2.CompositeCommand {}) {
111
+ err = validateAndReplaceForCompositeCommand (testVariable , nil )
112
+ } else {
113
+ err = validateAndReplaceForCompositeCommand (testVariable , & testCompositeCommand )
114
+ }
90
115
_ , ok := err .(* InvalidKeysError )
91
116
if tt .wantErr && ! ok {
92
117
t .Errorf ("Expected InvalidKeysError error from test but got %+v" , err )
@@ -124,6 +149,13 @@ func TestValidateAndReplaceApplyCommand(t *testing.T) {
124
149
variableFile : "test-fixtures/variables/variables-notreferenced.yaml" ,
125
150
wantErr : true ,
126
151
},
152
+ {
153
+ name : "Not an apply command" ,
154
+ testFile : "test-fixtures/components/volume.yaml" ,
155
+ outputFile : "test-fixtures/components/volume.yaml" ,
156
+ variableFile : "test-fixtures/variables/variables-notreferenced.yaml" ,
157
+ wantErr : false ,
158
+ },
127
159
}
128
160
for _ , tt := range tests {
129
161
t .Run (tt .name , func (t * testing.T ) {
@@ -133,7 +165,12 @@ func TestValidateAndReplaceApplyCommand(t *testing.T) {
133
165
testVariable := make (map [string ]string )
134
166
readFileToStruct (t , tt .variableFile , & testVariable )
135
167
136
- err := validateAndReplaceForApplyCommand (testVariable , & testApplyCommand )
168
+ var err error
169
+ if reflect .DeepEqual (testApplyCommand , v1alpha2.ApplyCommand {}) {
170
+ err = validateAndReplaceForApplyCommand (testVariable , nil )
171
+ } else {
172
+ err = validateAndReplaceForApplyCommand (testVariable , & testApplyCommand )
173
+ }
137
174
_ , ok := err .(* InvalidKeysError )
138
175
if tt .wantErr && ! ok {
139
176
t .Errorf ("Expected InvalidKeysError error from test but got %+v" , err )
0 commit comments