Skip to content

Commit

Permalink
Ginkgo v2 (#506)
Browse files Browse the repository at this point in the history
* ginkgo v2

* add changelog

* gofmt

* update gitignore

* set TEST_PKG in ci

* ignore binary test files

* PR feedback: fix ginkgo ref, improve makefile usability

* support make help

* use k8s-utils with ginkgo

* cleanup gha for pull request, default test_pkg

* use k8s-utils with ginkgo

* improve makefile

* Revert "use k8s-utils with ginkgo"

This reverts commit 91a27a4.

* Revert "use k8s-utils with ginkgo"

This reverts commit 91a27a4.

* go mod download tools

* tools

* gofmt

* cleanup makefile

* include race in tests

* Test branch protectiion rules

* try to run CI without kube cluster

* ubuntu bump

* update setup-gcloud gha

* skip github tests for now

* try to auth preoprly

* gcloud auth in gha?

* use new auth api

* creds json?

* run github tests again
  • Loading branch information
sam-heilbron authored Feb 7, 2023
1 parent af8548e commit da4a950
Show file tree
Hide file tree
Showing 89 changed files with 388 additions and 422 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeformat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: pull_request
jobs:
codegen:
name: Code format check
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- name: Cancel Previous Actions
uses: styfle/[email protected]
Expand Down
25 changes: 13 additions & 12 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ on:
push:
branches:
- 'master'
- 'main'
pull_request:

jobs:
test:
name: Tests
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
Expand All @@ -18,12 +19,17 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: google-github-actions/[email protected]
- name: Setup GCloud Auth
uses: google-github-actions/auth@v1
with:
version: '290.0.1'
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
credentials_json: ${{ secrets.GCP_SA_KEY }}
create_credentials_file: true
export_environment_variables: true
- name: Setup GCloud SDK
uses: google-github-actions/[email protected]
with:
version: '>= 386.0.0'
- name: Install Trivy
run: |
wget https://github.com/aquasecurity/trivy/releases/download/v0.18.3/trivy_0.18.3_Linux-64bit.deb
Expand All @@ -38,16 +44,11 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go
- uses: azure/setup-kubectl@v1
with:
version: 'v1.18.0'
- uses: engineerd/[email protected]
- name: Run tests
env:
GITHUB_TOKEN: ${{ secrets.CLOUDBUILD_GITHUB_TOKEN }}
run: |
go install -v github.com/onsi/ginkgo/[email protected] && export PATH=$PATH:$(go env GOPATH)/bin/
ginkgo -r -failFast -randomizeSuites -randomizeAllSpecs -skipPackage=./installutils/kubeinstall,./debugutils/test
TEST_PKG: ./... # Run all tests
run: make test
- uses: testspace-com/setup-testspace@v1
with:
domain: solo-io.testspace.com
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ vendor
# junit
junit.xml

_output
_output

test-report.json
junit*.xml
*cov

*.test
66 changes: 65 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
# https://www.gnu.org/software/make/manual/html_node/Special-Variables.html#Special-Variables
.DEFAULT_GOAL := help

#----------------------------------------------------------------------------------
# Help
#----------------------------------------------------------------------------------
# Our Makefile is quite large, and hard to reason through
# `make help` can be used to self-document targets
# To update a target to be self-documenting (and appear with the `help` command),
# place a comment after the target that is prefixed by `##`. For example:
# custom-target: ## comment that will appear in the documentation when running `make help`
#
# **NOTE TO DEVELOPERS**
# As you encounter make targets that are frequently used, please make them self-documenting
.PHONY: help
help: FIRST_COLUMN_WIDTH=35
help: ## Output the self-documenting make targets
@grep -hE '^[%a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-$(FIRST_COLUMN_WIDTH)s\033[0m %s\n", $$1, $$2}'

#----------------------------------------------------------------------------------
# Repo setup
#----------------------------------------------------------------------------------
ROOT_DIR := $(shell pwd)
OUTPUT_DIR := $(ROOT_DIR)/_output
DEPSGOBIN:= $(OUTPUT_DIR)/.bin

export PATH:=$(DEPSGOBIN):$(PATH)
export GOBIN:=$(DEPSGOBIN)

# https://www.viget.com/articles/two-ways-to-share-git-hooks-with-your-team/
.PHONY: init
Expand All @@ -13,4 +38,43 @@ install-go-tools:

.PHONY: format-code
format-code: install-go-tools
goimports -w .
goimports -w .

#----------------------------------------------------------------------------------
# Clean
#----------------------------------------------------------------------------------

.PHONY: clean
clean: ## Clean any local assets
rm -rf $(OUTPUT_DIR)
find * -type f -name '*.test' -exec rm {} \;

#----------------------------------------------------------------------------------
# Tests
#----------------------------------------------------------------------------------

GINKGO_VERSION ?= 2.5.0 # match our go.mod
GINKGO_ENV ?= GOLANG_PROTOBUF_REGISTRATION_CONFLICT=ignore ACK_GINKGO_DEPRECATIONS=$(GINKGO_VERSION)
GINKGO_FLAGS ?= -v -tags=purego -compilers=4 -fail-fast -race -randomize-suites -randomize-all -skip-package=./installutils/kubeinstall,./debugutils/test
GINKGO_REPORT_FLAGS ?= --json-report=test-report.json --junit-report=junit.xml -output-dir=$(OUTPUT_DIR)
GINKGO_COVERAGE_FLAGS ?= --cover --covermode=atomic --coverprofile=coverage.cov
TEST_PKG ?= ./... # Default to run all tests

# This is a way for a user executing `make test` to be able to provide flags which we do not include by default
# For example, you may want to run tests multiple times, or with various timeouts
GINKGO_USER_FLAGS ?=

.PHONY: install-test-tools
install-test-tools:
go install github.com/onsi/ginkgo/v2/ginkgo@v$(GINKGO_VERSION)

.PHONY: test
test: install-test-tools ## Run tests in the {TEST_PKG}
$(GINKGO_ENV) ginkgo \
$(GINKGO_FLAGS) $(GINKGO_REPORT_FLAGS) $(GINKGO_USER_FLAGS) \
$(TEST_PKG)

.PHONY: test-with-coverage
test-with-coverage: GINKGO_FLAGS += $(GINKGO_COVERAGE_FLAGS) ## Run tests in the {TEST_PKG} with coverage
test-with-coverage: test
go tool cover -html $(OUTPUT_DIR)/coverage.cov
12 changes: 3 additions & 9 deletions botutils/botconfig/botconfig_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@ package botconfig_test
import (
"testing"

"github.com/onsi/ginkgo/reporters"

"github.com/solo-io/go-utils/testutils"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestBotconfig(t *testing.T) {
test = t
RegisterFailHandler(Fail)
testutils.RegisterPreFailHandler(
func() {
testutils.PrintTrimmedStack()
})
testutils.RegisterPreFailHandler(testutils.PrintTrimmedStack)
testutils.RegisterCommonFailHandlers()
junitReporter := reporters.NewJUnitReporter("junit.xml")
RunSpecsWithDefaultAndCustomReporters(t, "Botconfig Suite", []Reporter{junitReporter})
RunSpecs(t, "Botconfig Suite")
}

var test *testing.T
2 changes: 1 addition & 1 deletion botutils/botconfig/botconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package botconfig_test

import (
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/palantir/go-baseapp/baseapp"
"github.com/palantir/go-githubapp/githubapp"
Expand Down
6 changes: 6 additions & 0 deletions changelog/v0.24.0/ginkgo-v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
- type: BREAKING_CHANGE
issueLink: https://github.com/solo-io/gloo/issues/7222
resolvesIssue: false
description: >
Upgrade Ginkgo from v1 to v2, using https://onsi.github.io/ginkgo/MIGRATING_TO_V2 as a helpful guide.
2 changes: 1 addition & 1 deletion changeloggenutils/changelogdocutils_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package changelogdocutils_test
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

Expand Down
2 changes: 1 addition & 1 deletion changeloggenutils/merged_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/google/go-github/v32/github"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/solo-io/go-utils/changeloggenutils"
"github.com/solo-io/go-utils/githubutils"
Expand Down
2 changes: 1 addition & 1 deletion changeloggenutils/minor_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

"github.com/google/go-github/v32/github"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/solo-io/go-utils/changeloggenutils"
"github.com/solo-io/go-utils/githubutils"
Expand Down
2 changes: 1 addition & 1 deletion changelogutils/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"

"github.com/ghodss/yaml"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/solo-io/go-utils/changelogutils"
"github.com/solo-io/go-utils/githubutils"
Expand Down
12 changes: 3 additions & 9 deletions changelogutils/changelogutils_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@ package changelogutils_test
import (
"testing"

"github.com/onsi/ginkgo/reporters"

"github.com/solo-io/go-utils/testutils"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestChangelogUtils(t *testing.T) {
test = t
RegisterFailHandler(Fail)
testutils.RegisterPreFailHandler(
func() {
testutils.PrintTrimmedStack()
})
testutils.RegisterPreFailHandler(testutils.PrintTrimmedStack)
testutils.RegisterCommonFailHandlers()
junitReporter := reporters.NewJUnitReporter("junit.xml")
RunSpecsWithDefaultAndCustomReporters(t, "ChangelogUtils Suite", []Reporter{junitReporter})
RunSpecs(t, "ChangelogUtils Suite")
}

var test *testing.T
2 changes: 1 addition & 1 deletion changelogutils/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rotisserie/eris"
"github.com/solo-io/go-utils/changelogutils"
Expand Down
4 changes: 1 addition & 3 deletions changelogutils/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import (
"os"
"path/filepath"

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

"github.com/golang/mock/gomock"
"github.com/google/go-github/v32/github"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rotisserie/eris"
"github.com/solo-io/go-utils/changelogutils"
Expand Down
9 changes: 9 additions & 0 deletions ci/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build tools
// +build tools

// This package imports things required by build scripts, to force `go mod` to see them as dependencies
package tools

import (
_ "golang.org/x/tools/cmd/goimports"
)
2 changes: 1 addition & 1 deletion clicore/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/solo-io/go-utils/contextutils"
"github.com/spf13/cobra"
Expand Down
13 changes: 3 additions & 10 deletions clicore/clicore_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@ package clicore
import (
"testing"

"github.com/onsi/ginkgo/reporters"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/solo-io/go-utils/testutils"
)

func TestCliCore(t *testing.T) {

testutils.RegisterPreFailHandler(
func() {
testutils.PrintTrimmedStack()
})
testutils.RegisterPreFailHandler(testutils.PrintTrimmedStack)
testutils.RegisterCommonFailHandlers()
RegisterFailHandler(Fail)
testutils.SetupLog()
junitReporter := reporters.NewJUnitReporter("junit.xml")
RunSpecsWithDefaultAndCustomReporters(t, "Clicore Suite", []Reporter{junitReporter})
RunSpecs(t, "Clicore Suite")
}
2 changes: 1 addition & 1 deletion cliutils/cli_helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cliutils_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/solo-io/go-utils/cliutils"
)
Expand Down
7 changes: 2 additions & 5 deletions cliutils/common_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ package cliutils_test
import (
"testing"

"github.com/onsi/ginkgo/reporters"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestCommon(t *testing.T) {
RegisterFailHandler(Fail)
junitReporter := reporters.NewJUnitReporter("junit.xml")
RunSpecsWithDefaultAndCustomReporters(t, "Common Suite", []Reporter{junitReporter})
RunSpecs(t, "Common Suite")
}
7 changes: 2 additions & 5 deletions docker/docker_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ package docker_test
import (
"testing"

"github.com/onsi/ginkgo/reporters"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestDocker(t *testing.T) {
RegisterFailHandler(Fail)
junitReporter := reporters.NewJUnitReporter("junit.xml")
RunSpecsWithDefaultAndCustomReporters(t, "Docker Suite", []Reporter{junitReporter})
RunSpecs(t, "Docker Suite")
}
2 changes: 1 addition & 1 deletion docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io/ioutil"
"os/exec"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/solo-io/go-utils/docker"
)
Expand Down
2 changes: 1 addition & 1 deletion docsutils/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"

"github.com/google/go-github/v32/github"
"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/v2"
"github.com/pkg/errors"
"github.com/rotisserie/eris"
"github.com/solo-io/go-utils/changelogutils"
Expand Down
Loading

0 comments on commit da4a950

Please sign in to comment.