Skip to content

Commit

Permalink
upgrade ginkgo to v2
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
  • Loading branch information
inteon committed Aug 4, 2022
1 parent f6a381d commit 9897f23
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 96 deletions.
6 changes: 1 addition & 5 deletions LICENSES
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ github.com/modern-go/reflect2,https://github.com/modern-go/reflect2/blob/v1.0.2/
github.com/monochromegane/go-gitignore,https://github.com/monochromegane/go-gitignore/blob/205db1a8cc00/LICENSE,MIT
github.com/morikuni/aec,https://github.com/morikuni/aec/blob/v1.0.0/LICENSE,MIT
github.com/munnerz/goautoneg,https://github.com/munnerz/goautoneg/blob/a7dc8b61c822/LICENSE,BSD-3-Clause
github.com/nxadm/tail,https://github.com/nxadm/tail/blob/v1.4.8/LICENSE,MIT
github.com/nxadm/tail/ratelimiter,https://github.com/nxadm/tail/blob/v1.4.8/ratelimiter/Licence,MIT
github.com/onsi/ginkgo,https://github.com/onsi/ginkgo/blob/v1.16.5/LICENSE,MIT
github.com/onsi/ginkgo/reporters/stenographer/support/go-colorable,https://github.com/onsi/ginkgo/blob/v1.16.5/reporters/stenographer/support/go-colorable/LICENSE,MIT
github.com/onsi/ginkgo/v2,https://github.com/onsi/ginkgo/blob/v2.1.4/LICENSE,MIT
github.com/onsi/gomega,https://github.com/onsi/gomega/blob/v1.19.0/LICENSE,MIT
github.com/opencontainers/go-digest,https://github.com/opencontainers/go-digest/blob/v1.0.0/LICENSE,Apache-2.0
github.com/opencontainers/image-spec/specs-go,https://github.com/opencontainers/image-spec/blob/c5a74bcca799/LICENSE,Apache-2.0
Expand Down Expand Up @@ -201,7 +198,6 @@ gopkg.in/ini.v1,https://github.com/go-ini/ini/blob/v1.66.2/LICENSE,Apache-2.0
gopkg.in/natefinch/lumberjack.v2,https://github.com/natefinch/lumberjack/blob/v2.0.0/LICENSE,MIT
gopkg.in/square/go-jose.v2,https://github.com/square/go-jose/blob/v2.5.1/LICENSE,Apache-2.0
gopkg.in/square/go-jose.v2/json,https://github.com/square/go-jose/blob/v2.5.1/json/LICENSE,BSD-3-Clause
gopkg.in/tomb.v1,https://github.com/go-tomb/tomb/blob/dd632973f1e7/LICENSE,BSD-3-Clause
gopkg.in/yaml.v2,https://github.com/go-yaml/yaml/blob/v2.4.0/LICENSE,Apache-2.0
gopkg.in/yaml.v3,https://github.com/go-yaml/yaml/blob/496545a6307b/LICENSE,MIT
helm.sh/helm/v3,https://github.com/helm/helm/blob/v3.9.0/LICENSE,Apache-2.0
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/miekg/dns v1.1.47
github.com/mitchellh/go-homedir v1.1.0
github.com/munnerz/crd-schema-fuzz v1.0.0
github.com/onsi/ginkgo v1.16.5
github.com/onsi/ginkgo/v2 v2.1.4
github.com/onsi/gomega v1.19.0
github.com/pavel-v-chernykh/keystore-go/v4 v4.2.0
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -126,6 +126,7 @@ require (
github.com/google/btree v1.0.1 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
Expand Down Expand Up @@ -172,7 +173,6 @@ require (
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
Expand Down Expand Up @@ -231,7 +231,6 @@ require (
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/square/go-jose.v2 v2.5.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/gengo v0.0.0-20211129171323-c02415ce4185 // indirect
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
Expand Down Expand Up @@ -1006,8 +1007,8 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
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 h1:e/3Cwtogj0HA+25nMP1jCMDIf8RtRYbGwGGuBIFztkc=
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-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
Expand Down
2 changes: 1 addition & 1 deletion hack/bin/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ limitations under the License.
package bin

import (
_ "github.com/onsi/ginkgo/ginkgo"
_ "github.com/onsi/ginkgo/v2/ginkgo"
_ "k8s.io/code-generator/cmd/client-gen"
_ "k8s.io/code-generator/cmd/conversion-gen"
_ "k8s.io/code-generator/cmd/deepcopy-gen"
Expand Down
24 changes: 16 additions & 8 deletions make/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ set -e
_default_bindir=$(make print-bindir)

BINDIR=${BINDIR:-$_default_bindir}
ARTIFACTS=${ARTIFACTS:-$(pwd)/$BINDIR/artifacts}

# Why do we only run 20 tests concurrently? Because we have noticed that
# many tests start timing out when the Prow pod gets overloaded. We are
Expand Down Expand Up @@ -75,6 +74,7 @@ flake_attempts=1
ginkgo_skip=
ginkgo_focus=
feature_gates=AdditionalCertificateOutputFormats=true,ExperimentalCertificateSigningRequestControllers=true,ExperimentalGatewayAPISupport=true
artifacts="./$BINDIR/artifacts"
help() {
cat <<EOF | color ""
Runs the end-to-end test suite against an already configured kind cluster.
Expand Down Expand Up @@ -106,7 +106,7 @@ Environment variables:
to $feature_gates
${green}ARTIFACTS${end}
The path to a directory where the JUnit XML files will be stored. By
default, the JUnit XML files are saved to ./$BINDIR/artifacts
default, the JUnit XML files are saved to $artifacts
Details:
Imagine you got the following failure:
Expand Down Expand Up @@ -149,7 +149,7 @@ if [ $# -gt 0 ]; then
esac
fi

for v in FEATURE_GATES FLAKE_ATTEMPTS NODES GINKGO_FOCUS GINKGO_SKIP; do
for v in FEATURE_GATES FLAKE_ATTEMPTS NODES GINKGO_FOCUS GINKGO_SKIP ARTIFACTS; do
if printenv "$v" >/dev/null && [ -n "${!v}" ]; then
eval "$(tr '[:upper:]' '[:lower:]' <<<"$v")=\"${!v}\""
fi
Expand Down Expand Up @@ -185,18 +185,26 @@ if [[ "${ginkgo_args[*]}" =~ ginkgo.focus ]]; then
ginkgo_args+=(--ginkgo.v --test.v)
fi

mkdir -p "${ARTIFACTS}"
mkdir -p "$artifacts"

export CGO_ENABLED=0

trace ginkgo \
-nodes "$nodes" \
-flakeAttempts "$flake_attempts" \
-tags e2e_test \
-tags=e2e_test \
-procs="$nodes" \
-output-dir="$artifacts" \
-junit-report="junit__01.xml" \
-flake-attempts="$flake_attempts" \
-timeout="24h" \
-v \
-randomize-all \
-progress \
-trace \
-slow-spec-threshold="${GINKGO_SLOW_SPEC_THRESHOLD:-300s}" \
./test/e2e/ \
-- \
--repo-root="$PWD" \
--report-dir="${ARTIFACTS}" \
--report-dir="$artifacts" \
--acme-dns-server="${SERVICE_IP_PREFIX}.16" \
--acme-ingress-ip="${SERVICE_IP_PREFIX}.15" \
--acme-gateway-ip="${SERVICE_IP_PREFIX}.14" \
Expand Down
6 changes: 3 additions & 3 deletions make/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ CONTROLLER_GEN_VERSION=0.8.0
COSIGN_VERSION=1.3.1
CMREL_VERSION=a1e2bad95be9688794fd0571c4c40e88cccf9173
K8S_RELEASE_NOTES_VERSION=0.7.0
GATEWAY_API_VERSION = 0.4.1
GATEWAY_API_VERSION=0.4.1
GOIMPORTS_VERSION=0.1.8
GOLICENSES_VERSION=1.2.1
GOTESTSUM_VERSION=1.7.0
RCLONE_VERSION=1.58.1
YTT_VERSION=0.36.0
YQ_VERSION=4.25.3
CRANE_VERSION=0.8.0
GINKGO_VERSION=$(shell awk '/ginkgo/ {print $$2}' go.mod)
GINKGO_VERSION=$(shell awk '/ginkgo\/v2/ {print $$2}' go.mod)

K8S_CODEGEN_VERSION=v0.24.2

Expand Down Expand Up @@ -226,7 +226,7 @@ $(BINDIR)/tools/ginkgo: $(BINDIR)/downloaded/tools/ginkgo@$(GINKGO_VERSION) $(BI
@cd $(dir $@) && $(LN) $(patsubst $(BINDIR)/%,../%,$<) $(notdir $@)

$(BINDIR)/downloaded/tools/ginkgo@$(GINKGO_VERSION): $(DEPENDS_ON_GO) | $(BINDIR)/downloaded/tools
GOBIN=$(PWD)/$(dir $@) $(GO) install github.com/onsi/ginkgo/ginkgo@$(GINKGO_VERSION)
GOBIN=$(PWD)/$(dir $@) $(GO) install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION)
@mv $(subst @$(GINKGO_VERSION),,$@) $@

#########
Expand Down
55 changes: 25 additions & 30 deletions test/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import (
"github.com/cert-manager/cert-manager/test/e2e/framework/log"
)

var (
cfg = framework.DefaultConfig
)
var cfg = framework.DefaultConfig

var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
addon.InitGlobals(cfg)
Expand All @@ -49,36 +47,33 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
}
})

var globalLogs map[string]string
var _ = ginkgo.SynchronizedAfterSuite(func() {}, func() {
ginkgo.By("Retrieving logs for global addons")
globalLogs, err := addon.GlobalLogs()
if err != nil {
log.Logf("Failed to retrieve global addon logs: " + err.Error())
}

for k, v := range globalLogs {
outPath := path.Join(cfg.Ginkgo.ReportDirectory, "logs", k)

var _ = ginkgo.SynchronizedAfterSuite(func() {},
func() {
ginkgo.By("Retrieving logs for global addons")
var err error
globalLogs, err = addon.GlobalLogs()
// Create a directory for the file if needed
err := os.MkdirAll(path.Dir(outPath), 0755)
if err != nil {
log.Logf("Failed to retrieve global addon logs: " + err.Error())
}

for k, v := range globalLogs {
outPath := path.Join(framework.DefaultConfig.Ginkgo.ReportDirectory, "logs", k)
// Create a directory for the file if needed
err := os.MkdirAll(path.Dir(outPath), 0755)
if err != nil {
log.Logf("Failed to create directory for logs: %v", err)
continue
}

err = os.WriteFile(outPath, []byte(v), 0644)
if err != nil {
log.Logf("Failed to write log file: %v", err)
continue
}
log.Logf("Failed to create directory for logs: %v", err)
continue
}

ginkgo.By("Cleaning up the provisioned globals")
err = addon.DeprovisionGlobals(cfg)
err = os.WriteFile(outPath, []byte(v), 0644)
if err != nil {
framework.Failf("Error deprovisioning global addons: %v", err)
log.Logf("Failed to write log file: %v", err)
continue
}
})
}

ginkgo.By("Cleaning up the provisioned globals")
err = addon.DeprovisionGlobals(cfg)
if err != nil {
framework.Failf("Error deprovisioning global addons: %v", err)
}
})
45 changes: 4 additions & 41 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,69 +20,32 @@ package e2e

import (
"flag"
"fmt"
"path"
"testing"
"time"

"github.com/onsi/ginkgo/v2"
ginkgoconfig "github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/reporters"
"github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/cert-manager/cert-manager/pkg/logs"
"github.com/cert-manager/cert-manager/test/e2e/framework"
_ "github.com/cert-manager/cert-manager/test/e2e/suite"
)

var featureGates string

func init() {
logs.InitLogs(flag.CommandLine)
framework.DefaultConfig.AddFlags(flag.CommandLine)

// Turn on verbose by default to get spec names
ginkgoconfig.DefaultReporterConfig.Verbose = true
// Turn on EmitSpecProgress to get spec progress (especially on interrupt)
ginkgoconfig.GinkgoConfig.EmitSpecProgress = true
// Randomize specs as well as suites
ginkgoconfig.GinkgoConfig.RandomizeAllSpecs = true
cfg.AddFlags(flag.CommandLine)

wait.ForeverTestTimeout = time.Second * 60
}

func TestE2E(t *testing.T) {
defer logs.FlushLogs()
flag.Parse()

// Disable skipped tests unless they are explicitly requested.
// Copied from https://github.com/kubernetes/kubernetes/blob/960e5e78255dd148d4dae49f62e729ea940f4f07/test/e2e/e2e.go#L103-L106
// See https://github.com/kubernetes/community/blob/master/contributors/devel/sig-testing/flaky-tests.md#quarantining-flakes
if len(ginkgoconfig.GinkgoConfig.FocusStrings) == 0 && len(ginkgoconfig.GinkgoConfig.SkipStrings) == 0 {
ginkgoconfig.GinkgoConfig.SkipStrings = []string{`\[Flaky\]`}
}

if err := framework.DefaultConfig.Validate(); err != nil {
t.Fatalf("Invalid test config: %v", err)
}

gomega.NewWithT(t)
gomega.RegisterFailHandler(ginkgo.Fail)

// TODO: properly make use of default SkipString
// Disable skipped tests unless they are explicitly requested.
// if ginkgoconfig.GinkgoConfig.FocusString == "" && ginkgoconfig.GinkgoConfig.SkipString == "" {
// ginkgoconfig.GinkgoConfig.SkipString = `\[Flaky\]|\[Feature:.+\]`
// }

var r []ginkgo.Reporter
if framework.DefaultConfig.Ginkgo.ReportDirectory != "" {
r = append(r, reporters.NewJUnitReporter(path.Join(framework.DefaultConfig.Ginkgo.ReportDirectory,
fmt.Sprintf("junit_%s_%02d.xml",
framework.DefaultConfig.Ginkgo.ReportPrefix,
ginkgoconfig.GinkgoConfig.ParallelNode))))
if err := cfg.Validate(); err != nil {
t.Fatalf("Invalid test config: %v", err)
}

ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "cert-manager e2e suite", r)
ginkgo.RunSpecs(t, "cert-manager e2e suite")
}
2 changes: 0 additions & 2 deletions test/e2e/framework/config/ginkgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import (

type Ginkgo struct {
ReportDirectory string
ReportPrefix string
}

func (g *Ginkgo) AddFlags(fs *flag.FlagSet) {
fs.StringVar(&g.ReportDirectory, "report-dir", "", "Optional directory to store junit output in. If not specified, no junit file will be output")
fs.StringVar(&g.ReportPrefix, "report-prefix", "", "Optional prefix for JUnit XML reports. Default is empty, which doesn't prepend anything to the default name")
}

func (c *Ginkgo) Validate() []error {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (f *Framework) AfterEach() {
}

func (f *Framework) printAddonLogs() {
if CurrentGinkgoTestDescription().Failed {
if CurrentSpecReport().Failed() {
for _, a := range f.requiredAddons {
if a, ok := a.(loggableAddon); ok {
l, err := a.Logs()
Expand Down

0 comments on commit 9897f23

Please sign in to comment.