Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠ Migrate to ginkgo v2 #1977

Merged
merged 15 commits into from Aug 26, 2022
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -22,3 +22,6 @@

# Tools binaries.
hack/tools/bin

junit-report.xml
/artifacts
3 changes: 3 additions & 0 deletions example_test.go
Expand Up @@ -26,6 +26,9 @@ import (
corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

// since we invoke tests with -ginkgo.junit-report we need to import ginkgo.
_ "github.com/onsi/ginkgo/v2"
)

// This example creates a simple application Controller that is configured for ReplicaSets and Pods.
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-logr/logr v1.2.3
github.com/go-logr/zapr v1.2.3
github.com/google/go-cmp v0.5.8
github.com/onsi/ginkgo v1.16.5
github.com/onsi/ginkgo/v2 v2.1.4
github.com/onsi/gomega v1.19.0
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/client_model v0.2.0
Expand Down Expand Up @@ -53,7 +53,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
Expand All @@ -67,7 +66,6 @@ require (
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // 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.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
Expand Down
5 changes: 1 addition & 4 deletions go.sum
Expand Up @@ -378,14 +378,12 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
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.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
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=
Expand Down Expand Up @@ -973,7 +971,6 @@ gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
17 changes: 15 additions & 2 deletions hack/test-all.sh
Expand Up @@ -20,8 +20,21 @@ source $(dirname ${BASH_SOURCE})/common.sh

header_text "running go test"

go test -race ${P_FLAG} ${MOD_OPT} ./...
if [[ -n ${ARTIFACTS:-} ]]; then
GINKGO_ARGS="-ginkgo.junit-report=junit-report.xml"
fi

result=0
go test -race ${P_FLAG} ${MOD_OPT} ./... ${GINKGO_ARGS} || result=$?

if [[ -n ${ARTIFACTS:-} ]]; then
if grep -Rin '<failure type="Failure">' ${ARTIFACTS}/*; then exit 1; fi
mkdir -p ${ARTIFACTS}
for file in `find . -name *junit-report.xml`; do
new_file=${file#./}
new_file=${new_file%/junit-report.xml}
new_file=${new_file//"/"/"-"}
mv "$file" "$ARTIFACTS/junit_${new_file}.xml"
done
fi

exit $result
8 changes: 3 additions & 5 deletions pkg/builder/builder_suite_test.go
Expand Up @@ -19,7 +19,7 @@ package builder
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/meta"
Expand All @@ -28,7 +28,6 @@ import (
"k8s.io/client-go/rest"

"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
"sigs.k8s.io/controller-runtime/pkg/internal/testing/addr"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
Expand All @@ -38,8 +37,7 @@ import (

func TestBuilder(t *testing.T) {
RegisterFailHandler(Fail)
suiteName := "application Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
RunSpecs(t, "application Suite")
}

var testenv *envtest.Environment
Expand All @@ -63,7 +61,7 @@ var _ = BeforeSuite(func() {

webhook.DefaultPort, _, err = addr.Suggest("")
Expect(err).NotTo(HaveOccurred())
}, 60)
})

var _ = AfterSuite(func() {
Expect(testenv.Stop()).To(Succeed())
Expand Down
7 changes: 3 additions & 4 deletions pkg/builder/controller_test.go
Expand Up @@ -23,7 +23,7 @@ import (
"sync/atomic"

"github.com/go-logr/logr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -321,7 +321,7 @@ var _ = Describe("application", func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
doReconcileTest(ctx, "3", m, false, bldr)
}, 10)
})

It("should Reconcile Watches objects", func() {
m, err := manager.New(cfg, manager.Options{})
Expand All @@ -336,7 +336,7 @@ var _ = Describe("application", func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
doReconcileTest(ctx, "4", m, true, bldr)
}, 10)
})
})

Describe("Set custom predicates", func() {
Expand Down Expand Up @@ -552,7 +552,6 @@ func doReconcileTest(ctx context.Context, nameSuffix string, mgr manager.Manager
go func() {
defer GinkgoRecover()
Expect(mgr.Start(ctx)).NotTo(HaveOccurred())
By("Stopping the application")
}()

By("Creating a Deployment")
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/webhook_test.go
Expand Up @@ -25,7 +25,7 @@ import (
"os"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down
8 changes: 3 additions & 5 deletions pkg/cache/cache_suite_test.go
Expand Up @@ -19,20 +19,18 @@ package cache_test
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
suiteName := "Cache Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
RunSpecs(t, "Cache Suite")
}

var testenv *envtest.Environment
Expand All @@ -50,7 +48,7 @@ var _ = BeforeSuite(func() {

clientset, err = kubernetes.NewForConfig(cfg)
Expect(err).NotTo(HaveOccurred())
}, 60)
})

var _ = AfterSuite(func() {
Expect(testenv.Stop()).To(Succeed())
Expand Down
11 changes: 5 additions & 6 deletions pkg/cache/cache_test.go
Expand Up @@ -23,8 +23,7 @@ import (
"sort"
"strconv"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -1540,7 +1539,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca

By("verifying the object is received on the channel")
Eventually(out).Should(Receive(Equal(pod)))
}, 3)
})

It("should be able to index an object field then retrieve objects by that field", func() {
By("creating the cache")
Expand Down Expand Up @@ -1590,7 +1589,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
Expect(listObj.Items).Should(HaveLen(1))
actual := listObj.Items[0]
Expect(actual.GetName()).To(Equal("test-pod-3"))
}, 3)
})

It("should allow for get informer to be cancelled", func() {
By("cancelling the context")
Expand Down Expand Up @@ -1660,7 +1659,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca

By("verifying the object's metadata is received on the channel")
Eventually(out).Should(Receive(Equal(podMeta)))
}, 3)
})

It("should be able to index an object field then retrieve objects by that field", func() {
By("creating the cache")
Expand Down Expand Up @@ -1714,7 +1713,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
Version: "v1",
Kind: "Pod",
}))
}, 3)
})

It("should allow for get informer to be cancelled", func() {
By("creating a context and cancelling it")
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/informer_cache_test.go
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package cache_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"k8s.io/client-go/rest"
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/informer_cache_unit_test.go
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package cache

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/internal/informers_map_test.go
Expand Up @@ -19,7 +19,7 @@ package internal
import (
"fmt"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down
6 changes: 2 additions & 4 deletions pkg/cache/internal/internal_suite_test.go
Expand Up @@ -19,13 +19,11 @@ package internal
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
)

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
suiteName := "Cache Internal Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
RunSpecs(t, "Cache Internal Suite")
}
10 changes: 4 additions & 6 deletions pkg/certwatcher/certwatcher_suite_test.go
Expand Up @@ -20,9 +20,8 @@ import (
"os"
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)
Expand All @@ -34,16 +33,15 @@ var (

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
suiteName := "CertWatcher Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
RunSpecs(t, "CertWatcher Suite")
}

var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
}, 60)
})

var _ = AfterSuite(func() {
for _, file := range []string{certPath, keyPath} {
_ = os.Remove(file)
}
}, 60)
})
2 changes: 1 addition & 1 deletion pkg/certwatcher/certwatcher_test.go
Expand Up @@ -29,7 +29,7 @@ import (
"os"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/prometheus/client_golang/prometheus/testutil"
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
Expand Down
8 changes: 3 additions & 5 deletions pkg/client/apiutil/apiutil_suite_test.go
Expand Up @@ -19,19 +19,17 @@ package apiutil
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"

logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

func TestSource(t *testing.T) {
RegisterFailHandler(Fail)
suiteName := "API Utilities Test Suite"
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
RunSpecs(t, "API Utilities Test Suite")
}

var cfg *rest.Config
Expand All @@ -41,4 +39,4 @@ var _ = BeforeSuite(func() {

// for things that technically need a rest.Config for defaulting, but don't actually use them
cfg = &rest.Config{}
}, 60)
})
2 changes: 1 addition & 1 deletion pkg/client/apiutil/dynamicrestmapper_test.go
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/format"
"github.com/onsi/gomega/types"
Expand Down