forked from cyverse-de/model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
step_test.go
559 lines (507 loc) · 15.8 KB
/
step_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
package model
import (
"reflect"
"testing"
)
func TestStepsCount(t *testing.T) {
s := inittests(t)
numSteps := len(s.Steps)
if numSteps != 1 {
t.Errorf("The number of steps was %d instead of 1", numSteps)
}
}
func TestStepType(t *testing.T) {
s := inittests(t)
step := s.Steps[0]
if step.Type != "condor" {
t.Errorf("The step type was '%s' instead of 'condor'", step.Type)
}
}
func TestStepStdinPath(t *testing.T) {
s := inittests(t)
step := s.Steps[0]
if step.StdinPath != "/path/to/stdin" {
t.Errorf("The step's path to stdin was '%s' instead of '/path/to/stdin'", step.StdinPath)
}
}
func TestStepStdoutPath(t *testing.T) {
s := inittests(t)
step := s.Steps[0]
if step.StdoutPath != "/path/to/stdout" {
t.Errorf("The step's path to stdout was '%s' instead of '/path/to/stdout'", step.StdoutPath)
}
}
func TestStepStderrPath(t *testing.T) {
s := inittests(t)
step := s.Steps[0]
if step.StderrPath != "/path/to/stderr" {
t.Errorf("The step's path to stderr was '%s' instead of '/path/to/stderr'", step.StderrPath)
}
}
func TestStepStdin(t *testing.T) {
s := inittests(t)
step := s.Steps[0]
actual := step.Stdin()
expected := "'/path/to/stdin'"
if actual != expected {
t.Errorf("Stdin() returned '%s' instead of '%s'", actual, expected)
}
step.StdinPath = ""
actual = step.Stdin()
expected = ""
if actual != expected {
t.Errorf("Stdin() returned '%s' instead of '%s'", actual, expected)
}
_inittests(t, false)
}
func TestStepStdout(t *testing.T) {
s := inittests(t)
step := s.Steps[0]
actual := step.Stdout("foo")
expected := "/path/to/stdout"
if actual != expected {
t.Errorf("Stdout() returned '%s' instead of '%s'", actual, expected)
}
step.StdoutPath = ""
actual = step.Stdout("foo")
expected = "logs/condor-stdout-foo"
if actual != expected {
t.Errorf("Stdout() returned '%s' instead of '%s'", actual, expected)
}
_inittests(t, false)
}
func TestStepStderr(t *testing.T) {
s := inittests(t)
step := s.Steps[0]
actual := step.Stderr("foo")
expected := "/path/to/stderr"
if actual != expected {
t.Errorf("Stderr() returned '%s' instead of '%s'", actual, expected)
}
step.StderrPath = ""
actual = step.Stderr("foo")
expected = "logs/condor-stderr-foo"
if actual != expected {
t.Errorf("Stderr() returned '%s' instead of '%s'", actual, expected)
}
_inittests(t, false)
}
func TestLogPath(t *testing.T) {
s := inittests(t)
step := s.Steps[0]
actual := step.LogPath("parent", "suffix")
expected := "parent/log-file-name"
if actual != expected {
t.Errorf("LogPath() returned '%s' instead of '%s'", actual, expected)
}
step.LogFile = ""
actual = step.LogPath("parent", "suffix")
expected = "parent/logs/condor-log-suffix"
if actual != expected {
t.Errorf("LogPath() returned '%s' instead of '%s'", actual, expected)
}
_inittests(t, false)
}
func TestStepEnvironmentLength(t *testing.T) {
s := inittests(t)
env := s.Steps[0].Environment
envlen := len(env)
if envlen != 2 {
t.Errorf("The number of env vars is '%d' when it should have been '2'", envlen)
}
}
func TestStepEnvironment(t *testing.T) {
s := inittests(t)
env := s.Steps[0].Environment
if env["food"] != "banana" {
t.Errorf("The env var 'food' was set to '%s' instead of 'banana'", env["food"])
}
}
func TestStepEnvironment2(t *testing.T) {
s := inittests(t)
env := s.Steps[0].Environment
if env["foo"] != "bar" {
t.Errorf("The env var 'foo' was set to '%s' instead of 'bar'", env["foo"])
}
}
func TestEnvOptions(t *testing.T) {
s := inittests(t)
actual := s.Steps[0].EnvOptions()
expected := []string{"--env=\"food=banana\"", "--env=\"foo=bar\""}
expected2 := []string{"--env=\"foo=bar\"", "--env=\"food=banana\""}
if !reflect.DeepEqual(actual, expected) && !reflect.DeepEqual(actual, expected2) {
if !reflect.DeepEqual(actual, expected) {
t.Errorf("EnvOptions() returned '%#v' instead of '%#v'", actual, expected)
}
if !reflect.DeepEqual(actual, expected2) {
t.Errorf("EnvOptions() returned '%#v' instead of '%#v'", actual, expected2)
}
}
s.Steps[0].Environment = make(StepEnvironment)
actual = s.Steps[0].EnvOptions()
expected = []string{}
if !reflect.DeepEqual(actual, expected) {
t.Errorf("EnvOptions() returned '%s' instead of '%s'", actual, expected)
}
_inittests(t, false)
}
func TestIsBackwardsCompatible(t *testing.T) {
s := inittests(t)
actual := s.Steps[0].IsBackwardsCompatible()
if !actual {
t.Errorf("IsBackwardsCompatible() returned false")
}
s.Steps[0].Component.Container.Image.Name = "discoenv/test"
actual = s.Steps[0].IsBackwardsCompatible()
if actual {
t.Errorf("IsBackwardsCompatible() returned true")
}
_inittests(t, false)
}
func TestExecutable(t *testing.T) {
s := inittests(t)
actual := s.Steps[0].Executable()
expected := "/usr/local2/bin/QATestTool.sh"
if actual != expected {
t.Errorf("Executable() returned '%s' instead of '%s'", actual, expected)
}
s.Steps[0].Component.Container.Image.Name = "discoenv/test"
actual = s.Steps[0].Executable()
expected = ""
if actual != expected {
t.Errorf("Executable() returned '%s' instead of '%s'", actual, expected)
}
_inittests(t, false)
}
func TestArguments(t *testing.T) {
s := inittests(t)
s.Steps[0].Environment = make(StepEnvironment) // Removed the environment to save my sanity. It's unordered.
actual := s.Steps[0].Arguments()
expected := []string{
"/usr/local2/bin/QATestTool.sh",
"param1", "Acer-tree.txt", "param3", "true",
"param0", "wc_out.txt", "param4", "four",
"--multi-param2", "input.1", "input.2", "input.3",
"input.4", "input.5", "input.6",
}
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Arguments() returned:\n\t%#v\ninstead of:\n\t%#v", actual, expected)
}
}
func TestStepConfig(t *testing.T) {
s := inittests(t)
config := s.Steps[0].Config
inputlen := len(config.Inputs)
outputlen := len(config.Outputs)
paramslen := len(config.Params)
if inputlen != 8 {
t.Errorf("The number of inputs was '%d' when it should have been '8'", inputlen)
}
if outputlen != 2 {
t.Errorf("The number of outputs was '%d' when it should have been '2'", outputlen)
}
if paramslen != 10 {
t.Errorf("The number of params was '%d' when it should have been '10'", paramslen)
}
}
func TestConfigInputID(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
if input.ID != "2f58fce9-8183-4ab5-97c4-970592d1c35a" {
t.Errorf("The input ID was '%s' when it should have been '2f58fce9-8183-4ab5-97c4-970592d1c35a'", input.ID)
}
}
func TestConfigInputMultiplicity(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
if input.Multiplicity != "single" {
t.Errorf("The input multiplicity was '%s' when it should have been 'single'", input.Multiplicity)
}
}
func TestConfigInputName(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
if input.Name != "Acer-tree.txt" {
t.Errorf("The input name was '%s' when it should have been 'Acer-tree.txt'", input.Name)
}
}
func TestConfigInputProperty(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
if input.Property != "Acer-tree.txt" {
t.Errorf("The input property was '%s' when it should have been 'Acer-tree.txt'", input.Name)
}
}
func TestConfigInputRetain(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
if !input.Retain {
t.Error("The input property was false when it should have been true")
}
}
func TestConfigInputType(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
if input.Type != "FileInput" {
t.Errorf("The input type was '%s' when it should have been 'FileInput'", input.Type)
}
}
func TestConfigInputValue(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
if input.Value != "/iplant/home/wregglej/Acer-tree.txt" {
t.Errorf("The input value was '%s' when it should have been '/iplant/home/wregglej/Acer-tree.txt'", input.Value)
}
}
func TestInputIRODSPath(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
actual := input.IRODSPath()
expected := "/iplant/home/wregglej/Acer-tree.txt"
if actual != expected {
t.Errorf("IRODSPath() returned '%s' instead of '%s'", actual, expected)
}
input.Value = "/iplant/home/wregglej/Acer-tree"
input.Multiplicity = "collection"
actual = input.IRODSPath()
expected = "/iplant/home/wregglej/Acer-tree/"
if actual != expected {
t.Errorf("IRODSPath() returned '%s' instead of '%s'", actual, expected)
}
_inittests(t, false)
}
func TestInputIdentifier(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
actual := input.Identifier("0-0")
expected := "input-0-0"
if actual != expected {
t.Errorf("Identifier() returned %s instead of %s", actual, expected)
}
}
func TestInputStdout(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
actual := input.Stdout("0-0")
expected := "logs/logs-stdout-input-0-0"
if actual != expected {
t.Errorf("StepInput.Stdout() returned %s instead of %s", actual, expected)
}
}
func TestInputStderr(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
actual := input.Stderr("0-0")
expected := "logs/logs-stderr-input-0-0"
if actual != expected {
t.Errorf("StepInput.Stderr() returned %s instead of %s", actual, expected)
}
}
func TestInputLogPath(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
actual := input.LogPath("parent", "0-0")
expected := "parent/logs/logs-condor-input-0-0"
if actual != expected {
t.Errorf("StepInput.LogPath() returned %s instead of %s", actual, expected)
}
}
func TestInputArguments(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
actual := input.Arguments("testuser", s.FileMetadata)
expected := []string{
"get",
"--user", "testuser",
"--source", "/iplant/home/wregglej/Acer-tree.txt",
"--config", "/configs/irods-config",
"-m", "attr1,value1,unit1",
"-m", "attr2,value2,unit2",
"-m", "ipc-analysis-id,c7f05682-23c8-4182-b9a2-e09650a5f49b,UUID",
"-m", "ipc-execution-id,07b04ce2-7757-4b21-9e15-0b4c2f44be26,UUID",
}
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Arguments() returned:\n\t%#v\ninstead of:\n\t%#v", actual, expected)
}
}
func TestInputSource(t *testing.T) {
s := inittests(t)
input := s.Steps[0].Config.Inputs[0]
actual := input.Source()
expected := "Acer-tree.txt"
if actual != expected {
t.Errorf("Source() returned %s instead of %s", actual, expected)
}
input.Value = "/foo"
input.Multiplicity = "collection"
actual = input.Source()
expected = "foo/"
if actual != expected {
t.Errorf("Source() returned %s instead of %s", actual, expected)
}
_inittests(t, false)
}
func TestConfigOutput0Multiplicity(t *testing.T) {
s := inittests(t)
output := s.Steps[0].Config.Outputs[0]
if output.Multiplicity != "single" {
t.Errorf("The output multiplicity was '%s' when it should have been 'single'", output.Multiplicity)
}
}
func TestConfigOutput0Name(t *testing.T) {
s := inittests(t)
output := s.Steps[0].Config.Outputs[0]
if output.Name != "wc_out.txt" {
t.Errorf("The output name was '%s' when it should have been 'wc_out.txt'", output.Name)
}
}
func TestConfigOutput0Property(t *testing.T) {
s := inittests(t)
output := s.Steps[0].Config.Outputs[0]
if output.Property != "wc_out.txt" {
t.Errorf("The output property was '%s' when it should have been 'wc_out.txt'", output.Property)
}
}
func TestConfigOutput0QualID(t *testing.T) {
s := inittests(t)
output := s.Steps[0].Config.Outputs[0]
if output.QualID != "67781636-854a-11e4-b715-e70c4f8db0dc_e7721c78-56c9-41ac-8ff5-8d46093f1fb1" {
t.Errorf("The output qual-id was '%s' when it should have been '67781636-854a-11e4-b715-e70c4f8db0dc_e7721c78-56c9-41ac-8ff5-8d46093f1fb1'", output.QualID)
}
}
func TestConfigOutput0Retain(t *testing.T) {
s := inittests(t)
output := s.Steps[0].Config.Outputs[0]
if !output.Retain {
t.Errorf("The output retain was false when it should have been true")
}
}
func TestConfigOutput0Type(t *testing.T) {
s := inittests(t)
output := s.Steps[0].Config.Outputs[0]
if output.Type != "File" {
t.Errorf("The output type was '%s' when it should have been 'File'", output.Type)
}
}
func TestConfigOutput1Multiplicity(t *testing.T) {
s := inittests(t)
output := s.Steps[0].Config.Outputs[1]
if output.Multiplicity != "collection" {
t.Errorf("The output multiplicity was '%s' when it should have been 'collection'", output.Multiplicity)
}
}
func TestConfigOutput1Name(t *testing.T) {
s := inittests(t)
output := s.Steps[0].Config.Outputs[1]
if output.Name != "logs" {
t.Errorf("The output name was '%s' when it should have been 'logs'", output.Name)
}
}
func TestConfigOutput1Property(t *testing.T) {
s := inittests(t)
output := s.Steps[0].Config.Outputs[1]
if output.Property != "logs" {
t.Errorf("The output property was '%s' when it should have been 'logs'", output.Property)
}
}
func TestConfigOutput1Retain(t *testing.T) {
s := inittests(t)
output := s.Steps[0].Config.Outputs[1]
if !output.Retain {
t.Errorf("The output retain was false when it should have been true")
}
}
func TestConfigOutput1Type(t *testing.T) {
s := inittests(t)
output := s.Steps[0].Config.Outputs[1]
if output.Type != "File" {
t.Errorf("The output type was '%s' when it should have been 'File'", output.Type)
}
}
func TestOutputSource(t *testing.T) {
s := inittests(t)
output := s.Steps[0].Config.Outputs[0]
actual := output.Source()
expected := "wc_out.txt"
if actual != expected {
t.Errorf("Source() returned %s instead of %s", actual, expected)
}
output.Name = "not-abs"
output.Multiplicity = "collection"
actual = output.Source()
expected = "/de-app-work/not-abs/"
if actual != expected {
t.Errorf("Source() returned %s instead of %s", actual, expected)
}
output.Name = "/abs/path"
output.Multiplicity = "collection"
actual = output.Source()
expected = "/abs/path/"
if actual != expected {
t.Errorf("Source() returned %s instead of %s", actual, expected)
}
output.Name = "/abs/path/"
output.Multiplicity = "collection"
actual = output.Source()
expected = "/abs/path/"
if actual != expected {
t.Errorf("Source() returned %s instead of %s", actual, expected)
}
_inittests(t, false)
}
func TestConfigParams0ID(t *testing.T) {
s := inittests(t)
params := s.Steps[0].Config.Params[0]
if params.ID != "e7721c78-56c9-41ac-8ff5-8d46093f1fb1" {
t.Errorf("The param ID was '%s' when it should have been 'e7721c78-56c9-41ac-8ff5-8d46093f1fb1'", params.ID)
}
}
func TestConfigParams0Name(t *testing.T) {
s := inittests(t)
params := s.Steps[0].Config.Params[0]
if params.Name != "param0" {
t.Errorf("The param name was '%s' when it should have been 'param0'", params.Name)
}
}
func TestConfigParams0Order(t *testing.T) {
s := inittests(t)
params := s.Steps[0].Config.Params[0]
if params.Order != 2 {
t.Errorf("The param order was '%d' when it should have been '2'", params.Order)
}
}
func TestConfigParams0Value(t *testing.T) {
s := inittests(t)
params := s.Steps[0].Config.Params[0]
if params.Value != "wc_out.txt" {
t.Errorf("The param value was '%s' when it should have been 'wc_out.txt'", params.Value)
}
}
func TestConfigParams1ID(t *testing.T) {
s := inittests(t)
params := s.Steps[0].Config.Params[1]
if params.ID != "2f58fce9-8183-4ab5-97c4-970592d1c35a" {
t.Errorf("The param ID was '%s' when it should have been '2f58fce9-8183-4ab5-97c4-970592d1c35a'", params.ID)
}
}
func TestConfigParams1Name(t *testing.T) {
s := inittests(t)
params := s.Steps[0].Config.Params[1]
if params.Name != "param1" {
t.Errorf("The param name was '%s' when it should have been 'param1'", params.Name)
}
}
func TestConfigParams1Order(t *testing.T) {
s := inittests(t)
params := s.Steps[0].Config.Params[1]
if params.Order != 1 {
t.Errorf("The param order was '%d' when it should have been '1'", params.Order)
}
}
func TestConfigParams1Value(t *testing.T) {
s := inittests(t)
params := s.Steps[0].Config.Params[1]
if params.Value != "Acer-tree.txt" {
t.Errorf("The param value was '%s' when it should have been 'Acer-tree.txt'", params.Value)
}
}