-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathintegration_test.go
More file actions
656 lines (613 loc) · 24.2 KB
/
integration_test.go
File metadata and controls
656 lines (613 loc) · 24.2 KB
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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
// +build integration
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tests
import (
"fmt"
"github.com/apache/incubator-openwhisk-cli/tests/src/integration/common"
"github.com/stretchr/testify/assert"
"os"
"strings"
"testing"
)
var invalidArgs []common.InvalidArg
var invalidArgsMsg = "error: Invalid argument(s)"
var tooFewArgsMsg = invalidArgsMsg + "."
var tooManyArgsMsg = invalidArgsMsg + ": "
var actionNameActionReqMsg = "An action name and code artifact are required."
var actionNameReqMsg = "An action name is required."
var actionOptMsg = "A code artifact is optional."
var packageNameReqMsg = "A package name is required."
var packageNameBindingReqMsg = "A package name and binding name are required."
var ruleNameReqMsg = "A rule name is required."
var ruleTriggerActionReqMsg = "A rule, trigger and action name are required."
var activationIdReq = "An activation ID is required."
var triggerNameReqMsg = "A trigger name is required."
var optNamespaceMsg = "An optional namespace is the only valid argument."
var noArgsReqMsg = "No arguments are required."
var invalidArg = "invalidArg"
var apiCreateReqMsg = "Specify a swagger file or specify an API base path with an API path, an API verb, and an action name."
var apiGetReqMsg = "An API base path or API name is required."
var apiDeleteReqMsg = "An API base path or API name is required. An optional API relative path and operation may also be provided."
var apiListReqMsg = "Optional parameters are: API base path (or API name), API relative path and operation."
var invalidShared = "Cannot use value '" + invalidArg + "' for shared"
func initInvalidArgs() {
invalidArgs = []common.InvalidArg{
{
Cmd: []string{"action", "create"},
Err: tooFewArgsMsg + " " + actionNameActionReqMsg,
},
{
Cmd: []string{"action", "create", "someAction"},
Err: tooFewArgsMsg + " " + actionNameActionReqMsg,
},
{
Cmd: []string{"action", "create", "actionName", "artifactName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"action", "update"},
Err: tooFewArgsMsg + " " + actionNameReqMsg + " " + actionOptMsg,
},
{
Cmd: []string{"action", "update", "actionName", "artifactName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ". " + actionNameReqMsg + " " + actionOptMsg,
},
{
Cmd: []string{"action", "delete"},
Err: tooFewArgsMsg + " " + actionNameReqMsg,
},
{
Cmd: []string{"action", "delete", "actionName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"action", "get"},
Err: tooFewArgsMsg + " " + actionNameReqMsg,
},
{
Cmd: []string{"action", "get", "actionName", "namespace", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"action", "list", "namespace", invalidArg},
Err: tooManyArgsMsg + invalidArg + ". " + optNamespaceMsg,
},
{
Cmd: []string{"action", "invoke"},
Err: tooFewArgsMsg + " " + actionNameReqMsg,
},
{
Cmd: []string{"action", "invoke", "actionName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"activation", "list", "namespace", invalidArg},
Err: tooManyArgsMsg + invalidArg + ". " + optNamespaceMsg,
},
{
Cmd: []string{"activation", "get"},
Err: tooFewArgsMsg + " " + activationIdReq,
},
{
Cmd: []string{"activation", "get", "activationID", "namespace", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"activation", "logs"},
Err: tooFewArgsMsg + " " + activationIdReq,
},
{
Cmd: []string{"activation", "logs", "activationID", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"activation", "result"},
Err: tooFewArgsMsg + " " + activationIdReq,
},
{
Cmd: []string{"activation", "result", "activationID", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"activation", "poll", "activationID", invalidArg},
Err: tooManyArgsMsg + invalidArg + ". " + optNamespaceMsg,
},
{
Cmd: []string{"namespace", "list", invalidArg},
Err: tooManyArgsMsg + invalidArg + ". " + noArgsReqMsg,
},
{
Cmd: []string{"namespace", "get", invalidArg},
Err: tooManyArgsMsg + invalidArg + ". " + noArgsReqMsg,
},
{
Cmd: []string{"package", "create"},
Err: tooFewArgsMsg + " " + packageNameReqMsg,
},
{
Cmd: []string{"package", "create", "packageName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"package", "create", "packageName", "--shared", invalidArg},
Err: invalidShared,
},
{
Cmd: []string{"package", "update"},
Err: tooFewArgsMsg + " " + packageNameReqMsg,
},
{
Cmd: []string{"package", "update", "packageName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"package", "update", "packageName", "--shared", invalidArg},
Err: invalidShared,
},
{
Cmd: []string{"package", "get"},
Err: tooFewArgsMsg + " " + packageNameReqMsg,
},
{
Cmd: []string{"package", "get", "packageName", "namespace", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"package", "bind"},
Err: tooFewArgsMsg + " " + packageNameBindingReqMsg,
},
{
Cmd: []string{"package", "bind", "packageName"},
Err: tooFewArgsMsg + " " + packageNameBindingReqMsg,
},
{
Cmd: []string{"package", "bind", "packageName", "bindingName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"package", "list", "namespace", invalidArg},
Err: tooManyArgsMsg + invalidArg + ". " + optNamespaceMsg,
},
{
Cmd: []string{"package", "delete"},
Err: tooFewArgsMsg + " " + packageNameReqMsg,
},
{
Cmd: []string{"package", "delete", "namespace", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"package", "refresh", "namespace", invalidArg},
Err: tooManyArgsMsg + invalidArg + ". " + optNamespaceMsg,
},
{
Cmd: []string{"rule", "enable"},
Err: tooFewArgsMsg + " " + ruleNameReqMsg,
},
{
Cmd: []string{"rule", "enable", "ruleName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"rule", "disable"},
Err: tooFewArgsMsg + " " + ruleNameReqMsg,
},
{
Cmd: []string{"rule", "disable", "ruleName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"rule", "status"},
Err: tooFewArgsMsg + " " + ruleNameReqMsg,
},
{
Cmd: []string{"rule", "status", "ruleName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"rule", "create"},
Err: tooFewArgsMsg + " " + ruleTriggerActionReqMsg,
},
{
Cmd: []string{"rule", "create", "ruleName"},
Err: tooFewArgsMsg + " " + ruleTriggerActionReqMsg,
},
{
Cmd: []string{"rule", "create", "ruleName", "triggerName"},
Err: tooFewArgsMsg + " " + ruleTriggerActionReqMsg,
},
{
Cmd: []string{"rule", "create", "ruleName", "triggerName", "actionName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"rule", "update"},
Err: tooFewArgsMsg + " " + ruleTriggerActionReqMsg,
},
{
Cmd: []string{"rule", "update", "ruleName"},
Err: tooFewArgsMsg + " " + ruleTriggerActionReqMsg,
},
{
Cmd: []string{"rule", "update", "ruleName", "triggerName"},
Err: tooFewArgsMsg + " " + ruleTriggerActionReqMsg,
},
{
Cmd: []string{"rule", "update", "ruleName", "triggerName", "actionName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"rule", "get"},
Err: tooFewArgsMsg + " " + ruleNameReqMsg,
},
{
Cmd: []string{"rule", "get", "ruleName", "namespace", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"rule", "delete"},
Err: tooFewArgsMsg + " " + ruleNameReqMsg,
},
{
Cmd: []string{"rule", "delete", "ruleName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"rule", "list", "namespace", invalidArg},
Err: tooManyArgsMsg + invalidArg + ". " + optNamespaceMsg,
},
{
Cmd: []string{"trigger", "fire"},
Err: tooFewArgsMsg + " " + triggerNameReqMsg,
},
{
Cmd: []string{"trigger", "fire", "triggerName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ". " + triggerNameReqMsg,
},
{
Cmd: []string{"trigger", "create"},
Err: tooFewArgsMsg + " " + triggerNameReqMsg,
},
{
Cmd: []string{"trigger", "create", "triggerName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"trigger", "update"},
Err: tooFewArgsMsg + " " + triggerNameReqMsg,
},
{
Cmd: []string{"trigger", "update", "triggerName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"trigger", "get"},
Err: tooFewArgsMsg + " " + triggerNameReqMsg,
},
{
Cmd: []string{"trigger", "get", "triggerName", "namespace", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"trigger", "delete"},
Err: tooFewArgsMsg + " " + triggerNameReqMsg,
},
{
Cmd: []string{"trigger", "delete", "triggerName", invalidArg},
Err: tooManyArgsMsg + invalidArg + ".",
},
{
Cmd: []string{"trigger", "list", "namespace", invalidArg},
Err: tooManyArgsMsg + invalidArg + ". " + optNamespaceMsg,
},
}
}
var wsk *common.Wsk = common.NewWsk()
var tmpProp = common.GetRepoPath() + "/wskprops.tmp"
// Test case to set apihost, auth, and namespace.
func TestSetAPIHostAuthNamespace(t *testing.T) {
common.CreateFile(tmpProp)
common.WriteFile(tmpProp, []string{})
os.Setenv("WSK_CONFIG_FILE", tmpProp)
assert.Equal(t, os.Getenv("WSK_CONFIG_FILE"), tmpProp, "The environment variable WSK_CONFIG_FILE has not been set.")
namespace, _ := wsk.ListNamespaces()
namespaces := strings.Split(strings.TrimSpace(string(namespace)), "\n")
expectedNamespace := string(namespaces[len(namespaces)-1])
fmt.Println(wsk.Wskprops.APIHost)
if wsk.Wskprops.APIHost != "" && wsk.Wskprops.AuthKey != "" {
stdout, err := wsk.RunCommand("property", "set", "--apihost", wsk.Wskprops.APIHost,
"--auth", wsk.Wskprops.AuthKey, "--namespace", expectedNamespace)
ouputString := string(stdout)
assert.Equal(t, nil, err, "The command property set --apihost --auth --namespace failed to run.")
assert.Contains(t, ouputString, "ok: whisk auth set. Run 'wsk property get --auth' to see the new value.",
"The output of the command property set --apihost --auth --namespace does not contain \"whisk auth set\".")
assert.Contains(t, ouputString, "ok: whisk API host set to "+wsk.Wskprops.APIHost,
"The output of the command property set --apihost --auth --namespace does not contain \"whisk API host set\".")
assert.Contains(t, ouputString, "ok: whisk namespace set to "+expectedNamespace,
"The output of the command property set --apihost --auth --namespace does not contain \"whisk namespace set\".")
}
common.DeleteFile(tmpProp)
}
// Test delete action when property promptOnChange is true
func TestDeleteActionWhenPromptOnChangeIsTrue(t *testing.T) {
common.CreateFile(tmpProp)
common.WriteFile(tmpProp, []string{})
os.Setenv("WSK_CONFIG_FILE", tmpProp)
assert.Equal(t, os.Getenv("WSK_CONFIG_FILE"), tmpProp, "The environment variable WSK_CONFIG_FILE has not been set.")
namespace, _ := wsk.ListNamespaces()
namespaces := strings.Split(strings.TrimSpace(string(namespace)), "\n")
expectedNamespace := string(namespaces[len(namespaces)-1])
if wsk.Wskprops.APIHost != "" && wsk.Wskprops.AuthKey != "" {
stdout, err := wsk.RunCommand("property", "set", "--apihost", wsk.Wskprops.APIHost,
"--auth", wsk.Wskprops.AuthKey, "--namespace", expectedNamespace, "--promptOnChange")
assert.Equal(t, nil, err, "The command property set --apihost --auth --namespace --promptOnChange failed to run.")
helloFile := common.GetTestActionFilename("hello.js")
stdout, err = wsk.RunCommand("action", "create", "hello", helloFile)
assert.Equal(t, nil, err, "The command action create failed to run.")
stdout, err = wsk.RunCommand("action", "delete", "hello")
assert.Contains(t, common.RemoveRedundentSpaces(string(stdout)), "please delete action using --force if you really want to delete it",
"The output of the command does not contain \"please delete action using --force if you really want to delete it\".")
stdout, err = wsk.RunCommand("action", "delete", "hello", "--force")
assert.Equal(t, nil, err, "The command action delete failed to run.")
}
common.DeleteFile(tmpProp)
}
// Test update action when property promptOnChange is true
func TestUpdateActionWhenPromptOnChangeIsTrue(t *testing.T) {
common.CreateFile(tmpProp)
common.WriteFile(tmpProp, []string{})
os.Setenv("WSK_CONFIG_FILE", tmpProp)
assert.Equal(t, os.Getenv("WSK_CONFIG_FILE"), tmpProp, "The environment variable WSK_CONFIG_FILE has not been set.")
namespace, _ := wsk.ListNamespaces()
namespaces := strings.Split(strings.TrimSpace(string(namespace)), "\n")
expectedNamespace := string(namespaces[len(namespaces)-1])
if wsk.Wskprops.APIHost != "" && wsk.Wskprops.AuthKey != "" {
stdout, err := wsk.RunCommand("property", "set", "--apihost", wsk.Wskprops.APIHost,
"--auth", wsk.Wskprops.AuthKey, "--namespace", expectedNamespace, "--promptOnChange")
assert.Equal(t, nil, err, "The command property set --apihost --auth --namespace --promptOnChange failed to run.")
helloFile := common.GetTestActionFilename("hello.js")
stdout, err = wsk.RunCommand("action", "create", "hello", helloFile)
assert.Equal(t, nil, err, "The command action create failed to run.")
stdout, err = wsk.RunCommand("action", "update", "hello", helloFile)
assert.Contains(t, common.RemoveRedundentSpaces(string(stdout)), "please update action using --force if you really want to update it",
"The output of the command does not contain \"please update action using --force if you really want to update it\".")
stdout, err = wsk.RunCommand("action", "update", "hello", helloFile, "--force")
assert.Equal(t, nil, err, "The command action update failed to run.")
stdout, err = wsk.RunCommand("action", "delete", "hello", "--force")
assert.Equal(t, nil, err, "The command action delete failed to run.")
}
common.DeleteFile(tmpProp)
}
// Test case to show api build version using property file.
func TestShowAPIBuildVersion(t *testing.T) {
common.CreateFile(tmpProp)
os.Setenv("WSK_CONFIG_FILE", tmpProp)
assert.Equal(t, os.Getenv("WSK_CONFIG_FILE"), tmpProp, "The environment variable WSK_CONFIG_FILE has not been set.")
stdout, err := wsk.RunCommand("property", "set", "--apihost", wsk.Wskprops.APIHost,
"--apiversion", wsk.Wskprops.Apiversion)
assert.Equal(t, nil, err, "The command property set --apihost --apiversion failed to run.")
stdout, err = wsk.RunCommand("property", "get", "-i", "--apibuild")
assert.Equal(t, nil, err, "The command property get -i --apibuild failed to run.")
println(common.RemoveRedundentSpaces(string(stdout)))
assert.NotContains(t, common.RemoveRedundentSpaces(string(stdout)), "whisk API build Unknown",
"The output of the command property get --apibuild does not contain \"whisk API build Unknown\".")
assert.NotContains(t, common.RemoveRedundentSpaces(string(stdout)), "Unable to obtain API build information",
"The output of the command property get --apibuild does not contain \"Unable to obtain API build information\".")
assert.Contains(t, common.RemoveRedundentSpaces(string(stdout)), "whisk API build 20",
"The output of the command property get --apibuild does not contain \"whisk API build 20\".")
common.DeleteFile(tmpProp)
}
// Test case to fail to show api build when setting apihost to bogus value.
func TestFailShowAPIBuildVersion(t *testing.T) {
common.CreateFile(tmpProp)
os.Setenv("WSK_CONFIG_FILE", tmpProp)
assert.Equal(t, os.Getenv("WSK_CONFIG_FILE"), tmpProp, "The environment variable WSK_CONFIG_FILE has not been set.")
_, err := wsk.RunCommand("property", "set", "--apihost", "xxxx.yyyy")
assert.Equal(t, nil, err, "The command property set --apihost failed to run.")
stdout, err := wsk.RunCommand("property", "get", "-i", "--apibuild")
assert.NotEqual(t, nil, err, "The command property get -i --apibuild does not raise any error.")
assert.Contains(t, common.RemoveRedundentSpaces(string(stdout)), "whisk API build Unknown",
"The output of the command property get --apibuild does not contain \"whisk API build Unknown\".")
assert.Contains(t, common.RemoveRedundentSpaces(string(stdout)), "Unable to obtain API build information",
"The output of the command property get --apibuild does not contain \"Unable to obtain API build information\".")
}
// Test case to show api build using http apihost.
func TestShowAPIBuildVersionHTTP(t *testing.T) {
common.CreateFile(tmpProp)
os.Setenv("WSK_CONFIG_FILE", tmpProp)
assert.Equal(t, os.Getenv("WSK_CONFIG_FILE"), tmpProp, "The environment variable WSK_CONFIG_FILE has not been set.")
apihost := wsk.Wskprops.APIHost
stdout, err := wsk.RunCommand("property", "set", "--apihost", apihost)
assert.Equal(t, nil, err, "The command property set --apihost failed to run.")
stdout, err = wsk.RunCommand("property", "get", "-i", "--apibuild")
println(common.RemoveRedundentSpaces(string(stdout)))
//assert.Equal(t, nil, err, "The command property get -i --apibuild failed to run.")
assert.NotContains(t, common.RemoveRedundentSpaces(string(stdout)), "whisk API build Unknown",
"The output of the command property get --apibuild does not contain \"whisk API build Unknown\".")
assert.NotContains(t, common.RemoveRedundentSpaces(string(stdout)), "Unable to obtain API build information",
"The output of the command property get --apibuild does not contain \"Unable to obtain API build information\".")
assert.Contains(t, common.RemoveRedundentSpaces(string(stdout)), "whisk API build 20",
"The output of the command property get --apibuild does not contain \"whisk API build 20\".")
common.DeleteFile(tmpProp)
}
// Test case to reject bad command.
func TestRejectAuthCommNoKey(t *testing.T) {
common.CreateFile(tmpProp)
os.Setenv("WSK_CONFIG_FILE", tmpProp)
assert.Equal(t, os.Getenv("WSK_CONFIG_FILE"), tmpProp, "The environment variable WSK_CONFIG_FILE has not been set.")
stdout, err := wsk.RunCommand("list", "--apihost", wsk.Wskprops.APIHost,
"--apiversion", wsk.Wskprops.Apiversion)
assert.NotEqual(t, nil, err, "The command list should fail to run.")
assert.Contains(t, common.RemoveRedundentSpaces(string(stdout)), "usage.",
"The output of the command does not contain \"usage.\".")
assert.Contains(t, common.RemoveRedundentSpaces(string(stdout)), "--auth is required",
"The output of the command does not contain \"--auth is required\".")
common.DeleteFile(tmpProp)
}
// Test case to reject commands that are executed with invalid arguments.
func TestRejectCommInvalidArgs(t *testing.T) {
initInvalidArgs()
for _, invalidArg := range invalidArgs {
cs := invalidArg.Cmd
cs = append(cs, "--apihost", wsk.Wskprops.APIHost)
stdout, err := wsk.RunCommand(cs...)
outputString := string(stdout)
assert.NotEqual(t, nil, err, "The command should fail to run.")
if err.Error() == "exit status 1" {
assert.Equal(t, "exit status 1", err.Error(), "The error should be exit status 1 or 2.")
} else {
assert.Equal(t, "exit status 2", err.Error(), "The error should be exit status 1 or 2.")
}
assert.Contains(t, outputString, invalidArg.Err,
"The output of the command does not contain "+invalidArg.Err)
assert.Contains(t, outputString, "Run 'wsk --help' for usage",
"The output of the command does not contain \"Run 'wsk --help' for usage\".")
}
}
// Test case to reject commands that are executed with invalid JSON for annotations and parameters.
func TestRejectCommInvalidJSON(t *testing.T) {
helloFile := common.GetTestActionFilename("hello.js")
var invalidJSONInputs = []string{
"{\"invalid1\": }",
"{\"invalid2\": bogus}",
"{\"invalid1\": \"aKey\"",
"invalid \"string\"",
"{\"invalid1\": [1, 2, \"invalid\"\"arr\"]}",
}
var invalidJSONFiles = []string{
common.GetTestActionFilename("malformed.js"),
common.GetTestActionFilename("invalidInput1.json"),
common.GetTestActionFilename("invalidInput2.json"),
common.GetTestActionFilename("invalidInput3.json"),
common.GetTestActionFilename("invalidInput4.json"),
}
var invalidParamArg = "Invalid parameter argument"
var invalidAnnoArg = "Invalid annotation argument"
var paramCmds = []common.InvalidArg{
{
Cmd: []string{"action", "create", "actionName", helloFile},
Err: invalidParamArg,
},
{
Cmd: []string{"action", "update", "actionName", helloFile},
Err: invalidParamArg,
},
{
Cmd: []string{"action", "invoke", "actionName"},
Err: invalidParamArg,
},
{
Cmd: []string{"package", "create", "packageName"},
Err: invalidParamArg,
},
{
Cmd: []string{"package", "update", "packageName"},
Err: invalidParamArg,
},
{
Cmd: []string{"package", "bind", "packageName", "boundPackageName"},
Err: invalidParamArg,
},
{
Cmd: []string{"trigger", "create", "triggerName"},
Err: invalidParamArg,
},
{
Cmd: []string{"trigger", "update", "triggerName"},
Err: invalidParamArg,
},
{
Cmd: []string{"trigger", "fire", "triggerName"},
Err: invalidParamArg,
},
}
var annotCmds = []common.InvalidArg{
{
Cmd: []string{"action", "create", "actionName", helloFile},
Err: invalidAnnoArg,
},
{
Cmd: []string{"action", "update", "actionName", helloFile},
Err: invalidAnnoArg,
},
{
Cmd: []string{"package", "create", "packageName"},
Err: invalidAnnoArg,
},
{
Cmd: []string{"package", "update", "packageName"},
Err: invalidAnnoArg,
},
{
Cmd: []string{"package", "bind", "packageName", "boundPackageName"},
Err: invalidAnnoArg,
},
{
Cmd: []string{"trigger", "create", "triggerName"},
Err: invalidAnnoArg,
},
{
Cmd: []string{"trigger", "update", "triggerName"},
Err: invalidAnnoArg,
},
}
for _, cmd := range paramCmds {
for _, invalid := range invalidJSONInputs {
cs := cmd.Cmd
cs = append(cs, "-p", "key", invalid, "--apihost", wsk.Wskprops.APIHost)
stdout, err := wsk.RunCommand(cs...)
outputString := string(stdout)
assert.NotEqual(t, nil, err, "The command should fail to run.")
assert.Equal(t, "exit status 1", err.Error(), "The error should be exit status 1.")
assert.Contains(t, outputString, cmd.Err,
"The output of the command does not contain "+cmd.Err+" .")
}
for _, invalid := range invalidJSONFiles {
cs := cmd.Cmd
cs = append(cs, "-P", invalid, "--apihost", wsk.Wskprops.APIHost)
stdout, err := wsk.RunCommand(cs...)
outputString := string(stdout)
assert.NotEqual(t, nil, err, "The command should fail to run.")
assert.Equal(t, "exit status 1", err.Error(), "The error should be exit status 1.")
assert.Contains(t, outputString, cmd.Err,
"The output of the command does not contain "+cmd.Err+" .")
}
}
for _, cmd := range annotCmds {
for _, invalid := range invalidJSONInputs {
cs := cmd.Cmd
cs = append(cs, "-a", "key", invalid, "--apihost", wsk.Wskprops.APIHost)
stdout, err := wsk.RunCommand(cs...)
outputString := string(stdout)
assert.NotEqual(t, nil, err, "The command should fail to run.")
assert.Equal(t, "exit status 1", err.Error(), "The error should be exit status 1.")
assert.Contains(t, outputString, cmd.Err,
"The output of the command does not contain "+cmd.Err+" .")
}
for _, invalid := range invalidJSONFiles {
cs := cmd.Cmd
cs = append(cs, "-A", invalid, "--apihost", wsk.Wskprops.APIHost)
stdout, err := wsk.RunCommand(cs...)
outputString := string(stdout)
assert.NotEqual(t, nil, err, "The command should fail to run.")
assert.Equal(t, "exit status 1", err.Error(), "The error should be exit status 1.")
assert.Contains(t, outputString, cmd.Err,
"The output of the command does not contain "+cmd.Err+" .")
}
}
}