diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8031d8f6..ff20039b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,16 +4,16 @@ jobs: build: strategy: matrix: - go-versions: [1.13.x] + go-versions: [1.18.x] platform: [windows-latest] runs-on: ${{ matrix.platform }} steps: - name: Install Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v3 with: - go-version: ${{ matrix.go-version }} + go-version: ${{ matrix.go-versions }} - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Build run: | go build ./... @@ -24,16 +24,16 @@ jobs: test: strategy: matrix: - go-versions: [1.12.x, 1.13.x, 1.14.x] + go-versions: [1.18.x] platform: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.platform }} steps: - name: Install Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v3 with: - go-version: ${{ matrix.go-version }} + go-version: ${{ matrix.go-versions }} - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Test run: | make test @@ -41,28 +41,30 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v3 + with: + go-version: 1.18.x - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Lint run: | - docker run --rm -v `pwd`:/go/src/k8s.io/klog -w /go/src/k8s.io/klog \ - golangci/golangci-lint:v1.23.8 golangci-lint run --disable-all -v \ + docker run --rm -v `pwd`:/go/src/k8s.io/util -w /go/src/k8s.io/util \ + golangci/golangci-lint:v1.45.0 golangci-lint run --go 1.18 --disable-all -v \ -E govet -E misspell -E gofmt -E ineffassign -E golint apidiff: runs-on: ubuntu-latest if: github.base_ref steps: - name: Install Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v3 with: - go-version: 1.13.x + go-version: 1.18.x - name: Add GOBIN to PATH run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH - name: Install dependencies - run: go get golang.org/x/exp/cmd/apidiff + run: go install golang.org/x/exp/cmd/apidiff@latest - name: Checkout old code - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: ${{ github.base_ref }} path: "old" diff --git a/go.mod b/go.mod index 71236960..41e29e24 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module k8s.io/utils -go 1.12 +go 1.18 require ( github.com/davecgh/go-spew v1.1.1 @@ -8,3 +8,9 @@ require ( github.com/stretchr/testify v1.3.0 k8s.io/klog/v2 v2.0.0 ) + +require ( + github.com/go-logr/logr v0.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/text v0.3.0 // indirect +) diff --git a/inotify/inotify_linux_test.go b/inotify/inotify_linux_test.go index cf56843f..dd5e662f 100644 --- a/inotify/inotify_linux_test.go +++ b/inotify/inotify_linux_test.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build linux // +build linux package inotify @@ -34,9 +35,11 @@ func TestInotifyEvents(t *testing.T) { } // Receive errors on the error channel on a separate goroutine + var watcherErrs []error go func() { for err := range watcher.Error { - t.Fatalf("error received: %s", err) + // Fatal inside a goroutine is not allowed + watcherErrs = append(watcherErrs, err) } }() @@ -82,6 +85,12 @@ func TestInotifyEvents(t *testing.T) { case <-time.After(1 * time.Second): t.Fatal("event stream was not closed after 1 second") } + + for _, err := range watcherErrs { + if err != nil { + t.Errorf("watcher had error: %v", err) + } + } } func TestInotifyClose(t *testing.T) { diff --git a/internal/third_party/forked/golang/net/ip.go b/internal/third_party/forked/golang/net/ip.go index 4340b6e7..9a3aea29 100644 --- a/internal/third_party/forked/golang/net/ip.go +++ b/internal/third_party/forked/golang/net/ip.go @@ -29,6 +29,19 @@ import ( // type IP = stdnet.IP + +func IPUnmarshalText(text []byte) (IP, error) { + if len(text) == 0 { + return nil, nil + } + s := string(text) + x := ParseIP(s) + if x == nil { + return nil, &ParseError{Type: "IP address", Text: s} + } + return x, nil +} + type IPNet = stdnet.IPNet type ParseError = stdnet.ParseError diff --git a/internal/third_party/forked/golang/net/ip_test.go b/internal/third_party/forked/golang/net/ip_test.go index 6271f4fc..7bc97236 100644 --- a/internal/third_party/forked/golang/net/ip_test.go +++ b/internal/third_party/forked/golang/net/ip_test.go @@ -80,9 +80,8 @@ func TestParseIP(t *testing.T) { // Tested in TestMarshalEmptyIP below. continue } - var out IP - if err := out.UnmarshalText([]byte(tt.in)); !reflect.DeepEqual(out, tt.out) || (tt.out == nil) != (err != nil) { - t.Errorf("IP.UnmarshalText(%q) = %v, %v, want %v", tt.in, out, err, tt.out) + if out, err := IPUnmarshalText([]byte(tt.in)); !reflect.DeepEqual(out, tt.out) || (tt.out == nil) != (err != nil) { + t.Errorf("IPUnmarshalText(%q) = %v, %v, want %v", tt.in, out, err, tt.out) } } } diff --git a/pointer/generic.go b/pointer/generic.go new file mode 100644 index 00000000..9757d8eb --- /dev/null +++ b/pointer/generic.go @@ -0,0 +1,5 @@ +package pointer + +func Pointer[T any](in T) *T { + return &in +} diff --git a/pointer/generic_test.go b/pointer/generic_test.go new file mode 100644 index 00000000..874e3314 --- /dev/null +++ b/pointer/generic_test.go @@ -0,0 +1,10 @@ +package pointer + +import "testing" + +func TestPointer(t *testing.T) { + ptr := Pointer(5) + if *ptr != 5 { + t.Errorf("expected pointer value to be 5, was %v", *ptr) + } +}