Skip to content

Commit

Permalink
update ci.sh to make it easier to test prerelease versions of go
Browse files Browse the repository at this point in the history
also remove unnecessary integration test logic for GO111MODULE and GOPATH

Signed-off-by: Joe Fitzgerald <joeyfitz@gmail.com>
  • Loading branch information
joefitzgerald committed Jan 12, 2024
1 parent 09933ea commit e020be0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
33 changes: 7 additions & 26 deletions integration/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package integration_test

import (
"fmt"
"go/build"
"io"
"log"
"os"
Expand All @@ -20,26 +19,19 @@ func runTests(t *testing.T, when spec.G, it spec.S) {
log.SetOutput(io.Discard) // Comment this out to see verbose log output
log.SetFlags(log.Llongfile)
var (
baseDir string
relativeDir string
originalGopath string
originalBuildGopath string
originalGo111module string
testDir string
copyDirFunc func()
copyFileFunc func(name string)
initModuleFunc func()
writeToTestData bool
baseDir string
relativeDir string
testDir string
copyDirFunc func()
copyFileFunc func(name string)
initModuleFunc func()
writeToTestData bool
)

name := "working with a module"

it.Before(func() {
RegisterTestingT(t)
originalGo111module = os.Getenv("GO111MODULE")
os.Setenv("GO111MODULE", "on")
originalGopath = os.Getenv("GOPATH")
originalBuildGopath = build.Default.GOPATH
var err error
testDir, err = os.MkdirTemp("", "counterfeiter-integration")
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -79,17 +71,6 @@ func runTests(t *testing.T, when spec.G, it spec.S) {
})

it.After(func() {
if originalGo111module != "" {
os.Setenv("GO111MODULE", originalGo111module)
} else {
os.Unsetenv("GO111MODULE")
}
if originalGopath != "" {
os.Setenv("GOPATH", originalGopath)
} else {
os.Unsetenv("GOPATH")
}
build.Default.GOPATH = originalBuildGopath
if baseDir == "" {
return
}
Expand Down
19 changes: 11 additions & 8 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,34 @@ set -eu
cd "$(dirname "$0")/.."
pwd

# run go vet to verify everything builds and to check common issues
GOCOMMAND="go"
# GOCOMMAND="go1.22rc1"

# run ${GOCOMMAND} vet to verify everything builds and to check common issues
echo
echo "Running go vet..."
echo "Running ${GOCOMMAND} vet..."
echo
GO111MODULE=on go vet ./...
${GOCOMMAND} vet ./...

# counterfeit all the things
echo
echo "Installing counterfeiter..."
echo
GO111MODULE=on go install .
${GOCOMMAND} install .

# counterfeit all the things
echo
echo "Generating fakes used by tests..."
echo
GO111MODULE=on go generate ./...
${GOCOMMAND} generate ./...

# validate that the generated fakes match the committed fakes
echo
echo "Validating that generated fakes have not changed..."
echo
git diff --exit-code
if output=$(git status --porcelain) && [ ! -z "$output" ]; then
echo "the working copy is not clean; make sure that go generate ./... has been run, and"
echo "the working copy is not clean; make sure that ${GOCOMMAND} generate ./... has been run, and"
echo "that you have committed or ignored all files before running ./scripts/ci.sh"
exit 1
fi
Expand All @@ -38,13 +41,13 @@ fi
echo
echo "Ensuring generated fakes compile..."
echo
GO111MODULE=on go build -v ./...
${GOCOMMAND} build -v ./...

# run the tests using the fakes
echo
echo "Running tests..."
echo
GO111MODULE=on go test -race ./...
${GOCOMMAND} test -race ./...

echo "
_______ _ _ _______ _______ _______
Expand Down

0 comments on commit e020be0

Please sign in to comment.