test improvements (#5741)

## Summary
Some test improvements:

- disable the race detector on macos, which currently results in a ton
of linking errors, and I think doing race detection on linux is
sufficient to find stuff
- add build tags to the `integration` folder so it's not included by
default when running `go test ./...`
- remove some unused stuff in the Makefile
- change the file `testenv` searches for from `.git` to `go.mod` which
allows test caching to work more reliably
- remove the test for orphaned connections in postgres. It doesn't
actually make sense because we have listener connections in the
background. I think it was racy.
- fix yarn caching


## Checklist

- [ ] reference any related issues
- [x] updated unit tests
- [x] add appropriate label (`enhancement`, `bug`, `breaking`,
`dependencies`, `ci`)
- [x] ready for review
This commit is contained in:
Caleb Doxsey 2025-07-23 14:07:11 -06:00 committed by GitHub
parent f1ed893e10
commit 9471527a35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 34 additions and 28 deletions

View file

@ -29,7 +29,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: yarn
cache-dependency-path: ui/yarn.lock
cache-dependency-path: "**/yarn.lock"
- name: set env vars
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
@ -47,7 +47,7 @@ jobs:
- name: integration tests
run: |
(cd ./integration/clusters/${{matrix.deployment}}-${{matrix.authenticate-flow}} && docker compose logs -f &)
go test -v ./integration/...
go test -tags integration -v ./integration/...
build:
strategy:

View file

@ -6,34 +6,36 @@ PKG := github.com/pomerium/pomerium
BUILDDIR := ${PREFIX}/dist
BINDIR := ${PREFIX}/bin
GO111MODULE=on
CGO_ENABLED := 0
export GOEXPERIMENT=synctest
# Set any default go build tags
BUILDTAGS :=
# Populate version variables
# Add to compile time flags
VERSION?= $(shell git describe --tags)
VERSION ?= $(shell git describe --tags)
GITCOMMIT := $(shell git rev-parse --short HEAD)
BUILDMETA:=
BUILDMETA :=
GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
ifneq ($(GITUNTRACKEDCHANGES),)
BUILDMETA := dirty
endif
CTIMEVAR=-X $(PKG)/internal/version.GitCommit=$(GITCOMMIT) \
CTIMEVAR = \
-X $(PKG)/internal/version.GitCommit=$(GITCOMMIT) \
-X $(PKG)/internal/version.Version=$(VERSION) \
-X $(PKG)/internal/version.BuildMeta=$(BUILDMETA) \
-X $(PKG)/internal/version.ProjectName=$(NAME) \
-X $(PKG)/internal/version.ProjectURL=$(PKG)
GO ?= "go"
GO_LDFLAGS=-ldflags "-s -w $(CTIMEVAR)"
GOOSARCHES = linux/amd64 darwin/amd64 windows/amd64
GO_LDFLAGS = -ldflags "-s -w $(CTIMEVAR)"
GOOS = $(shell $(GO) env GOOS)
GOARCH= $(shell $(GO) env GOARCH)
GETENVOY_VERSION = v0.2.0
GOARCH = $(shell $(GO) env GOARCH)
GORELEASER_VERSION = v0.174.2
GO_TESTFLAGS := -race
# disable the race detector in macos
ifeq ($(shell env -u GOOS $(GO) env GOOS), darwin)
GO_TESTFLAGS :=
endif
.PHONY: all
all: clean build-deps test lint build ## Runs a clean, build, fmt, lint, test, and vet.
@ -41,7 +43,7 @@ all: clean build-deps test lint build ## Runs a clean, build, fmt, lint, test, a
.PHONY: get-envoy
get-envoy: ## Fetch envoy binaries
@echo "==> $@"
@cd pkg/envoy/files && env -u GOOS go run ../get-envoy
@cd pkg/envoy/files && env -u GOOS $(GO) run ../get-envoy
.PHONY: deps-build
deps-build: get-envoy ## Install build dependencies
@ -50,17 +52,12 @@ deps-build: get-envoy ## Install build dependencies
.PHONY: deps-release
deps-release: get-envoy ## Install release dependencies
@echo "==> $@"
@cd /tmp; GO111MODULE=on $(GO) install github.com/goreleaser/goreleaser@${GORELEASER_VERSION}
@cd /tmp; $(GO) install github.com/goreleaser/goreleaser@${GORELEASER_VERSION}
.PHONY: build-deps
build-deps: deps-build deps-release
@echo "==> $@"
.PHONY: tag
tag: ## Create a new git tag to prepare to build a release
git tag -sa $(VERSION) -m "$(VERSION)"
@echo "Run git push origin $(VERSION) to push your new tag to GitHub."
.PHONY: proto
proto:
@echo "==> $@"
@ -78,12 +75,12 @@ build: build-ui build-go
.PHONY: build-debug
build-debug: build-deps ## Builds binaries appropriate for debugging
@echo "==> $@"
@CGO_ENABLED=0 GO111MODULE=on $(GO) build -gcflags="all=-N -l" -o $(BINDIR)/$(NAME) ./cmd/"$(NAME)"
@CGO_ENABLED=0 $(GO) build -gcflags="all=-N -l" -o $(BINDIR)/$(NAME) ./cmd/"$(NAME)"
.PHONY: build-go
build-go: build-deps
@echo "==> $@"
@CGO_ENABLED=0 GO111MODULE=on $(GO) build -tags "$(BUILDTAGS)" ${GO_LDFLAGS} -o $(BINDIR)/$(NAME) ./cmd/"$(NAME)"
@CGO_ENABLED=0 $(GO) build -tags "$(BUILDTAGS)" ${GO_LDFLAGS} -o $(BINDIR)/$(NAME) ./cmd/"$(NAME)"
.PHONY: build-ui
build-ui: yarn
@ -94,17 +91,17 @@ build-ui: yarn
lint:
@echo "@==> $@"
@VERSION=$$(go run github.com/mikefarah/yq/v4@v4.34.1 '.jobs.lint.steps[] | select(.uses == "golangci/golangci-lint-action*") | .with.version' .github/workflows/lint.yaml) && \
go run github.com/golangci/golangci-lint/cmd/golangci-lint@$$VERSION run ./... --fix
$(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@$$VERSION run ./... --fix
.PHONY: test
test: get-envoy ## Runs the go tests.
@echo "==> $@"
@$(GO) test -race -tags "$(BUILDTAGS)" $(shell $(GO) list ./... | grep -v vendor | grep -v github.com/pomerium/pomerium/integration)
$(GO) test $(GO_TESTFLAGS) -tags "$(BUILDTAGS)" ./...
.PHONY: cover
cover: get-envoy ## Runs go test with coverage
@echo "==> $@"
$(GO) test -race -coverprofile=coverage.txt -tags "$(BUILDTAGS)" $(shell $(GO) list ./... | grep -v vendor | grep -v github.com/pomerium/pomerium/integration)
$(GO) test $(GO_TESTFLAGS) -tags "$(BUILDTAGS)" -coverprofile=coverage.txt ./...
@sed -i.bak '/\.pb\.go\:/d' coverage.txt
@sed -i.bak '/\/mock\.go\:/d' coverage.txt
@sort -o coverage.txt coverage.txt
@ -127,7 +124,7 @@ snapshot: build-deps ## Builds the cross-compiled binaries, naming them in such
.PHONY: yarn
yarn:
@echo "==> $@"
cd ui ; yarn install --network-timeout 120000
cd ui ; yarn install --network-timeout 120000 --frozen-lockfile
.PHONY: help
help:

View file

@ -1,3 +1,5 @@
//go:build integration
package main
import (

View file

@ -1,3 +1,5 @@
//go:build integration
package main
import (

View file

@ -1,3 +1,5 @@
//go:build integration
package main
import (

View file

@ -1,3 +1,5 @@
//go:build integration
package main
import (

View file

@ -1,3 +1,5 @@
//go:build integration
// Package main contains the pomerium integration tests
package main

View file

@ -1,3 +1,5 @@
//go:build integration
package main
import (

View file

@ -366,7 +366,7 @@ func New(t testing.TB, opts ...EnvironmentOption) Environment {
workspaceFolder, err := os.Getwd()
require.NoError(t, err)
for {
if _, err := os.Stat(filepath.Join(workspaceFolder, ".git")); err == nil {
if _, err := os.Stat(filepath.Join(workspaceFolder, "go.mod")); err == nil {
break
}
workspaceFolder = filepath.Dir(workspaceFolder)

View file

@ -48,9 +48,6 @@ func TestBackend(t *testing.T) {
stream.Close()
}
})
assert.Equal(t, int32(0), backend.pool.Stat().AcquiredConns(),
"acquired connections should be released")
})
}