diff --git a/.circleci/config.yml b/.circleci/config.yml index 1131415..37a02fc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,7 @@ version: 2.1 jobs: test: docker: - - image: circleci/golang:1.11 + - image: circleci/golang:1.14 working_directory: /home/circleci/go/src/github.com/shirou/gopsutil environment: GOPATH: /home/circleci/go @@ -19,7 +19,7 @@ jobs: - run: command: dep ensure - run: - command: go build -v + command: make vet - run: command: make build_test macos: diff --git a/Makefile b/Makefile index 1dc5e72..7a540a9 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,35 @@ ifeq ($(shell uname -s), Darwin) endif @echo 'Successfully built on all known operating systems' +vet: + GOOS=darwin GOARCH=amd64 go vet ./... + GOOS=darwin GOARCH=386 go vet ./... + GOOS=darwin GOARCH=arm64 go vet ./... + + GOOS=dragonfly GOARCH=amd64 go vet ./... + + GOOS=freebsd GOARCH=amd64 go vet ./... + GOOS=freebsd GOARCH=386 go vet ./... + GOOS=freebsd GOARCH=arm go vet ./... + + GOOS=linux GOARCH=386 go vet ./... + GOOS=linux GOARCH=amd64 go vet ./... + GOOS=linux GOARCH=arm64 go vet ./... + GOOS=linux GOARCH=arm go vet ./... + GOOS=linux GOARCH=mips64 go vet ./... + GOOS=linux GOARCH=mips64le go vet ./... + GOOS=linux GOARCH=mips go vet ./... + GOOS=linux GOARCH=mipsle go vet ./... + GOOS=linux GOARCH=ppc64le go vet ./... + GOOS=linux GOARCH=riscv64 go vet ./... + GOOS=linux GOARCH=s390x go vet ./... + + GOOS=netbsd GOARCH=amd64 go vet ./... + GOOS=solaris GOARCH=amd64 go vet ./... + + GOOS=windows GOARCH=amd64 go vet ./... + GOOS=windows GOARCH=386 go vet ./... + macos_test: CGO_ENABLED=0 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) diff --git a/disk/disk_windows.go b/disk/disk_windows.go index f871e9d..a77a15b 100644 --- a/disk/disk_windows.go +++ b/disk/disk_windows.go @@ -155,7 +155,7 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC } for _, v := range lpBuffer[:lpBufferLen] { if 'A' <= v && v <= 'Z' { - path := string(v) + ":" + path := string(rune(v)) + ":" typepath, _ := windows.UTF16PtrFromString(path) typeret := windows.GetDriveType(typepath) if typeret == 0 { diff --git a/internal/common/common.go b/internal/common/common.go index 57e291b..ebf70ea 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -326,7 +326,6 @@ func GetEnv(key string, dfault string, combineWith ...string) string { copy(all[1:], combineWith) return filepath.Join(all...) } - panic("invalid switch case") } func HostProc(combineWith ...string) string { diff --git a/internal/common/common_test.go b/internal/common/common_test.go index 3d6ae10..b0e051c 100644 --- a/internal/common/common_test.go +++ b/internal/common/common_test.go @@ -57,19 +57,19 @@ func TestHexToUint32(t *testing.T) { } } -func TestmustParseInt32(t *testing.T) { +func TestMustParseInt32(t *testing.T) { ret := mustParseInt32("11111") if ret != int32(11111) { t.Error("could not parse") } } -func TestmustParseUint64(t *testing.T) { +func TestMustParseUint64(t *testing.T) { ret := mustParseUint64("11111") if ret != uint64(11111) { t.Error("could not parse") } } -func TestmustParseFloat64(t *testing.T) { +func TestMustParseFloat64(t *testing.T) { ret := mustParseFloat64("11111.11") if ret != float64(11111.11) { t.Error("could not parse") diff --git a/net/net_darwin_test.go b/net/net_darwin_test.go index e4c33bb..f5e5a47 100644 --- a/net/net_darwin_test.go +++ b/net/net_darwin_test.go @@ -30,7 +30,7 @@ en0 1500 a8:66:7f:dd:ee:ff 5708989 0 7295722068 3494252 en0 1500 fe80::aa66: fe80:4::aa66:7fff 5708989 - 7295722068 3494252 - 379533492 - -` ) -func TestparseNetstatLineHeader(t *testing.T) { +func TestParseNetstatLineHeader(t *testing.T) { stat, linkIkd, err := parseNetstatLine(`Name Mtu Network Address Ipkts Ierrs Ibytes Opkts Oerrs Obytes Coll Drop`) assert.Nil(t, linkIkd) assert.Nil(t, stat) @@ -48,7 +48,7 @@ func assertLoopbackStat(t *testing.T, err error, stat *IOCountersStat) { assert.Equal(t, 169411756, stat.BytesSent) } -func TestparseNetstatLineLink(t *testing.T) { +func TestParseNetstatLineLink(t *testing.T) { stat, linkID, err := parseNetstatLine( `lo0 16384 869107 0 169411755 869108 1 169411756 0 0`, ) @@ -57,7 +57,7 @@ func TestparseNetstatLineLink(t *testing.T) { assert.Equal(t, uint(1), *linkID) } -func TestparseNetstatLineIPv6(t *testing.T) { +func TestParseNetstatLineIPv6(t *testing.T) { stat, linkID, err := parseNetstatLine( `lo0 16384 ::1/128 ::1 869107 - 169411755 869108 1 169411756 - -`, ) @@ -65,7 +65,7 @@ func TestparseNetstatLineIPv6(t *testing.T) { assert.Nil(t, linkID) } -func TestparseNetstatLineIPv4(t *testing.T) { +func TestParseNetstatLineIPv4(t *testing.T) { stat, linkID, err := parseNetstatLine( `lo0 16384 127 127.0.0.1 869107 - 169411755 869108 1 169411756 - -`, ) diff --git a/process/process_windows.go b/process/process_windows.go index f5ad7d7..6c91120 100644 --- a/process/process_windows.go +++ b/process/process_windows.go @@ -712,7 +712,7 @@ func (p *Process) SuspendWithContext(ctx context.Context) error { } defer windows.CloseHandle(c) - r1, _, _ := procNtSuspendProcess.Call(uintptr(unsafe.Pointer(c))) + r1, _, _ := procNtSuspendProcess.Call(uintptr(c)) if r1 != 0 { // See https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55 return fmt.Errorf("NtStatus='0x%.8X'", r1) @@ -732,7 +732,7 @@ func (p *Process) ResumeWithContext(ctx context.Context) error { } defer windows.CloseHandle(c) - r1, _, _ := procNtResumeProcess.Call(uintptr(unsafe.Pointer(c))) + r1, _, _ := procNtResumeProcess.Call(uintptr(c)) if r1 != 0 { // See https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55 return fmt.Errorf("NtStatus='0x%.8X'", r1)