diff --git a/.build/build.yaml b/.build/build.yaml index 1c7e53083..337dabc44 100644 --- a/.build/build.yaml +++ b/.build/build.yaml @@ -38,6 +38,9 @@ spec: workspace: source - name: gotest + params: + - name: verbose + value: "true" taskRef: name: katanomi-gotest kind: ClusterTask diff --git a/errors/convert_response_error_test.go b/errors/convert_response_error_test.go index e4af1e0b4..17a07c569 100644 --- a/errors/convert_response_error_test.go +++ b/errors/convert_response_error_test.go @@ -23,7 +23,7 @@ import ( "k8s.io/apimachinery/pkg/api/errors" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/errors/setup_test.go b/errors/setup_test.go index 14b378160..a51924cb3 100644 --- a/errors/setup_test.go +++ b/errors/setup_test.go @@ -19,7 +19,7 @@ package errors import ( "testing" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/examples/sample-controller/apis/test/v1alpha1/suite_test.go b/examples/sample-controller/apis/test/v1alpha1/suite_test.go index ac8ed2f3b..280f42679 100644 --- a/examples/sample-controller/apis/test/v1alpha1/suite_test.go +++ b/examples/sample-controller/apis/test/v1alpha1/suite_test.go @@ -19,10 +19,9 @@ package v1alpha1 import ( "testing" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "sigs.k8s.io/controller-runtime/pkg/envtest/printer" - //+kubebuilder:scaffold:imports + // +kubebuilder:scaffold:imports ) // These tests use Ginkgo (BDD-style Go testing framework). Refer to @@ -31,7 +30,5 @@ import ( func TestV1alpha1(t *testing.T) { RegisterFailHandler(Fail) - RunSpecsWithDefaultAndCustomReporters(t, - "pkg/apis/test/v1alpha1", - []Reporter{printer.NewlineReporter{}}) + RunSpecs(t, "pkg/apis/test/v1alpha1") } diff --git a/examples/sample-e2e/another/another.go b/examples/sample-e2e/another/another.go index 5e1a407a2..e1942d4d8 100644 --- a/examples/sample-e2e/another/another.go +++ b/examples/sample-e2e/another/another.go @@ -21,7 +21,7 @@ package another import ( . "github.com/katanomi/pkg/testing/framework" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/examples/sample-e2e/testcase_test.go b/examples/sample-e2e/testcase_test.go index 672307729..d408322f6 100644 --- a/examples/sample-e2e/testcase_test.go +++ b/examples/sample-e2e/testcase_test.go @@ -21,7 +21,7 @@ package e2e import ( . "github.com/katanomi/pkg/testing/framework" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/go.mod b/go.mod index 46fa62d6c..452c8ef4a 100644 --- a/go.mod +++ b/go.mod @@ -18,8 +18,8 @@ require ( github.com/google/go-cmp v0.5.7 github.com/googleapis/gnostic v0.5.3 // indirect github.com/jarcoal/httpmock v1.0.8 - github.com/onsi/ginkgo v1.16.5 - github.com/onsi/gomega v1.16.0 + github.com/onsi/ginkgo/v2 v2.1.4 + github.com/onsi/gomega v1.19.0 github.com/opencontainers/image-spec v1.0.2 github.com/opentracing/opentracing-go v1.1.0 github.com/prometheus/client_golang v1.11.0 @@ -52,7 +52,9 @@ require ( go.opentelemetry.io/otel/trace v1.2.0 ) -require golang.org/x/net v0.0.0-20210917221730-978cfadd31cf +require golang.org/x/net v0.0.0-20220225172249-27dd8689420f + +require github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 // indirect require ( contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect @@ -91,7 +93,6 @@ require ( github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect - github.com/nxadm/tail v1.4.8 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/openzipkin/zipkin-go v0.4.0 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -107,8 +108,8 @@ require ( go.uber.org/multierr v1.6.0 // indirect golang.org/x/crypto v0.0.0-20210920023735-84f357641f63 // indirect golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 // indirect - golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect - golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect + golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect + golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect google.golang.org/api v0.36.0 // indirect @@ -118,7 +119,6 @@ require ( google.golang.org/protobuf v1.27.1 // indirect gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect k8s.io/apiextensions-apiserver v0.20.7 // indirect diff --git a/go.sum b/go.sum index 6eec1d28e..dddd59a03 100644 --- a/go.sum +++ b/go.sum @@ -93,7 +93,6 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= -github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= @@ -108,7 +107,6 @@ github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QH github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.3.0 h1:t/LhUZLVitR1Ow2YOnduCsavhwFUklBMoGVYUCqmCqk= github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -145,6 +143,7 @@ github.com/dgryski/go-gk v0.0.0-20140819190930-201884a44051/go.mod h1:qm+vckxRlD github.com/dgryski/go-gk v0.0.0-20200319235926-a69029f61654/go.mod h1:qm+vckxRlDt0aOla0RYJJVeqHZlWfOm2UIxHaqPB46E= github.com/dgryski/go-lttb v0.0.0-20180810165845-318fcdf10a77/go.mod h1:Va5MyIzkU0rAM92tn3hb3Anb7oz7KcnixF49+2wOMe4= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 h1:cenwrSVm+Z7QLSV/BsnenAOcDXdX4cMv4wP0B/5QbPg= github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -154,9 +153,9 @@ github.com/eapache/go-resiliency v1.2.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5m github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= +github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153 h1:yUdfgN0XgIJw7foRItutHYUIhlcKzcSf5vDpdhQAKTc= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= -github.com/emicklei/go-restful v2.9.5+incompatible h1:spTtZBk5DYEvbxMVutUuTyh1Ao2r4iyvLdACqsl/Ljk= github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful-openapi/v2 v2.3.0 h1:tDgSCzQrkk4N+Isos0zGBYX/GTINjmQuP9BvITbEe38= github.com/emicklei/go-restful-openapi/v2 v2.3.0/go.mod h1:bs67E3SEVgSmB3qDuRLqpS0NcpheqtsCCMhW2/jml1E= @@ -512,14 +511,17 @@ github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.1.4 h1:GNapqRSid3zijZ9H77KrgVG4/8KqiyRsxcSxe+7ApXY= +github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c= github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw= +github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= @@ -811,8 +813,9 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20210917221730-978cfadd31cf h1:R150MpwJIv1MpS0N/pc+NhTM8ajzvlmxlY5OYsrevXQ= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -896,10 +899,12 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -979,8 +984,8 @@ golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/parallel/task_test.go b/parallel/task_test.go index 89a3fc601..049e2d25e 100644 --- a/parallel/task_test.go +++ b/parallel/task_test.go @@ -28,8 +28,7 @@ import ( "go.uber.org/zap" apierrors "k8s.io/apimachinery/pkg/util/errors" - . "github.com/onsi/ginkgo" - "github.com/onsi/ginkgo/reporters" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -51,8 +50,7 @@ func (e *executeFlag) get() bool { func TestParallelTask(t *testing.T) { RegisterFailHandler(Fail) - junitReporter := reporters.NewJUnitReporter("parallel.xml") - RunSpecsWithDefaultAndCustomReporters(t, "pkg/parallel", []Reporter{junitReporter}) + RunSpecs(t, "pkg/parallel") } func generateTask(index int, sleep time.Duration, err error, excuted *executeFlag) (task parallel.Task) { @@ -188,10 +186,10 @@ var _ = Describe("P().Do().Wait()", func() { Expect(errs).To(BeEquivalentTo(context.DeadlineExceeded)) fmt.Printf("%v,%v,%v,", t1Excuted.get(), t2Excuted.get(), t3Excuted.get()) - //up to now, task is not support cancel - //Expect(t1Excuted.executed).To(BeFalse()) - //Expect(t2Excuted.executed).To(BeFalse()) - //Expect(t3Excuted.executed).To(BeFalse()) + // up to now, task is not support cancel + // Expect(t1Excuted.executed).To(BeFalse()) + // Expect(t2Excuted.executed).To(BeFalse()) + // Expect(t3Excuted.executed).To(BeFalse()) Expect(elapsed < 1 && elapsed > 0.1).To(BeTrue()) Expect(len(res)).To(BeEquivalentTo(0)) diff --git a/plugin/route/options_test.go b/plugin/route/options_test.go index c59d80307..ec7cb9c05 100644 --- a/plugin/route/options_test.go +++ b/plugin/route/options_test.go @@ -21,17 +21,13 @@ import ( "testing" metav1alpha1 "github.com/katanomi/pkg/apis/meta/v1alpha1" - "sigs.k8s.io/controller-runtime/pkg/envtest/printer" - - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) func TestHandleSortQuery(t *testing.T) { RegisterFailHandler(Fail) - RunSpecsWithDefaultAndCustomReporters(t, - "test for get sort params", - []Reporter{printer.NewlineReporter{}}) + RunSpecs(t, "test for get sort params") } var _ = Describe("test for get sort params", func() { diff --git a/sharedmain/sharedmain_suite_test.go b/sharedmain/sharedmain_suite_test.go index fe8e56cfb..c92fcbb44 100644 --- a/sharedmain/sharedmain_suite_test.go +++ b/sharedmain/sharedmain_suite_test.go @@ -19,7 +19,7 @@ package sharedmain_test import ( "testing" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/sharedmain/sharedmain_test.go b/sharedmain/sharedmain_test.go index 02ce8c568..5b4ba3c32 100644 --- a/sharedmain/sharedmain_test.go +++ b/sharedmain/sharedmain_test.go @@ -18,7 +18,7 @@ package sharedmain_test import ( "github.com/katanomi/pkg/sharedmain" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/testing/framework/README.md b/testing/framework/README.md index 47896ba32..7f52d1942 100644 --- a/testing/framework/README.md +++ b/testing/framework/README.md @@ -62,7 +62,7 @@ package another import ( . "github.com/katanomi/pkg/testing/framework" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/testing/framework/client.go b/testing/framework/client.go new file mode 100644 index 000000000..ccde23a2c --- /dev/null +++ b/testing/framework/client.go @@ -0,0 +1,22 @@ +package framework + +import ( + "encoding/base64" + "encoding/json" + + "github.com/go-resty/resty/v2" + "github.com/katanomi/pkg/plugin/client" +) + +func RequestWrapAuthMeta(req *resty.Request, auth client.Auth, meta client.Meta) *resty.Request { + if req == nil { + return nil + } + + req.SetHeader(client.PluginAuthHeader, string(auth.Type)) + authData, _ := json.Marshal(auth.Secret) + req.SetHeader(client.PluginSecretHeader, base64.StdEncoding.EncodeToString(authData)) + + client.MetaOpts(meta)(req) + return req +} diff --git a/testing/framework/condition.go b/testing/framework/condition.go new file mode 100644 index 000000000..d4cbe8de4 --- /dev/null +++ b/testing/framework/condition.go @@ -0,0 +1,170 @@ +/* +Copyright 2022 The Katanomi Authors. + +Licensed 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 framework + +import ( + "fmt" + "time" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/wait" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +var ( + skipWhenConditionMismatch = GetDefaultEnv("SKIP_WHEN_CONDITION_MISMATCH", "true") +) + +type ConditionFunc func(testCtx *TestContext) error + +func (c ConditionFunc) Condition(testCtx *TestContext) error { + return c(testCtx) +} + +type Condition interface { + Condition(testCtx *TestContext) error +} + +func NewTestNamespace(nsName string) *TestNamespaceCondition { + return &TestNamespaceCondition{nsName: nsName} +} + +type TestNamespaceCondition struct { + nsName string +} + +func (t *TestNamespaceCondition) Condition(testCtx *TestContext) error { + var ( + clt = testCtx.Client + ctx = testCtx.Context + err error + ) + + ns := v1.Namespace{} + key := types.NamespacedName{Name: t.nsName} + err = clt.Get(ctx, key, &ns) + if client.IgnoreNotFound(err) != nil { + return err + } + + if ns.Name != "" { + if err = clt.Delete(ctx, &ns); err != nil { + return err + } + MustRollback(testCtx, &ns) + } + + ns = v1.Namespace{ + ObjectMeta: metav1.ObjectMeta{Name: t.nsName}, + } + if err = clt.Create(ctx, &ns); err != nil { + return err + } + + DeferCleanup(func() error { + MustRollback(testCtx, &ns) + return nil + }) + return nil +} + +func NewReconcileCondition(obj client.Object, f func(obj client.Object) bool) *ReconcileCondition { + c := &ReconcileCondition{ + Poller: &Poller{}, + obj: obj, + objCheckFun: f, + } + + return c +} + +type ReconcileCondition struct { + *Poller + obj client.Object + objCheckFun func(obj client.Object) bool +} + +func (n *ReconcileCondition) WithPoller(interval, timeout time.Duration) *ReconcileCondition { + n.Interval = interval + n.Timeout = timeout + + return n +} + +func (n *ReconcileCondition) Condition(testCtx *TestContext) error { + var ( + clt = testCtx.Client + ctx = testCtx.Context + err error + ) + + n.obj.SetNamespace(testCtx.Namespace) + + By(fmt.Sprintf("try to create %s resource", n.obj.GetName())) + err = clt.Create(ctx, n.obj) + if err != nil && !errors.IsAlreadyExists(err) { + return err + } + + if err == nil { + defer func() { + MustRollback(testCtx, n.obj) + }() + } + + By(fmt.Sprintf("wait for %s to be ready", n.obj.GetName())) + brokerKey := types.NamespacedName{Namespace: n.obj.GetNamespace(), Name: n.obj.GetName()} + interval, timeout := n.Settings() + return wait.PollImmediate(interval, timeout, func() (bool, error) { + if err = clt.Get(ctx, brokerKey, n.obj); err != nil { + if errors.IsNotFound(err) { + return false, nil + } else { + return false, err + } + } + if n.objCheckFun != nil && !n.objCheckFun(n.obj) { + return false, nil + } + return true, nil + }) +} + +func MustRollback(testCtx *TestContext, obj client.Object, opts ...client.DeleteOption) { + Expect(testCtx.Client).NotTo(BeNil()) + Expect(testCtx.Context).NotTo(BeNil()) + Expect(obj).NotTo(BeNil()) + + err := testCtx.Client.Delete(testCtx.Context, obj, opts...) + Expect(err).To(Succeed()) + + WaitRollback(testCtx, obj) +} + +func WaitRollback(testCtx *TestContext, obj client.Object) { + key := types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()} + Eventually(func(g Gomega) error { + err := testCtx.Client.Get(testCtx.Context, key, obj) + g.Expect(errors.IsNotFound(err)).To(BeTrue()) + return nil + }).WithPolling(time.Second).WithTimeout(time.Minute).Should(Succeed()) +} diff --git a/testing/framework/config.go b/testing/framework/config.go new file mode 100644 index 000000000..0c635db85 --- /dev/null +++ b/testing/framework/config.go @@ -0,0 +1,63 @@ +package framework + +import ( + "context" + "strings" + "sync" + + v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +var ( + e2eConfigNs = GetDefaultEnv("E2E_CONFIG_NAMESPACE", "katanomi-e2e") + e2eConfigNamePrefix = GetDefaultEnv("E2E_CONFIG_NAME_PREFIX", "e2e-config") +) + +func GetE2EConfig(cmName string) *TestConfig { + name := []string{strings.TrimSuffix(e2eConfigNamePrefix, "-"), cmName} + return &TestConfig{ + Namespace: e2eConfigNs, + Name: strings.Join(name, "-"), + } +} + +type ConfigGetter interface { + Get(ctx context.Context, clt client.Client, configKey string) (string, error) +} + +type TestConfig struct { + Namespace string + Name string + + lock sync.RWMutex + once sync.Once + + data string +} + +func (c *TestConfig) initData(ctx context.Context, clt client.Client) error { + var err error + c.once.Do(func() { + key := types.NamespacedName{Namespace: c.Namespace, Name: c.Name} + cm := &v1.ConfigMap{} + if err = clt.Get(ctx, key, cm); err != nil { + return + } + if cm.Data != nil { + c.data = cm.Data["config"] + } + }) + return err +} + +func (c *TestConfig) Get(ctx context.Context, clt client.Client) (string, error) { + if err := c.initData(ctx, clt); err != nil { + return "", err + } + + c.lock.RLock() + defer c.lock.RUnlock() + return c.data, nil +} diff --git a/testing/framework/context.go b/testing/framework/context.go index 6fe132c84..3886be050 100644 --- a/testing/framework/context.go +++ b/testing/framework/context.go @@ -18,21 +18,67 @@ package framework import ( "context" + "strings" "go.uber.org/zap" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/rand" "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" ) // TestContext a test context type TestContext struct { Context context.Context Config *rest.Config - Opts Options + Client client.Client + *zap.SugaredLogger + Namespace string + Scheme *runtime.Scheme } +type TestContextOption interface { + Init(testContext *TestContext) + Setup(testContext *TestContext) error +} + +type TestContextEmptyOption struct{} + +func (b TestContextEmptyOption) Init(_ *TestContext) {} +func (b TestContextEmptyOption) Setup(_ *TestContext) error { + return nil +} + +func NewNamespaceOption(ns string) TestContextOption { + return &NamespaceOption{ns: ns} +} + +type NamespaceOption struct { + ns string + + TestContextEmptyOption +} + +func (n NamespaceOption) Init(testContext *TestContext) { + testContext.Namespace = n.ns +} + +func NewNamespacePrefixOption(prefix string) TestContextOption { + return &NamespacePrefixOption{prefix: prefix} +} + +type NamespacePrefixOption struct { + prefix string + + TestContextEmptyOption +} + +func (n NamespacePrefixOption) Init(testContext *TestContext) { + testContext.Namespace = strings.TrimSuffix(n.prefix, "-") + "-" + rand.String(5) +} + // TestFunction function used as describe -type TestFunction func(TestContext) +type TestFunction func(*TestContext) diff --git a/testing/framework/framework.go b/testing/framework/framework.go index 17bd2ffe4..013fa456e 100644 --- a/testing/framework/framework.go +++ b/testing/framework/framework.go @@ -25,9 +25,8 @@ import ( "testing" "time" - "github.com/onsi/ginkgo" - "github.com/onsi/ginkgo/reporters" - "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" "go.uber.org/zap" "go.uber.org/zap/zapcore" "k8s.io/apimachinery/pkg/runtime" @@ -68,13 +67,12 @@ func New(name string) *Framework { // init is a do once initialization function to startup any necessary data func (f *Framework) init() { f.Once.Do(func() { - ginkgo.By("Framework.Init") f.Context = context.TODO() cfg := ctrl.GetConfigOrDie() f.Context = injection.WithConfig(f.Context, cfg) f.Config = cfg - logger, err := zap.NewDevelopment(zap.ErrorOutput(zapcore.AddSync(ginkgo.GinkgoWriter))) + logger, err := zap.NewDevelopment(zap.ErrorOutput(zapcore.AddSync(GinkgoWriter))) if err != nil { panic(err) } @@ -91,10 +89,8 @@ func (f *Framework) MRun(m *testing.M) { // Run start tests func (f *Framework) Run(t *testing.T) { - gomega.RegisterFailHandler(ginkgo.Fail) - var r []ginkgo.Reporter - r = append(r, reporters.NewJUnitReporter(f.Name+".xml")) - ginkgo.RunSpecsWithDefaultAndCustomReporters(t, f.Name, r) + RegisterFailHandler(Fail) + RunSpecs(t, f.Name) } // WithScheme adds a scheme object to the framework @@ -105,28 +101,28 @@ func (f *Framework) WithScheme(scheme *runtime.Scheme) *Framework { // SynchronizedBeforeSuite basic before suite initialization func (f *Framework) SynchronizedBeforeSuite(initFunc func()) *Framework { - ginkgo.SynchronizedBeforeSuite(func() []byte { - ginkgo.By("Setup") + SynchronizedBeforeSuite(func() []byte { + By("Setup") if initFunc != nil { - ginkgo.By("Setup.Func") + By("Setup.Func") initFunc() } return nil }, func(_ []byte) { // no-op for now - }, DurationToFloat(f.InitTimeout)) + }) return f } // SynchronizedAfterSuite destroys the whole environment func (f *Framework) SynchronizedAfterSuite(destroyFunc func()) *Framework { - ginkgo.SynchronizedAfterSuite(func() {}, func() { - ginkgo.By("Teardown") + SynchronizedAfterSuite(func() {}, func() { + By("Teardown") if destroyFunc != nil { - ginkgo.By("Teardown.Func") + By("Teardown.Func") destroyFunc() } - }, DurationToFloat(f.InitTimeout)) + }) return f } diff --git a/testing/framework/params.go b/testing/framework/params.go new file mode 100644 index 000000000..fb90474f0 --- /dev/null +++ b/testing/framework/params.go @@ -0,0 +1,26 @@ +/* +Copyright 2022 The Katanomi Authors. + +Licensed 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 framework + +import "os" + +func GetDefaultEnv(key string, defaultValue string) string { + if value := os.Getenv(key); value != "" { + return value + } + return defaultValue +} diff --git a/testing/framework/poller.go b/testing/framework/poller.go new file mode 100644 index 000000000..bad64b12a --- /dev/null +++ b/testing/framework/poller.go @@ -0,0 +1,42 @@ +/* +Copyright 2022 The Katanomi Authors. + +Licensed 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 framework + +import "time" + +type Poller struct { + Interval time.Duration + Timeout time.Duration +} + +func (p Poller) Settings() (interval, timeout time.Duration) { + interval = p.Interval + timeout = p.Timeout + if p.Interval == 0 { + interval = 200 * time.Millisecond + } + + if p.Timeout == 0 { + timeout = 2 * time.Second + } + + if interval > timeout { + timeout = interval + } + + return +} diff --git a/testing/framework/port_forward.go b/testing/framework/port_forward.go new file mode 100644 index 000000000..e38c1b2e4 --- /dev/null +++ b/testing/framework/port_forward.go @@ -0,0 +1,141 @@ +/* +Copyright 2022 The Katanomi Authors. + +Licensed 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 framework + +import ( + "errors" + "fmt" + "net/http" + "os" + + "github.com/go-resty/resty/v2" + v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/types" + clientset "k8s.io/client-go/kubernetes" + "k8s.io/client-go/tools/portforward" + "k8s.io/client-go/transport/spdy" + client "sigs.k8s.io/controller-runtime/pkg/client" +) + +func NewServicePortForward(ns string, serviceName string) *ServicePortForward { + return &ServicePortForward{ + Namespace: ns, + ServiceName: serviceName, + } +} + +type ServicePortForward struct { + Namespace string + ServiceName string + ServicePortFilter func(ports []v1.ServicePort) int32 + + stopChan chan struct{} +} + +func (s *ServicePortForward) Close() { + if s.stopChan != nil { + close(s.stopChan) + } +} + +func (s *ServicePortForward) getServicePort(ports []v1.ServicePort) int32 { + if s.ServicePortFilter != nil { + return s.ServicePortFilter(ports) + } + + if len(ports) > 0 { + return int32(ports[0].TargetPort.IntValue()) + } + + return 0 +} + +func (s *ServicePortForward) Forward(testCtx *TestContext) (restyClient *resty.Client, err error) { + ctx := testCtx.Context + clt := testCtx.Client + logger := testCtx.With("Namespace", s.Namespace, "ServiceName", s.ServiceName) + + service := &v1.Service{} + serviceKey := types.NamespacedName{Namespace: s.Namespace, Name: s.ServiceName} + if err = clt.Get(ctx, serviceKey, service); err != nil { + logger.Errorw("get service error", "err", err) + return nil, err + } + + servicePort := s.getServicePort(service.Spec.Ports) + + podList := &v1.PodList{} + podLabel := client.MatchingLabels(service.Spec.Selector) + if err = clt.List(ctx, podList, podLabel, client.InNamespace(s.Namespace)); err != nil { + logger.Errorw("get pod list error", "err", err) + return nil, err + } + + if len(podList.Items) == 0 { + err = errors.New("no pods to choose from") + logger.Errorw("get service pod error", "err", err) + return nil, err + } + + pod := podList.Items[0] + return s.forward(testCtx, pod.GetName(), servicePort) +} + +func (s *ServicePortForward) forward(testCtx *TestContext, podName string, forwardPort int32) (restyClient *resty.Client, err error) { + var ( + config = testCtx.Config + logger = testCtx.With("Namespace", s.Namespace, "podName", podName) + ) + clientSet := clientset.NewForConfigOrDie(config) + req := clientSet.CoreV1().RESTClient().Post().Namespace(s.Namespace). + Resource("pods").Name(podName).SubResource("portforward") + + transport, upgrader, err := spdy.RoundTripperFor(config) + if err != nil { + return nil, err + } + + s.stopChan = make(chan struct{}) + readyChan := make(chan struct{}) + + dialer := spdy.NewDialer(upgrader, &http.Client{Transport: transport}, http.MethodPost, req.URL()) + ports := []string{fmt.Sprintf(":%d", forwardPort)} + pf, err := portforward.New(dialer, ports, s.stopChan, readyChan, os.Stdout, os.Stderr) + if err != nil { + logger.Errorw("forward port error", "err", err) + return nil, err + } + + go func() { + if forwardErr := pf.ForwardPorts(); forwardErr != nil { + logger.Errorw("forwardPorts returned with error", "err", forwardErr) + } + }() + + <-pf.Ready + + // ignore the error because portforward should be ready now + list, _ := pf.GetPorts() + if len(list) == 0 || list[0].Local == 0 { + err = errors.New("get local port error") + logger.Errorw("get local port error", "portList", list) + return nil, err + } + + restyClient = resty.New().SetHostURL(fmt.Sprintf("http://localhost:%d", list[0].Local)) + return restyClient, err +} diff --git a/testing/framework/reflect.go b/testing/framework/reflect.go new file mode 100644 index 000000000..e1381d153 --- /dev/null +++ b/testing/framework/reflect.go @@ -0,0 +1,27 @@ +/* +Copyright 2022 The Katanomi Authors. + +Licensed 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 framework + +import "reflect" + +func getType(myvar interface{}) string { + if t := reflect.TypeOf(myvar); t.Kind() == reflect.Ptr { + return "*" + t.Elem().Name() + } else { + return t.Name() + } +} diff --git a/testing/framework/resource.go b/testing/framework/resource.go new file mode 100644 index 000000000..bca64e961 --- /dev/null +++ b/testing/framework/resource.go @@ -0,0 +1,36 @@ +/* +Copyright 2022 The Katanomi Authors. + +Licensed 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 framework + +import ( + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func NewTestConfigMap(name, namespace string, data map[string]string) *v1.ConfigMap { + return &v1.ConfigMap{ + TypeMeta: metav1.TypeMeta{ + Kind: "ConfigMap", + APIVersion: "v1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + }, + Data: data, + } +} diff --git a/testing/framework/testcase.go b/testing/framework/testcase.go index 34ebf74c4..d5ee75576 100644 --- a/testing/framework/testcase.go +++ b/testing/framework/testcase.go @@ -19,7 +19,10 @@ package framework import ( "fmt" - "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/util/rand" + "sigs.k8s.io/controller-runtime/pkg/client" ) // TestCasePriority priority for the testcase @@ -42,10 +45,20 @@ type TestCaseScope string const ( // ClusterScoped cluster test case scope ClusterScoped TestCaseScope = "Cluster" - //NamespaceScoped test case scoped for a namespace + // NamespaceScoped test case scoped for a Namespace NamespaceScoped TestCaseScope = "Namespaced" ) +// TestCaseLabel label for test case +type TestCaseLabel = string + +const ( + ControllerLabel TestCaseLabel = "controller" + WebhookLabel TestCaseLabel = "webhook" + WebServiceLabel TestCaseLabel = "webservice" + CliLabel TestCaseLabel = "cli" +) + // Options options for TestCase type Options struct { // Name oof the test case @@ -54,6 +67,12 @@ type Options struct { Priority TestCasePriority // Scope defines what kind of permissions this test case needs Scope TestCaseScope + // Labels used to filter test cases when executing testing + Labels []string + // Condition function checked before testing + Conditions []Condition + + TestContextOptions []TestContextOption } func (o Options) defaultVals() Options { @@ -66,6 +85,33 @@ func (o Options) defaultVals() Options { return o } +func (o Options) appendLabels(labels ...string) Options { + m := make(map[string]struct{}, len(o.Labels)) + for _, label := range o.Labels { + m[label] = struct{}{} + } + for _, newLabel := range labels { + if _, exist := m[newLabel]; exist { + continue + } + m[newLabel] = struct{}{} + o.Labels = append(o.Labels, newLabel) + } + return o +} + +func (o Options) checkCondition(testCtx *TestContext) error { + for _, condition := range o.Conditions { + if condition == nil { + continue + } + if err := condition.Condition(testCtx); err != nil { + return fmt.Errorf("condition %s check failed: %w", getType(condition), err) + } + } + return nil +} + // TestCaseBuilder builder for TestCases // helps provide methods to construct type TestCaseBuilder struct { @@ -113,6 +159,22 @@ func (b *TestCaseBuilder) WithPriority(prior TestCasePriority) *TestCaseBuilder return b } +// WithLabels sets labels +func (b *TestCaseBuilder) WithLabels(labels ...string) *TestCaseBuilder { + b.opts = b.opts.appendLabels(labels...) + return b +} + +func (b *TestCaseBuilder) WithCondition(funcs ...Condition) *TestCaseBuilder { + b.opts.Conditions = append(b.opts.Conditions, funcs...) + return b +} + +func (b *TestCaseBuilder) WithTestContextOptions(options ...TestContextOption) *TestCaseBuilder { + b.opts.TestContextOptions = append(b.opts.TestContextOptions, options...) + return b +} + // Namespaced set the scope of the testcase as namespaced func (b *TestCaseBuilder) Namespaced() *TestCaseBuilder { b.opts.Scope = NamespaceScoped @@ -145,18 +207,70 @@ func (b *TestCaseBuilder) P3() *TestCaseBuilder { return b.WithPriority(P3) } -// Do builds and returns the test case -func (b *TestCaseBuilder) Do() bool { - ctx := TestContext{ - Opts: b.opts, +func (b *TestCaseBuilder) setupTestContext(ctx *TestContext) (err error) { + err = NewTestNamespace(ctx.Namespace).Condition(ctx) + Expect(err).To(Succeed()) + + for _, option := range b.opts.TestContextOptions { + if err = option.Setup(ctx); err != nil { + return err + } + } + return nil +} + +func (b *TestCaseBuilder) initTestContext(ctx *TestContext) { + ctx.Context = fmw.Context + ctx.Config = fmw.Config + ctx.SugaredLogger = fmw.SugaredLogger.Named(b.caseName()) + ctx.Scheme = fmw.Scheme + + for _, option := range b.opts.TestContextOptions { + option.Init(ctx) + } + + if ctx.Namespace == "" { + ctx.Namespace = "e2e-test-ns" + rand.String(5) + } + + if ctx.Client == nil { + c, err := client.New(ctx.Config, client.Options{Scheme: ctx.Scheme}) + Expect(err).To(Succeed()) + ctx.Client = c } - fullName := fmt.Sprintf("[P%d][%s][%s]", b.opts.Priority, b.opts.Scope, b.opts.Name) - return ginkgo.Describe(fullName, func() { - ginkgo.By("Initializing " + fullName) - ctx.Config = fmw.Config - ctx.Context = fmw.Context - ctx.SugaredLogger = fmw.SugaredLogger.Named(fullName) - ctx.Scheme = fmw.Scheme - b.testFunc(ctx) +} + +func (b *TestCaseBuilder) caseName() string { + return fmt.Sprintf("[P%d][%s][%s]", b.opts.Priority, b.opts.Scope, b.opts.Name) +} + +// Do build and return the test case +func (b *TestCaseBuilder) Do() bool { + fullName := b.caseName() + return Describe(fullName, Ordered, Labels(b.opts.Labels), func() { + var ctx = &TestContext{} + + BeforeAll(func() { + b.initTestContext(ctx) + err := b.setupTestContext(ctx) + Expect(err).To(Succeed()) + + err = b.opts.checkCondition(ctx) + if err != nil && skipWhenConditionMismatch == "true" { + skipMsg := fmt.Sprintf("Skip test case, name: %s, reason: %s", fullName, err.Error()) + Skip(skipMsg) + } else { + Expect(err).To(Succeed()) + } + }) + + if b.testFunc != nil { + b.testFunc(ctx) + } }) } + +func (b *TestCaseBuilder) DoFunc(f TestFunction) bool { + b.testFunc = f + return b.Do() +} diff --git a/testing/kubernetes_test.go b/testing/kubernetes_test.go index 55cb156ac..78a189532 100644 --- a/testing/kubernetes_test.go +++ b/testing/kubernetes_test.go @@ -20,7 +20,7 @@ import ( "context" "fmt" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" diff --git a/testing/loadfile.go b/testing/loadfile.go index ae68fdd92..e55f05606 100644 --- a/testing/loadfile.go +++ b/testing/loadfile.go @@ -17,6 +17,7 @@ limitations under the License. package testing import ( + "fmt" "io/ioutil" corev1 "k8s.io/api/core/v1" @@ -36,6 +37,14 @@ func LoadYAML(file string, obj interface{}) (err error) { return } +// MustLoadYaml loads yaml or panics if the parse fails. +func MustLoadYaml(file string, obj interface{}) { + err := LoadYAML(file, obj) + if err != nil { + panic(fmt.Sprintf("load yaml file failed, file path: %s", file)) + } +} + // LoadObjectOrDie loads object from yaml and returns func LoadObjectOrDie(g *WithT, file string, obj metav1.Object, patches ...func(metav1.Object)) metav1.Object { g.Expect(LoadYAML(file, obj)).To(Succeed(), "could not load file into metav1.Object") diff --git a/testing/testing_suite_test.go b/testing/testing_suite_test.go index 018b8ff2f..900c33ab0 100644 --- a/testing/testing_suite_test.go +++ b/testing/testing_suite_test.go @@ -19,7 +19,7 @@ package testing_test import ( "testing" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/tracing/filter_test.go b/tracing/filter_test.go index 385e2d205..793a4608d 100644 --- a/tracing/filter_test.go +++ b/tracing/filter_test.go @@ -22,7 +22,7 @@ import ( "net/http/httptest" "github.com/emicklei/go-restful/v3" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/propagation" diff --git a/tracing/options_test.go b/tracing/options_test.go index dda0759d6..19f764e82 100644 --- a/tracing/options_test.go +++ b/tracing/options_test.go @@ -19,7 +19,7 @@ package tracing import ( "context" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/propagation" diff --git a/tracing/setup_test.go b/tracing/setup_test.go index 9535cf259..3a6a9e51a 100644 --- a/tracing/setup_test.go +++ b/tracing/setup_test.go @@ -22,7 +22,7 @@ import ( "sync/atomic" "time" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "go.uber.org/zap" v1 "k8s.io/api/core/v1" diff --git a/tracing/suite_test.go b/tracing/suite_test.go index adfa9a3f2..c6f5ea231 100644 --- a/tracing/suite_test.go +++ b/tracing/suite_test.go @@ -23,7 +23,7 @@ import ( "testing" "github.com/emicklei/go-restful/v3" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "go.opentelemetry.io/otel" "k8s.io/client-go/kubernetes" diff --git a/tracing/transport_test.go b/tracing/transport_test.go index 2f10dabd3..a56dbb190 100644 --- a/tracing/transport_test.go +++ b/tracing/transport_test.go @@ -25,7 +25,7 @@ import ( "testing" "time" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/propagation" diff --git a/user/matching/helpers_test.go b/user/matching/helpers_test.go index 727af9fc8..ee74a1dc2 100644 --- a/user/matching/helpers_test.go +++ b/user/matching/helpers_test.go @@ -19,8 +19,7 @@ package matching_test import ( . "github.com/katanomi/pkg/user/matching" - . "github.com/onsi/ginkgo" - . "github.com/onsi/ginkgo/extensions/table" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" gomegatypes "github.com/onsi/gomega/types" authenticationv1 "k8s.io/api/authentication/v1" diff --git a/user/matching/matchuser_suite_test.go b/user/matching/matchuser_suite_test.go index ce7e09632..903f52919 100644 --- a/user/matching/matchuser_suite_test.go +++ b/user/matching/matchuser_suite_test.go @@ -19,7 +19,7 @@ package matching_test import ( "testing" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/user/matching/matchuser_test.go b/user/matching/matchuser_test.go index 86a89af5c..ea651218f 100644 --- a/user/matching/matchuser_test.go +++ b/user/matching/matchuser_test.go @@ -19,8 +19,7 @@ package matching_test import ( . "github.com/katanomi/pkg/user/matching" - . "github.com/onsi/ginkgo" - . "github.com/onsi/ginkgo/extensions/table" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" gomegatypes "github.com/onsi/gomega/types" authenticationv1 "k8s.io/api/authentication/v1"