From 539df956373e28d615eafafc5de7664cdde190d8 Mon Sep 17 00:00:00 2001 From: kumarabd Date: Thu, 6 Aug 2020 22:21:26 +0530 Subject: [PATCH] fixed docker and result Signed-off-by: kumarabd --- smi-conformance/Dockerfile | 4 +- smi-conformance/test-gen/test_gen.go | 119 ++++++++++++++------------- 2 files changed, 66 insertions(+), 57 deletions(-) diff --git a/smi-conformance/Dockerfile b/smi-conformance/Dockerfile index eff2775..3e0b33a 100644 --- a/smi-conformance/Dockerfile +++ b/smi-conformance/Dockerfile @@ -14,8 +14,8 @@ FROM alpine:latest RUN apk --no-cache add ca-certificates && mkdir /home/test-yamls && mkdir /home/test-yamls/traffic-access && mkdir /home/test-yamls/traffic-spec && mkdir /home/test-yamls/traffic-split COPY --from=build-img /home/meshery/** /home/ COPY --from=build-img /go/src/github.com/layer5io/learn-layer5/smi-conformance/test-gen/test-yamls/traffic-access/** /home/test-yamls/traffic-access/ -COPY --from=build-img /go/src/github.com/layer5io/learn-layer5/smi-conformance/test-gen/test-yamls/test-split/** /home/test-yamls/traffic-split/ -COPY --from=build-img /go/src/github.com/layer5io/learn-layer5/smi-conformance/test-gen/test-yamls/test-spec/** /home/test-yamls/traffic-spec/ +COPY --from=build-img /go/src/github.com/layer5io/learn-layer5/smi-conformance/test-gen/test-yamls/traffic-split/** /home/test-yamls/traffic-split/ +COPY --from=build-img /go/src/github.com/layer5io/learn-layer5/smi-conformance/test-gen/test-yamls/traffic-spec/** /home/test-yamls/traffic-spec/ WORKDIR /home/ EXPOSE 10008 CMD ["sh","-c","./smi_conformance"] \ No newline at end of file diff --git a/smi-conformance/test-gen/test_gen.go b/smi-conformance/test-gen/test_gen.go index dc98a46..a0f8255 100644 --- a/smi-conformance/test-gen/test_gen.go +++ b/smi-conformance/test-gen/test_gen.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "testing" + "time" harness "github.com/kudobuilder/kuttl/pkg/apis/testharness/v1beta1" "github.com/kudobuilder/kuttl/pkg/report" @@ -29,70 +30,78 @@ type Results struct { } func RunTest(meshConfig ServiceMesh, annotations map[string]string) Results { - manifestDirs := []string{} - output := Results{} - results := &report.Testsuites{} - // Run all testCases - testToRun := "" - // Run only traffic-split - // testToRun := "traffic-split" + c := make(chan Results) + go func() { + manifestDirs := []string{} + results := &report.Testsuites{} + output := Results{} - startKIND := false - options := harness.TestSuite{} + // Run all testCases + testToRun := "" + // Run only traffic-split + // testToRun := "traffic-split" - args := []string{"./test-yamls/"} + startKIND := false + options := harness.TestSuite{} - options.TestDirs = args - options.Timeout = 30 - options.Parallel = 1 - options.TestDirs = manifestDirs - options.StartKIND = startKIND - options.SkipDelete = true + args := []string{"./test-yamls/"} - if options.KINDContext == "" { - options.KINDContext = harness.DefaultKINDContext - } - - if len(args) != 0 { options.TestDirs = args - } - - // annotations := make(map[string]string) - // Namespace Injection - // annotations["linkerd.io/inject"] = "enabled" - - serviceMeshConfObj := SMIConformance{ - SMObj: meshConfig, - } + options.Timeout = 30 + options.Parallel = 1 + options.TestDirs = manifestDirs + options.StartKIND = startKIND + options.SkipDelete = true + + if options.KINDContext == "" { + options.KINDContext = harness.DefaultKINDContext + } - testHandlers := make(map[string]map[string]test.CustomTest) - testHandlers["traffic-access"] = serviceMeshConfObj.TrafficAccessGetTests() - testHandlers["traffic-spec"] = serviceMeshConfObj.TrafficSpecGetTests() - testHandlers["traffic-split"] = serviceMeshConfObj.TrafficSplitGetTests() - - testutils.RunTests("kudo", testToRun, options.Parallel, func(t *testing.T) { - harness := test.Harness{ - TestSuite: options, - T: t, - SuiteCustomTests: testHandlers, - NamespaceAnnotations: annotations, + if len(args) != 0 { + options.TestDirs = args } - // Runs the test using the inCluster kubeConfig (runs only when the code is running inside the pod) - harness.InCluster = true - - s, _ := json.MarshalIndent(options, "", " ") - fmt.Printf("Running integration tests with following options:\n%s\n", string(s)) - results = harness.Run() - data, _ := json.Marshal(results) - // Results of the test - fmt.Printf("Results :\n%v\n", string(data)) - err := json.Unmarshal([]byte(data), &output) - if err != nil { - fmt.Printf("Unable to unmarshal results") + // annotations := make(map[string]string) + // Namespace Injection + // annotations["linkerd.io/inject"] = "enabled" + + serviceMeshConfObj := SMIConformance{ + SMObj: meshConfig, } - }) - return output + testHandlers := make(map[string]map[string]test.CustomTest) + testHandlers["traffic-access"] = serviceMeshConfObj.TrafficAccessGetTests() + testHandlers["traffic-spec"] = serviceMeshConfObj.TrafficSpecGetTests() + testHandlers["traffic-split"] = serviceMeshConfObj.TrafficSplitGetTests() + + testutils.RunTests("kudo", testToRun, options.Parallel, func(t *testing.T) { + harness := test.Harness{ + TestSuite: options, + T: t, + SuiteCustomTests: testHandlers, + NamespaceAnnotations: annotations, + } + + // Runs the test using the inCluster kubeConfig (runs only when the code is running inside the pod) + harness.InCluster = true + + s, _ := json.MarshalIndent(options, "", " ") + fmt.Printf("Running integration tests with following options:\n%s\n", string(s)) + results = harness.Run() + data, _ := json.Marshal(results) + // Results of the test + fmt.Printf("Results :\n%v\n", string(data)) + err := json.Unmarshal([]byte(data), &output) + if err != nil { + fmt.Printf("Unable to unmarshal results") + } + c <- output + time.Sleep(5 * time.Second) + }) + }() + select { + case x := <-c: + return x + } }