Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Feb 1, 2024
1 parent 1112e53 commit 35074d1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/goproxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ jobs:
with:
go-version: "${{ matrix.goversion }}"

# Verify that we can build when using the goproxy subcommand
- run: go run ./internal/cmd/buildtool goproxy go run ./internal/cmd/buildtool generic miniooni
9 changes: 1 addition & 8 deletions internal/cmd/buildtool/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main
//

import (
"os"
"strings"

"github.com/apex/log"
Expand All @@ -27,15 +26,9 @@ func golangCorrectVersionCheckP(filename string) bool {
return true
}

// golangOsExit allows to test that [golangCheck] invokes [os.Exit] with exit code 1
// whenever the version of golang is not the intended one.
var golangOsExit = os.Exit

// golangCheck checks whether the "go" binary is the correct version
func golangCheck(filename string) {
if !golangCorrectVersionCheckP(filename) {
golangOsExit(1)
}
runtimex.Assert(golangCorrectVersionCheckP(filename), "invalid Go version")
}

// golangGOPATH returns the GOPATH value.
Expand Down
21 changes: 19 additions & 2 deletions internal/cmd/buildtool/golang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ import (
)

func TestGolangCheck(t *testing.T) {
// make sure the code does not panic when it runs
golangCheck(filepath.Join("..", "..", "..", "GOVERSION"))
t.Run("successful case", func(t *testing.T) {
// make sure the code does not panic when it runs
golangCheck(filepath.Join("..", "..", "..", "GOVERSION"))
})

t.Run("invalid Go version", func(t *testing.T) {
var panicked bool
func() {
defer func() {
if recover() != nil {
panicked = true
}
}()
golangCheck(filepath.Join("testdata", "GOVERSION"))
}()
if !panicked {
t.Fatal("should have panicked")
}
})
}
1 change: 1 addition & 0 deletions internal/cmd/buildtool/testdata/GOVERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.17.11

0 comments on commit 35074d1

Please sign in to comment.