Skip to content

Commit

Permalink
CI: test against go1.22 (#1195)
Browse files Browse the repository at this point in the history
This PR modifies CI to test against Go versions 1.21 and 1.22. To avoid
forcing users to upgrade to 1.21, I kept `go.mod` version at `1.20.`

Some tests had to be updated to pass in 1.22.

I can remove `stack_120_test.go` if there's a good argument for it, but
my thoughts are that we should have a complete & passing test suite for
every version >= `go.mod`'s version.
  • Loading branch information
JacobOaks committed Apr 29, 2024
1 parent 029720f commit 2379ac9
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest"]
go: ["1.20.x", "1.21.x"]
go: ["1.21.x", "1.22.x"]

steps:
- name: Checkout code
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Test
run: make cover COVER_MODULES=./docs
Expand All @@ -68,7 +68,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x
cache: false # managed by golangci-lint

- uses: golangci/golangci-lint-action@v5
Expand Down
41 changes: 41 additions & 0 deletions app_121_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2024 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build !go1.22
// +build !go1.22

package fx_test

import (
"testing"

"github.com/stretchr/testify/assert"

. "go.uber.org/fx"
)

func TestNopLoggerOptionString(t *testing.T) {
t.Parallel()

assert.Equal(t,
"fx.WithLogger(go.uber.org/fx.glob..func1())",
NopLogger.String(),
)
}
41 changes: 41 additions & 0 deletions app_122_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2024 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build go1.22
// +build go1.22

package fx_test

import (
"testing"

"github.com/stretchr/testify/assert"

. "go.uber.org/fx"
)

func TestNopLoggerOptionString(t *testing.T) {
t.Parallel()

assert.Equal(t,
"fx.WithLogger(go.uber.org/fx.init.func1())",
NopLogger.String(),
)
}
5 changes: 0 additions & 5 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2542,11 +2542,6 @@ func TestOptionString(t *testing.T) {
give: WithLogger(func() fxevent.Logger { return testLogger{t} }),
want: "fx.WithLogger(go.uber.org/fx_test.TestOptionString.func3())",
},
{
desc: "NopLogger",
give: NopLogger,
want: "fx.WithLogger(go.uber.org/fx.glob..func1())",
},
{
desc: "ErrorHook",
give: ErrorHook(testErrorHandler{t}),
Expand Down
4 changes: 2 additions & 2 deletions internal/fxreflect/stack_121_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build go1.21
// +build go1.21
//go:build (go1.21 && !go1.22)
// +build go1.21,!go1.22

package fxreflect

Expand Down
50 changes: 50 additions & 0 deletions internal/fxreflect/stack_122_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build go1.22
// +build go1.22

package fxreflect

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestDeepStack(t *testing.T) {
t.Run("nest", func(t *testing.T) {
// Introduce a few frames.
frames := func() []Frame {
return func() []Frame {
return CallerStack(0, 0)
}()
}()

require.True(t, len(frames) > 3, "expected at least three frames")
for i, name := range []string{"func1.TestDeepStack.func1.1.2", "func1.1", "func1"} {
f := frames[i]
assert.Equal(t, "go.uber.org/fx/internal/fxreflect.TestDeepStack."+name, f.Function)
assert.Contains(t, f.File, "internal/fxreflect/stack_122_test.go")
assert.NotZero(t, f.Line)
}
})
}

0 comments on commit 2379ac9

Please sign in to comment.