Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pointer: Add generic Pointer func #239

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 18 additions & 16 deletions .github/workflows/test.yml
Expand Up @@ -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 ./...
Expand All @@ -24,45 +24,47 @@ 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
lint:
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"
Expand Down
8 changes: 7 additions & 1 deletion go.mod
@@ -1,10 +1,16 @@
module k8s.io/utils

go 1.12
go 1.18

require (
github.com/davecgh/go-spew v1.1.1
github.com/spf13/afero v1.2.2
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
)
11 changes: 10 additions & 1 deletion inotify/inotify_linux_test.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}()

Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions internal/third_party/forked/golang/net/ip.go
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions internal/third_party/forked/golang/net/ip_test.go
Expand Up @@ -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)
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions pointer/generic.go
@@ -0,0 +1,5 @@
package pointer

func Pointer[T any](in T) *T {
return &in
}
10 changes: 10 additions & 0 deletions 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)
}
}