@@ -15,10 +15,13 @@ package component
15
15
16
16
import (
17
17
"context"
18
+ "encoding/json"
18
19
"io"
19
20
"os"
20
21
"testing"
21
22
23
+ "google.golang.org/protobuf/encoding/protojson"
24
+
22
25
"github.com/kubeflow/pipelines/api/v2alpha1/go/pipelinespec"
23
26
"github.com/kubeflow/pipelines/backend/src/v2/metadata"
24
27
"github.com/kubeflow/pipelines/backend/src/v2/objectstore"
@@ -106,7 +109,7 @@ func Test_executeV2_Parameters(t *testing.T) {
106
109
}
107
110
}
108
111
109
- func Test_executeV2_publishLogss (t * testing.T ) {
112
+ func Test_executeV2_publishLogs (t * testing.T ) {
110
113
tests := []struct {
111
114
name string
112
115
executorInput * pipelinespec.ExecutorInput
@@ -167,6 +170,75 @@ func Test_executeV2_publishLogss(t *testing.T) {
167
170
}
168
171
}
169
172
173
+ func Test_executorInput_compileCmdAndArgs (t * testing.T ) {
174
+ executorInputJSON := `{
175
+ "inputs": {
176
+ "parameterValues": {
177
+ "config": {
178
+ "category_ids": "{{$.inputs.parameters['pipelinechannel--category_ids']}}",
179
+ "dump_filename": "{{$.inputs.parameters['pipelinechannel--dump_filename']}}",
180
+ "sphinx_host": "{{$.inputs.parameters['pipelinechannel--sphinx_host']}}",
181
+ "sphinx_port": "{{$.inputs.parameters['pipelinechannel--sphinx_port']}}"
182
+ },
183
+ "pipelinechannel--category_ids": "116",
184
+ "pipelinechannel--dump_filename": "dump_filename_test.txt",
185
+ "pipelinechannel--sphinx_host": "sphinx-default-host.ru",
186
+ "pipelinechannel--sphinx_port": 9312
187
+ }
188
+ },
189
+ "outputs": {
190
+ "artifacts": {
191
+ "dataset": {
192
+ "artifacts": [{
193
+ "type": {
194
+ "schemaTitle": "system.Dataset",
195
+ "schemaVersion": "0.0.1"
196
+ },
197
+ "uri": "s3://aviflow-stage-kfp-artifacts/debug-component-pipeline/ae02034e-bd96-4b8a-a06b-55c99fe9eccb/sayhello/c98ac032-2448-4637-bf37-3ad1e13a112c/dataset"
198
+ }]
199
+ }
200
+ },
201
+ "outputFile": "/tmp/kfp_outputs/output_metadata.json"
202
+ }
203
+ }`
204
+
205
+ executorInput := & pipelinespec.ExecutorInput {}
206
+ err := protojson .Unmarshal ([]byte (executorInputJSON ), executorInput )
207
+
208
+ assert .NoError (t , err )
209
+
210
+ cmd := "sh"
211
+ args := []string {
212
+ "--executor_input" , "{{$}}" ,
213
+ "--function_to_execute" , "sayHello" ,
214
+ }
215
+ cmd , args , err = compileCmdAndArgs (executorInput , cmd , args )
216
+
217
+ assert .NoError (t , err )
218
+
219
+ var actualExecutorInput string
220
+ for i := 0 ; i < len (args )- 1 ; i ++ {
221
+ if args [i ] == "--executor_input" {
222
+ actualExecutorInput = args [i + 1 ]
223
+ break
224
+ }
225
+ }
226
+ assert .NotEmpty (t , actualExecutorInput , "--executor_input not found" )
227
+
228
+ var parsed map [string ]any
229
+ err = json .Unmarshal ([]byte (actualExecutorInput ), & parsed )
230
+ assert .NoError (t , err )
231
+
232
+ inputs := parsed ["inputs" ].(map [string ]any )
233
+ paramValues := inputs ["parameterValues" ].(map [string ]any )
234
+ config := paramValues ["config" ].(map [string ]any )
235
+
236
+ assert .Equal (t , "116" , config ["category_ids" ])
237
+ assert .Equal (t , "dump_filename_test.txt" , config ["dump_filename" ])
238
+ assert .Equal (t , "sphinx-default-host.ru" , config ["sphinx_host" ])
239
+ assert .Equal (t , "9312" , config ["sphinx_port" ])
240
+ }
241
+
170
242
func Test_get_log_Writer (t * testing.T ) {
171
243
old := osCreateFunc
172
244
defer func () { osCreateFunc = old }()
0 commit comments