44 "encoding/json"
55 "fmt"
66 "testing"
7+ "time"
78
89 harness "github.com/kudobuilder/kuttl/pkg/apis/testharness/v1beta1"
910 "github.com/kudobuilder/kuttl/pkg/report"
@@ -29,70 +30,78 @@ type Results struct {
2930}
3031
3132func RunTest (meshConfig ServiceMesh , annotations map [string ]string ) Results {
32- manifestDirs := []string {}
33- output := Results {}
34- results := & report.Testsuites {}
3533
36- // Run all testCases
37- testToRun := ""
38- // Run only traffic-split
39- // testToRun := "traffic-split"
34+ c := make (chan Results )
35+ go func () {
36+ manifestDirs := []string {}
37+ results := & report.Testsuites {}
38+ output := Results {}
4039
41- startKIND := false
42- options := harness.TestSuite {}
40+ // Run all testCases
41+ testToRun := ""
42+ // Run only traffic-split
43+ // testToRun := "traffic-split"
4344
44- args := []string {"./test-yamls/" }
45+ startKIND := false
46+ options := harness.TestSuite {}
4547
46- options .TestDirs = args
47- options .Timeout = 30
48- options .Parallel = 1
49- options .TestDirs = manifestDirs
50- options .StartKIND = startKIND
51- options .SkipDelete = true
48+ args := []string {"./test-yamls/" }
5249
53- if options .KINDContext == "" {
54- options .KINDContext = harness .DefaultKINDContext
55- }
56-
57- if len (args ) != 0 {
5850 options .TestDirs = args
59- }
60-
61- // annotations := make(map[string]string)
62- // Namespace Injection
63- // annotations["linkerd.io/inject"] = "enabled"
64-
65- serviceMeshConfObj := SMIConformance {
66- SMObj : meshConfig ,
67- }
51+ options . Timeout = 30
52+ options . Parallel = 1
53+ options . TestDirs = manifestDirs
54+ options . StartKIND = startKIND
55+ options . SkipDelete = true
56+
57+ if options . KINDContext == "" {
58+ options . KINDContext = harness . DefaultKINDContext
59+ }
6860
69- testHandlers := make (map [string ]map [string ]test.CustomTest )
70- testHandlers ["traffic-access" ] = serviceMeshConfObj .TrafficAccessGetTests ()
71- testHandlers ["traffic-spec" ] = serviceMeshConfObj .TrafficSpecGetTests ()
72- testHandlers ["traffic-split" ] = serviceMeshConfObj .TrafficSplitGetTests ()
73-
74- testutils .RunTests ("kudo" , testToRun , options .Parallel , func (t * testing.T ) {
75- harness := test.Harness {
76- TestSuite : options ,
77- T : t ,
78- SuiteCustomTests : testHandlers ,
79- NamespaceAnnotations : annotations ,
61+ if len (args ) != 0 {
62+ options .TestDirs = args
8063 }
8164
82- // Runs the test using the inCluster kubeConfig (runs only when the code is running inside the pod)
83- harness .InCluster = true
84-
85- s , _ := json .MarshalIndent (options , "" , " " )
86- fmt .Printf ("Running integration tests with following options:\n %s\n " , string (s ))
87- results = harness .Run ()
88- data , _ := json .Marshal (results )
89- // Results of the test
90- fmt .Printf ("Results :\n %v\n " , string (data ))
91- err := json .Unmarshal ([]byte (data ), & output )
92- if err != nil {
93- fmt .Printf ("Unable to unmarshal results" )
65+ // annotations := make(map[string]string)
66+ // Namespace Injection
67+ // annotations["linkerd.io/inject"] = "enabled"
68+
69+ serviceMeshConfObj := SMIConformance {
70+ SMObj : meshConfig ,
9471 }
95- })
9672
97- return output
73+ testHandlers := make (map [string ]map [string ]test.CustomTest )
74+ testHandlers ["traffic-access" ] = serviceMeshConfObj .TrafficAccessGetTests ()
75+ testHandlers ["traffic-spec" ] = serviceMeshConfObj .TrafficSpecGetTests ()
76+ testHandlers ["traffic-split" ] = serviceMeshConfObj .TrafficSplitGetTests ()
77+
78+ testutils .RunTests ("kudo" , testToRun , options .Parallel , func (t * testing.T ) {
79+ harness := test.Harness {
80+ TestSuite : options ,
81+ T : t ,
82+ SuiteCustomTests : testHandlers ,
83+ NamespaceAnnotations : annotations ,
84+ }
85+
86+ // Runs the test using the inCluster kubeConfig (runs only when the code is running inside the pod)
87+ harness .InCluster = true
88+
89+ s , _ := json .MarshalIndent (options , "" , " " )
90+ fmt .Printf ("Running integration tests with following options:\n %s\n " , string (s ))
91+ results = harness .Run ()
92+ data , _ := json .Marshal (results )
93+ // Results of the test
94+ fmt .Printf ("Results :\n %v\n " , string (data ))
95+ err := json .Unmarshal ([]byte (data ), & output )
96+ if err != nil {
97+ fmt .Printf ("Unable to unmarshal results" )
98+ }
99+ c <- output
100+ time .Sleep (5 * time .Second )
101+ })
102+ }()
103+ select {
104+ case x := <- c :
105+ return x
106+ }
98107}
0 commit comments