forked from redhat-developer/odo
/
component.go
796 lines (670 loc) · 36.5 KB
/
component.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
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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
package integration
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper"
)
func componentTests(args ...string) {
var oc helper.OcRunner
var project string
var context string
var originalDir string
BeforeEach(func() {
SetDefaultEventuallyTimeout(10 * time.Minute)
SetDefaultConsistentlyDuration(30 * time.Second)
context = helper.CreateNewContext()
os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml"))
oc = helper.NewOcRunner("oc")
})
// Clean up after the test
// This is run after every Spec (It)
var _ = AfterEach(func() {
helper.DeleteDir(context)
os.Unsetenv("GLOBALODOCONFIG")
})
Context("Generic machine readable output tests", func() {
It("Command should fail if json is non-existent for a command", func() {
output := helper.CmdShouldFail("odo", "version", "-o", "json")
Expect(output).To(ContainSubstring("Machine readable output is not yet implemented for this command"))
})
It("Help for odo version should not contain machine output", func() {
output := helper.CmdShouldPass("odo", "version", "--help")
Expect(output).NotTo(ContainSubstring("Specify output format, supported format: json"))
})
})
Context("Creating component", func() {
JustBeforeEach(func() {
project = helper.CreateRandProject()
originalDir = helper.Getwd()
helper.Chdir(context)
})
JustAfterEach(func() {
helper.DeleteProject(project)
helper.Chdir(originalDir)
})
It("should create component even in new project", func() {
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "cmp-git", "--git", "https://github.com/openshift/nodejs-ex", "--project", project, "--context", context, "--app", "testing")...)
helper.CmdShouldPass("odo", "push", "--context", context, "-v4")
oc.SwitchProject(project)
projectList := helper.CmdShouldPass("odo", "project", "list")
Expect(projectList).To(ContainSubstring(project))
})
It("Without an application should create one", func() {
componentName := helper.RandString(6)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "--project", project, componentName, "--ref", "master", "--git", "https://github.com/openshift/nodejs-ex")...)
helper.CmdShouldPass("odo", "push")
appName := helper.CmdShouldPass("odo", "app", "list")
Expect(appName).ToNot(BeEmpty())
// checking if application name is set to "app"
applicationName := helper.GetConfigValue("Application")
Expect(applicationName).To(Equal("app"))
// clean up
helper.CmdShouldPass("odo", "app", "delete", "app", "-f")
helper.CmdShouldFail("odo", "app", "delete", "app", "-f")
helper.CmdShouldFail("odo", "component", "delete", componentName, "-f")
})
It("should create default named component when passed same context differently", func() {
dir := filepath.Base(context)
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "--project", project, "--context", ".", "--app", "testing")...)
componentName := helper.GetConfigValueWithContext("Name", context)
Expect(componentName).To(ContainSubstring("nodejs-" + dir))
helper.DeleteDir(filepath.Join(context, ".odo"))
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "--project", project, "--context", context, "--app", "testing")...)
newComponentName := helper.GetConfigValueWithContext("Name", context)
Expect(newComponentName).To(ContainSubstring("nodejs-" + dir))
})
It("should show an error when ref flag is provided with sources except git", func() {
outputErr := helper.CmdShouldFail("odo", append(args, "create", "nodejs", "--project", project, "cmp-git", "--ref", "test")...)
Expect(outputErr).To(ContainSubstring("The --ref flag is only valid for --git flag"))
})
It("create component twice fails from same directory", func() {
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "nodejs", "--project", project)...)
output := helper.CmdShouldFail("odo", append(args, "create", "nodejs", "nodejs", "--project", project)...)
Expect(output).To(ContainSubstring("this directory already contains a component"))
})
It("should list out component in json format along with path flag", func() {
var contextPath string
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "nodejs", "--project", project)...)
if runtime.GOOS == "windows" {
contextPath = strings.Replace(strings.TrimSpace(context), "\\", "\\\\", -1)
} else {
contextPath = strings.TrimSpace(context)
}
// this orders the json
desired, err := helper.Unindented(fmt.Sprintf(`{"kind":"Component","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"nodejs","namespace":"%s","creationTimestamp":null},"spec":{"app":"app","type":"nodejs","source":"./","ports":["8080/TCP"]},"status":{"context":"%s","state":"Not Pushed"}}`, project, contextPath))
Expect(err).Should(BeNil())
actual, err := helper.Unindented(helper.CmdShouldPass("odo", append(args, "list", "-o", "json", "--path", filepath.Dir(context))...))
Expect(err).Should(BeNil())
// since the tests are run parallel, there might be many odo component directories in the root folder
// so we only check for the presence of the current one
Expect(actual).Should(ContainSubstring(desired))
})
It("should list out pushed components of different projects in json format along with path flag", func() {
var contextPath string
var contextPath2 string
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "nodejs", "--project", project)...)
helper.CmdShouldPass("odo", append(args, "push")...)
project2 := helper.CreateRandProject()
context2 := helper.CreateNewContext()
helper.Chdir(context2)
helper.CopyExample(filepath.Join("source", "python"), context2)
helper.CmdShouldPass("odo", append(args, "create", "python", "python", "--project", project2)...)
helper.CmdShouldPass("odo", append(args, "push")...)
if runtime.GOOS == "windows" {
contextPath = strings.Replace(strings.TrimSpace(context), "\\", "\\\\", -1)
contextPath2 = strings.Replace(strings.TrimSpace(context2), "\\", "\\\\", -1)
} else {
contextPath = strings.TrimSpace(context)
contextPath2 = strings.TrimSpace(context2)
}
actual, err := helper.Unindented(helper.CmdShouldPass("odo", append(args, "list", "-o", "json", "--path", filepath.Dir(context))...))
Expect(err).Should(BeNil())
helper.Chdir(context)
helper.DeleteDir(context2)
helper.DeleteProject(project2)
// this orders the json
expected, err := helper.Unindented(fmt.Sprintf(`{"kind":"Component","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"nodejs","namespace":"%s","creationTimestamp":null},"spec":{"app":"app","type":"nodejs","source":"./","ports":["8080/TCP"]},"status":{"context":"%s","state":"Pushed"}}`, project, contextPath))
Expect(err).Should(BeNil())
Expect(actual).Should(ContainSubstring(expected))
// this orders the json
expected, err = helper.Unindented(fmt.Sprintf(`{"kind":"Component","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"python","namespace":"%s","creationTimestamp":null},"spec":{"app":"app","type":"python","source":"./","ports":["8080/TCP"]},"status":{"context":"%s","state":"Pushed"}}`, project2, contextPath2))
Expect(err).Should(BeNil())
Expect(actual).Should(ContainSubstring(expected))
})
It("should create the component from the branch ref when provided", func() {
helper.CmdShouldPass("odo", append(args, "create", "ruby", "ref-test", "--project", project, "--git", "https://github.com/girishramnani/ruby-ex.git", "--ref", "develop")...)
helper.CmdShouldPass("odo", "push")
})
It("should list the component", func() {
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "cmp-git", "--project", project, "--git", "https://github.com/openshift/nodejs-ex", "--min-memory", "100Mi", "--max-memory", "300Mi", "--min-cpu", "0.1", "--max-cpu", "2", "--context", context, "--app", "testing")...)
helper.CmdShouldPass("odo", "push", "--context", context)
cmpList := helper.CmdShouldPass("odo", append(args, "list", "--project", project)...)
Expect(cmpList).To(ContainSubstring("cmp-git"))
actualCompListJSON := helper.CmdShouldPass("odo", append(args, "list", "--project", project, "-o", "json")...)
desiredCompListJSON := fmt.Sprintf(`{"kind":"List","apiVersion":"odo.openshift.io/v1alpha1","metadata":{},"items":[{"kind":"Component","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"cmp-git","namespace":"%s","creationTimestamp":null},"spec":{"app":"testing","type":"nodejs","source":"https://github.com/openshift/nodejs-ex","env":[{"name":"DEBUG_PORT","value":"5858"}]},"status":{"state":"Pushed"}}]}`, project)
Expect(desiredCompListJSON).Should(MatchJSON(actualCompListJSON))
cmpAllList := helper.CmdShouldPass("odo", append(args, "list", "--all")...)
Expect(cmpAllList).To(ContainSubstring("cmp-git"))
helper.CmdShouldPass("odo", append(args, "delete", "cmp-git", "-f")...)
})
It("should list the component when it is not pushed", func() {
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "cmp-git", "--project", project, "--git", "https://github.com/openshift/nodejs-ex", "--min-memory", "100Mi", "--max-memory", "300Mi", "--min-cpu", "0.1", "--max-cpu", "2", "--context", context, "--app", "testing")...)
cmpList := helper.CmdShouldPass("odo", append(args, "list", "--context", context)...)
Expect(cmpList).To(ContainSubstring("cmp-git"))
Expect(cmpList).To(ContainSubstring("Not Pushed"))
helper.CmdShouldPass("odo", append(args, "delete", "-f", "--all", "--context", context)...)
})
It("should describe the component when it is not pushed", func() {
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "cmp-git", "--project", project, "--git", "https://github.com/openshift/nodejs-ex", "--context", context, "--app", "testing")...)
helper.CmdShouldPass("odo", "url", "create", "url-1", "--context", context)
cmpDescribe := helper.CmdShouldPass("odo", append(args, "describe", "--context", context)...)
Expect(cmpDescribe).To(ContainSubstring("cmp-git"))
Expect(cmpDescribe).To(ContainSubstring("nodejs"))
Expect(cmpDescribe).To(ContainSubstring("url-1"))
Expect(cmpDescribe).To(ContainSubstring("https://github.com/openshift/nodejs-ex"))
cmpDescribeJson, err := helper.Unindented(helper.CmdShouldPass("odo", append(args, "describe", "-o", "json", "--context", context)...))
Expect(err).Should(BeNil())
expected, err := helper.Unindented(`{"kind": "Component","apiVersion": "odo.openshift.io/v1alpha1","metadata": {"name": "cmp-git","namespace": "` + project + `","creationTimestamp": null},"spec":{"app": "testing","type":"nodejs","source": "https://github.com/openshift/nodejs-ex","url": ["url-1"],"ports": ["8080/TCP"]},"status": {"state": "Not Pushed"}}`)
Expect(err).Should(BeNil())
Expect(cmpDescribeJson).To(Equal(expected))
helper.CmdShouldPass("odo", append(args, "delete", "-f", "--all", "--context", context)...)
})
It("should list the component in the same app when one is pushed and the other one is not pushed", func() {
helper.Chdir(originalDir)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "cmp-git", "--project", project, "--git", "https://github.com/openshift/nodejs-ex", "--context", context, "--app", "testing")...)
helper.CmdShouldPass("odo", append(args, "push", "--context", context)...)
context2 := helper.CreateNewContext()
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "cmp-git-2", "--project", project, "--git", "https://github.com/openshift/nodejs-ex", "--context", context2, "--app", "testing")...)
cmpList := helper.CmdShouldPass("odo", append(args, "list", "--context", context2)...)
Expect(cmpList).To(ContainSubstring("cmp-git"))
Expect(cmpList).To(ContainSubstring("cmp-git-2"))
Expect(cmpList).To(ContainSubstring("Not Pushed"))
Expect(cmpList).To(ContainSubstring("Pushed"))
helper.CmdShouldPass("odo", append(args, "delete", "-f", "--all", "--context", context)...)
helper.CmdShouldPass("odo", append(args, "delete", "-f", "--all", "--context", context2)...)
helper.DeleteDir(context2)
})
It("should succeed listing catalog components", func() {
// Since components catalog is constantly changing, we simply check to see if this command passes.. rather than checking the JSON each time.
output := helper.CmdShouldPass("odo", "catalog", "list", "components", "-o", "json")
Expect(output).To(ContainSubstring("List"))
})
It("binary component should not fail when --context is not set", func() {
oc.ImportJavaIS(project)
helper.CopyExample(filepath.Join("binary", "java", "openjdk"), context)
// Was failing due to https://github.com/openshift/odo/issues/1969
helper.CmdShouldPass("odo", "create", "java:8", "sb-jar-test", "--project",
project, "--binary", filepath.Join(context, "sb.jar"))
})
It("binary component should fail when --binary is not in --context folder", func() {
oc.ImportJavaIS(project)
helper.CopyExample(filepath.Join("binary", "java", "openjdk"), context)
newContext := helper.CreateNewContext()
defer helper.DeleteDir(newContext)
output := helper.CmdShouldFail("odo", "create", "java:8", "sb-jar-test", "--project",
project, "--binary", filepath.Join(context, "sb.jar"), "--context", newContext)
Expect(output).To(ContainSubstring("inside of the context directory"))
})
It("binary component is valid if path is relative and includes ../", func() {
oc.ImportJavaIS(project)
helper.CopyExample(filepath.Join("binary", "java", "openjdk"), context)
relativeContext := fmt.Sprintf("..%c%s", filepath.Separator, filepath.Base(context))
fmt.Printf("relativeContext = %#v\n", relativeContext)
helper.CmdShouldPass("odo", "create", "java:8", "sb-jar-test", "--project",
project, "--binary", filepath.Join(context, "sb.jar"), "--context", relativeContext)
})
})
Context("Test odo push with --source and --config flags", func() {
JustBeforeEach(func() {
project = helper.CreateRandProject()
originalDir = helper.Getwd()
helper.Chdir(context)
})
JustAfterEach(func() {
helper.DeleteProject(project)
helper.Chdir(originalDir)
})
Context("Using project flag(--project) and current directory", func() {
It("create local nodejs component and push source and code separately", func() {
appName := "nodejs-push-test"
cmpName := "nodejs"
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", cmpName, "--app", appName, "--project", project)...)
// component doesn't exist yet so attempt to only push source should fail
helper.CmdShouldFail("odo", "push", "--source")
// Push only config and see that the component is created but wothout any source copied
helper.CmdShouldPass("odo", "push", "--config")
oc.VerifyCmpExists(cmpName, appName, project)
// Push only source and see that the component is updated with source code
helper.CmdShouldPass("odo", "push", "--source")
oc.VerifyCmpExists(cmpName, appName, project)
remoteCmdExecPass := oc.CheckCmdOpInRemoteCmpPod(
cmpName,
appName,
project,
[]string{"sh", "-c", "ls -la $ODO_S2I_DEPLOYMENT_DIR/package.json"},
func(cmdOp string, err error) bool {
return err == nil
},
)
Expect(remoteCmdExecPass).To(Equal(true))
})
It("create local nodejs component and push source and code at once", func() {
appName := "nodejs-push-test"
cmpName := "nodejs-push-atonce"
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", cmpName, "--app", appName, "--project", project)...)
// Push only config and see that the component is created but wothout any source copied
helper.CmdShouldPass("odo", "push")
oc.VerifyCmpExists(cmpName, appName, project)
remoteCmdExecPass := oc.CheckCmdOpInRemoteCmpPod(
cmpName,
appName,
project,
[]string{"sh", "-c", "ls -la $ODO_S2I_DEPLOYMENT_DIR/package.json"},
func(cmdOp string, err error) bool {
return err == nil
},
)
Expect(remoteCmdExecPass).To(Equal(true))
})
})
Context("when --context is used", func() {
// don't need to switch to any dir here, as this test should use --context flag
It("create local nodejs component and push source and code separately", func() {
appName := "nodejs-push-context-test"
cmpName := "nodejs"
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", cmpName, "--context", context, "--app", appName, "--project", project)...)
//TODO: verify that config was properly created
// component doesn't exist yet so attempt to only push source should fail
helper.CmdShouldFail("odo", "push", "--source", "--context", context)
// Push only config and see that the component is created but wothout any source copied
helper.CmdShouldPass("odo", "push", "--config", "--context", context)
oc.VerifyCmpExists(cmpName, appName, project)
// Push only source and see that the component is updated with source code
helper.CmdShouldPass("odo", "push", "--source", "--context", context)
oc.VerifyCmpExists(cmpName, appName, project)
remoteCmdExecPass := oc.CheckCmdOpInRemoteCmpPod(
cmpName,
appName,
project,
[]string{"sh", "-c", "ls -la $ODO_S2I_DEPLOYMENT_DIR/package.json"},
func(cmdOp string, err error) bool {
return err == nil
},
)
Expect(remoteCmdExecPass).To(Equal(true))
})
It("create local nodejs component and push source and code at once", func() {
appName := "nodejs-push-context-test"
cmpName := "nodejs-push-atonce"
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", cmpName, "--app", appName, "--context", context, "--project", project)...)
// Push both config and source
helper.CmdShouldPass("odo", "push", "--context", context)
oc.VerifyCmpExists(cmpName, appName, project)
remoteCmdExecPass := oc.CheckCmdOpInRemoteCmpPod(
cmpName,
appName,
project,
[]string{"sh", "-c", "ls -la $ODO_S2I_DEPLOYMENT_DIR/package.json"},
func(cmdOp string, err error) bool {
return err == nil
},
)
Expect(remoteCmdExecPass).To(Equal(true))
})
})
})
Context("Creating Component even in new project", func() {
var project string
JustBeforeEach(func() {
project = helper.RandString(10)
})
JustAfterEach(func() {
helper.DeleteProject(project)
})
It("should create component", func() {
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "cmp-git", "--git", "https://github.com/openshift/nodejs-ex", "--project", project, "--context", context, "--app", "testing")...)
helper.CmdShouldPass("odo", "push", "--context", context, "-v4")
oc.SwitchProject(project)
projectList := helper.CmdShouldPass("odo", "project", "list")
Expect(projectList).To(ContainSubstring(project))
})
})
Context("Test odo push with --now flag during creation", func() {
JustBeforeEach(func() {
project = helper.CreateRandProject()
originalDir = helper.Getwd()
helper.Chdir(context)
})
JustAfterEach(func() {
helper.Chdir(originalDir)
})
It("should successfully create config and push code in one create command with --now", func() {
appName := "nodejs-create-now-test"
cmpName := "nodejs-push-atonce"
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", cmpName, "--app", appName, "--project", project, "--now")...)
oc.VerifyCmpExists(cmpName, appName, project)
remoteCmdExecPass := oc.CheckCmdOpInRemoteCmpPod(
cmpName,
appName,
project,
[]string{"sh", "-c", "ls -la $ODO_S2I_DEPLOYMENT_DIR/package.json"},
func(cmdOp string, err error) bool {
return err == nil
},
)
Expect(remoteCmdExecPass).To(Equal(true))
})
})
Context("when component is in the current directory and --project flag is used", func() {
appName := "app"
componentName := "my-component"
JustBeforeEach(func() {
project = helper.CreateRandProject()
originalDir = helper.Getwd()
helper.Chdir(context)
})
JustAfterEach(func() {
helper.Chdir(originalDir)
helper.DeleteProject(project)
})
It("create local nodejs component twice and fail", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "--project", project, "--env", "key=value,key1=value1")...)
output := helper.CmdShouldFail("odo", append(args, "create", "nodejs", "--project", project, "--env", "key=value,key1=value1")...)
Expect(output).To(ContainSubstring("this directory already contains a component"))
})
It("creates and pushes local nodejs component and then deletes --all", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", componentName, "--app", appName, "--project", project, "--env", "key=value,key1=value1")...)
helper.CmdShouldPass("odo", append(args, "push", "--context", context)...)
helper.CmdShouldPass("odo", append(args, "delete", "--context", context, "-f", "--all", "--app", appName)...)
componentList := helper.CmdShouldPass("odo", append(args, "list", "--context", context, "--app", appName, "--project", project)...)
Expect(componentList).NotTo(ContainSubstring(componentName))
files := helper.ListFilesInDir(context)
Expect(files).NotTo(ContainElement(".odo"))
})
It("creates a local python component, pushes it and then deletes it using --all flag", func() {
helper.CopyExample(filepath.Join("source", "python"), context)
helper.CmdShouldPass("odo", append(args, "create", "python", componentName, "--app", appName, "--project", project, "--context", context)...)
helper.CmdShouldPass("odo", append(args, "push", "--context", context)...)
helper.CmdShouldPass("odo", append(args, "delete", "--context", context, "-f")...)
helper.CmdShouldPass("odo", append(args, "delete", "--all", "-f", "--context", context)...)
componentList := helper.CmdShouldPass("odo", append(args, "list", "--context", context, "--app", appName, "--project", project)...)
Expect(componentList).NotTo(ContainSubstring(componentName))
files := helper.ListFilesInDir(context)
Expect(files).NotTo(ContainElement(".odo"))
})
It("creates a local python component, pushes it and then deletes it using --all flag in local directory", func() {
helper.CopyExample(filepath.Join("source", "python"), context)
helper.CmdShouldPass("odo", append(args, "create", "python", componentName, "--app", appName, "--project", project)...)
helper.CmdShouldPass("odo", append(args, "push")...)
helper.CmdShouldPass("odo", append(args, "delete", "--all", "-f")...)
componentList := helper.CmdShouldPass("odo", append(args, "list", "--app", appName, "--project", project)...)
Expect(componentList).NotTo(ContainSubstring(componentName))
files := helper.ListFilesInDir(context)
fmt.Println(files)
Expect(files).NotTo(ContainElement(".odo"))
})
It("creates a local python component and check for unsupported warning", func() {
helper.CopyExample(filepath.Join("source", "python"), context)
output := helper.CmdShouldPass("odo", append(args, "create", "python", componentName, "--app", appName, "--project", project, "--context", context)...)
Expect(output).To(ContainSubstring("Warning: python is not fully supported by odo, and it is not guaranteed to work"))
})
It("creates a local nodejs component and check unsupported warning hasn't occured", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context)
output := helper.CmdShouldPass("odo", append(args, "create", "nodejs:8", componentName, "--app", appName, "--project", project, "--context", context)...)
Expect(output).NotTo(ContainSubstring("Warning"))
})
})
/*
Enable once #1782 and #1778 are fixed
Context("odo component updating", func() {
JustBeforeEach(func() {
project = helper.CreateRandProject()
})
JustAfterEach(func() {
helper.DeleteProject(project)
})
It("should be able to create a git component and update it from local to git", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "cmp-git", "--project", project, "--min-cpu", "0.1", "--max-cpu", "2", "--context", context, "--app", "testing")...)
helper.CmdShouldPass("odo", "push", "--context", context, "-v", "4")
getCPULimit := oc.MaxCPU("cmp-git", "testing", project)
Expect(getCPULimit).To(ContainSubstring("2"))
getCPURequest := oc.MinCPU("cmp-git", "testing", project)
Expect(getCPURequest).To(ContainSubstring("100m"))
// update the component config according to the git component
helper.CmdShouldPass("odo", "config", "set", "sourcelocation", "https://github.com/openshift/nodejs-ex", "--context", context, "-f")
helper.CmdShouldPass("odo", "config", "set", "sourcetype", "git", "--context", context, "-f")
// check if the earlier resource requests are still valid
helper.CmdShouldPass("odo", "push", "--context", context, "-v", "4")
getCPULimit = oc.MaxCPU("cmp-git", "testing", project)
Expect(getCPULimit).To(ContainSubstring("2"))
getCPURequest = oc.MinCPU("cmp-git", "testing", project)
Expect(getCPURequest).To(ContainSubstring("100m"))
// check the source location and type in the deployment config
getSourceLocation := oc.SourceLocationDC("cmp-git", "testing", project)
Expect(getSourceLocation).To(ContainSubstring("https://github.com/openshift/nodejs-ex"))
getSourceType := oc.SourceTypeDC("cmp-git", "testing", project)
Expect(getSourceType).To(ContainSubstring("git"))
// since the current component type is git
// check the source location and type in the build config
getSourceLocation = oc.SourceLocationBC("cmp-git", "testing", project)
Expect(getSourceLocation).To(ContainSubstring("https://github.com/openshift/nodejs-ex"))
getSourceType = oc.SourceTypeBC("cmp-git", "testing", project)
Expect(getSourceType).To(ContainSubstring("Git"))
})
It("should be able to update a component from git to local", func() {
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "cmp-git", "--project", project, "--git", "https://github.com/openshift/nodejs-ex", "--min-memory", "100Mi", "--max-memory", "300Mi", "--context", context, "--app", "testing")...)
helper.CmdShouldPass("odo", "push", "--context", context, "-v", "4")
getMemoryLimit := oc.MaxMemory("cmp-git", "testing", project)
Expect(getMemoryLimit).To(ContainSubstring("300Mi"))
getMemoryRequest := oc.MinMemory("cmp-git", "testing", project)
Expect(getMemoryRequest).To(ContainSubstring("100Mi"))
// update the component config according to the git component
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", "config", "set", "sourcelocation", "./", "--context", context, "-f")
helper.CmdShouldPass("odo", "config", "set", "sourcetype", "local", "--context", context, "-f")
// check if the earlier resource requests are still valid
helper.CmdShouldPass("odo", "push", "--context", context, "-v", "4")
getMemoryLimit = oc.MaxMemory("cmp-git", "testing", project)
Expect(getMemoryLimit).To(ContainSubstring("300Mi"))
getMemoryRequest = oc.MinMemory("cmp-git", "testing", project)
Expect(getMemoryRequest).To(ContainSubstring("100Mi"))
// check the source location and type in the deployment config
getSourceLocation := oc.SourceLocationDC("cmp-git", "testing", project)
var sourcePath string
if runtime.GOOS == "windows" {
sourcePath = "file:///./"
} else {
sourcePath = "file://./"
}
Expect(getSourceLocation).To(ContainSubstring(sourcePath))
getSourceType := oc.SourceTypeDC("cmp-git", "testing", project)
Expect(getSourceType).To(ContainSubstring("local"))
})
})
})
*/
Context("odo component delete, list and describe", func() {
appName := "app"
cmpName := "nodejs"
JustBeforeEach(func() {
project = helper.CreateRandProject()
originalDir = helper.Getwd()
})
JustAfterEach(func() {
helper.DeleteProject(project)
helper.Chdir(originalDir)
})
It("should pass inside a odo directory without component name as parameter", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", cmpName, "--app", appName, "--project", project, "--context", context)...)
helper.CmdShouldPass("odo", "url", "create", "example", "--context", context)
helper.CmdShouldPass("odo", "push", "--context", context)
// changing directory to the context directory
helper.Chdir(context)
cmpListOutput := helper.CmdShouldPass("odo", "list")
Expect(cmpListOutput).To(ContainSubstring(cmpName))
cmpDescribe := helper.CmdShouldPass("odo", "describe")
Expect(cmpDescribe).To(ContainSubstring(cmpName))
Expect(cmpDescribe).To(ContainSubstring("nodejs"))
if runtime.GOOS == "windows" {
Expect(cmpDescribe).To(ContainSubstring("file:///./"))
} else {
Expect(cmpDescribe).To(ContainSubstring("file://./"))
}
url := helper.DetermineRouteURL(context)
Expect(cmpDescribe).To(ContainSubstring(url))
helper.CmdShouldPass("odo", "delete", "-f")
})
It("should fail outside a odo directory without component name as parameter", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", cmpName, "--app", appName, "--project", project, "--context", context)...)
helper.CmdShouldPass("odo", "push", "--context", context)
// list command should fail as no app flag is given
helper.CmdShouldFail("odo", "list", "--project", project)
// commands should fail as the component name is missing
helper.CmdShouldFail("odo", "describe", "--app", appName, "--project", project)
helper.CmdShouldFail("odo", "delete", "-f", "--app", appName, "--project", project)
})
It("should pass outside a odo directory with component name as parameter", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", cmpName, "--app", appName, "--project", project, "--context", context)...)
helper.CmdShouldPass("odo", append(args, "push", "--context", context)...)
cmpListOutput := helper.CmdShouldPass("odo", append(args, "list", "--app", appName, "--project", project)...)
Expect(cmpListOutput).To(ContainSubstring(cmpName))
actualDesCompJSON := helper.CmdShouldPass("odo", append(args, "describe", cmpName, "--app", appName, "--project", project, "-o", "json")...)
var sourcePath string
if runtime.GOOS == "windows" {
sourcePath = "file:///./"
} else {
sourcePath = "file://./"
}
desiredDesCompJSON := fmt.Sprintf(`{"kind":"Component","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"nodejs","namespace":"%s","creationTimestamp":null},"spec":{"app":"app","type":"nodejs","source":"%s","env":[{"name":"DEBUG_PORT","value":"5858"}]},"status":{"state":"Pushed"}}`, project, sourcePath)
Expect(desiredDesCompJSON).Should(MatchJSON(actualDesCompJSON))
helper.CmdShouldPass("odo", append(args, "delete", cmpName, "--app", appName, "--project", project, "-f")...)
})
})
Context("when running odo push multiple times, check for existence of environment variables", func() {
JustBeforeEach(func() {
project = helper.CreateRandProject()
originalDir = helper.Getwd()
})
JustAfterEach(func() {
helper.DeleteProject(project)
helper.Chdir(originalDir)
})
It("should should retain the same environment variable on multiple push", func() {
componentName := helper.RandString(6)
appName := helper.RandString(6)
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", componentName, "--app", appName, "--project", project, "--context", context)...)
helper.CmdShouldPass("odo", "push", "--context", context)
helper.Chdir(context)
helper.CmdShouldPass("odo", "config", "set", "--env", "FOO=BAR")
helper.CmdShouldPass("odo", "push")
dcName := oc.GetDcName(componentName, project)
stdOut := helper.CmdShouldPass("oc", "get", "dc/"+dcName, "-n", project, "-o", "go-template={{ .spec.template.spec }}{{.env}}")
Expect(stdOut).To(ContainSubstring("FOO"))
helper.CmdShouldPass("odo", "push")
stdOut = oc.DescribeDc(dcName, project)
Expect(stdOut).To(ContainSubstring("FOO"))
})
})
Context("Creating component with numeric named context", func() {
var contextNumeric string
JustBeforeEach(func() {
var err error
ts := time.Now().UnixNano()
contextNumeric, err = ioutil.TempDir("", fmt.Sprint(ts))
Expect(err).ToNot(HaveOccurred())
project = helper.CreateRandProject()
})
JustAfterEach(func() {
helper.DeleteProject(project)
helper.DeleteDir(contextNumeric)
})
It("should create default named component in a directory with numeric name", func() {
helper.CopyExample(filepath.Join("source", "nodejs"), contextNumeric)
helper.CmdShouldPass("odo", append(args, "create", "nodejs", "--project", project, "--context", contextNumeric, "--app", "testing")...)
helper.CmdShouldPass("odo", "push", "--context", contextNumeric, "-v4")
})
})
Context("when creating component with improper memory quantities", func() {
JustBeforeEach(func() {
project = helper.CreateRandProject()
})
JustAfterEach(func() {
helper.DeleteProject(project)
})
It("should fail gracefully with proper error message", func() {
stdError := helper.CmdShouldFail("odo", append(args, "create", "java:8", "backend", "--memory", "1GB", "--project", project, "--context", context)...)
Expect(stdError).ToNot(ContainSubstring("panic: cannot parse"))
Expect(stdError).To(ContainSubstring("quantities must match the regular expression"))
})
})
Context("Creating component using symlink", func() {
var symLinkPath string
JustBeforeEach(func() {
if runtime.GOOS == "windows" {
Skip("Skipping test because for symlink creation on platform like Windows, go library needs elevated privileges.")
}
// create a symlink
symLinkName := helper.RandString(10)
helper.CreateSymLink(context, filepath.Join(filepath.Dir(context), symLinkName))
symLinkPath = filepath.Join(filepath.Dir(context), symLinkName)
project = helper.CreateRandProject()
originalDir = helper.Getwd()
})
JustAfterEach(func() {
// remove the symlink
err := os.Remove(symLinkPath)
Expect(err).NotTo(HaveOccurred())
helper.DeleteProject(project)
helper.Chdir(originalDir)
})
It("Should be able to deploy a spring boot uberjar file using symlinks in all odo commands", func() {
oc.ImportJavaIS(project)
helper.CopyExample(filepath.Join("binary", "java", "openjdk"), context)
// create the component using symlink
helper.CmdShouldPass("odo", append(args, "create", "java:8", "sb-jar-test", "--project",
project, "--binary", filepath.Join(symLinkPath, "sb.jar"), "--context", symLinkPath)...)
// Create a URL and push without using the symlink
helper.CmdShouldPass("odo", "url", "create", "uberjaropenjdk", "--port", "8080", "--context", symLinkPath)
helper.CmdShouldPass("odo", append(args, "push", "--context", symLinkPath)...)
routeURL := helper.DetermineRouteURL(symLinkPath)
// Ping said URL
helper.HttpWaitFor(routeURL, "HTTP Booster", 90, 1)
// Delete the component
helper.CmdShouldPass("odo", append(args, "delete", "sb-jar-test", "-f", "--context", symLinkPath)...)
})
It("Should be able to deploy a wildfly war file using symlinks in some odo commands", func() {
helper.CopyExample(filepath.Join("binary", "java", "wildfly"), context)
helper.CmdShouldPass("odo", append(args, "create", "wildfly", "javaee-war-test", "--project",
project, "--binary", filepath.Join(symLinkPath, "ROOT.war"), "--context", symLinkPath)...)
// Create a URL
helper.CmdShouldPass("odo", "url", "create", "warfile", "--port", "8080", "--context", context)
helper.CmdShouldPass("odo", append(args, "push", "--context", context)...)
routeURL := helper.DetermineRouteURL(context)
// Ping said URL
helper.HttpWaitFor(routeURL, "Sample", 90, 1)
// Delete the component
helper.CmdShouldPass("odo", append(args, "delete", "javaee-war-test", "-f", "--context", context)...)
})
})
}