Merge pull request #989 from Lomanic/issue734tests

[ci] Implement automatic tests on GH Actions on linux, windows and darwin
pull/1001/head
shirou 5 years ago committed by GitHub
commit 6286bea32a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,91 @@
on: [push, pull_request]
name: Test
jobs:
test_v3_module:
strategy:
matrix:
go-version: [1.12.x, 1.14.x, 1.15.x]
os: [ubuntu-18.04, ubuntu-16.04, windows-2019, windows-2016, macOS-10.14, macos-11.0]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: |
cd ./v3/
go test ./...
test_v3_gopath:
env:
GOPATH: ${{ github.workspace }}
GO111MODULE: off
strategy:
matrix:
go-version: [1.13.x, 1.14.x, 1.15.x]
os: [ubuntu-18.04, ubuntu-16.04, windows-2019, windows-2016, macOS-10.14, macos-11.0]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
with:
path: ${{ github.workspace }}/src/github.com/shirou/gopsutil
- name: Get dependencies
run: |
go get -t github.com/shirou/gopsutil/v3/...
- name: Test
run: |
go test github.com/shirou/gopsutil/v3/...
test_v2_gopath:
env:
GOPATH: ${{ github.workspace }}
GO111MODULE: off
strategy:
matrix:
go-version: [1.12.x, 1.14.x, 1.15.x]
os: [ubuntu-18.04, ubuntu-16.04, windows-2019, windows-2016, macOS-10.14, macos-11.0]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
with:
path: ${{ github.workspace }}/src/github.com/shirou/gopsutil
- name: Get dependencies
if: runner.os == 'Windows'
run: |
go get -d -u github.com/golang/dep
cd $Env:GOPATH/src/github.com/golang/dep
git checkout v0.5.4
go install -ldflags="-X main.version=v0.5.4" ./cmd/dep
echo "$Env:GOPATH/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
cd $Env:GOPATH/src/github.com/shirou/gopsutil
dep ensure
# exclude v3 from being run with ./...
try { rm -ErrorAction:Stop -Recurse -Force $Env:GOPATH/src/github.com/shirou/gopsutil/v3 } catch [System.Management.Automation.ItemNotFoundException] {}
- name: Get dependencies
if: runner.os != 'Windows'
run: |
if ! command -v dep &>/dev/null; then
mkdir -p $GOPATH/bin
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
echo "PATH=$GOPATH/bin:$PATH" >> $GITHUB_PATH
fi
cd $GOPATH/src/github.com/shirou/gopsutil
dep ensure
# exclude v3 from being run with ./...
rm -rf $GOPATH/src/github.com/shirou/gopsutil/v3
- name: Test
run: |
go test github.com/shirou/gopsutil/...

@ -269,7 +269,7 @@ func FilterCounters() ([]FilterStat, error) {
}
func FilterCountersWithContext(ctx context.Context) ([]FilterStat, error) {
return nil, errors.New("NetFilterCounters not implemented for darwin")
return nil, common.ErrNotImplementedError
}
func ConntrackStats(percpu bool) ([]ConntrackStat, error) {
@ -289,5 +289,5 @@ func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
}
func ProtoCountersWithContext(ctx context.Context, protocols []string) ([]ProtoCountersStat, error) {
return nil, errors.New("NetProtoCounters not implemented for darwin")
return nil, common.ErrNotImplementedError
}

@ -40,12 +40,12 @@ func TestParseNetstatLineHeader(t *testing.T) {
func assertLoopbackStat(t *testing.T, err error, stat *IOCountersStat) {
assert.NoError(t, err)
assert.Equal(t, 869107, stat.PacketsRecv)
assert.Equal(t, 0, stat.Errin)
assert.Equal(t, 169411755, stat.BytesRecv)
assert.Equal(t, 869108, stat.PacketsSent)
assert.Equal(t, 1, stat.Errout)
assert.Equal(t, 169411756, stat.BytesSent)
assert.Equal(t, uint64(869107), stat.PacketsRecv)
assert.Equal(t, uint64(0), stat.Errin)
assert.Equal(t, uint64(169411755), stat.BytesRecv)
assert.Equal(t, uint64(869108), stat.PacketsSent)
assert.Equal(t, uint64(1), stat.Errout)
assert.Equal(t, uint64(169411756), stat.BytesSent)
}
func TestParseNetstatLineLink(t *testing.T) {

@ -4,7 +4,6 @@ package net
import (
"context"
"errors"
"os/exec"
"strconv"
"strings"
@ -109,7 +108,7 @@ func FilterCounters() ([]FilterStat, error) {
}
func FilterCountersWithContext(ctx context.Context) ([]FilterStat, error) {
return nil, errors.New("NetFilterCounters not implemented for freebsd")
return nil, common.ErrNotImplementedError
}
func ConntrackStats(percpu bool) ([]ConntrackStat, error) {
@ -117,7 +116,7 @@ func ConntrackStats(percpu bool) ([]ConntrackStat, error) {
}
func ConntrackStatsWithContext(ctx context.Context, percpu bool) ([]ConntrackStat, error) {
return nil, errors.New("ConntrackStats not implemented for freebsd")
return nil, common.ErrNotImplementedError
}
// NetProtoCounters returns network statistics for the entire system
@ -129,5 +128,5 @@ func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
}
func ProtoCountersWithContext(ctx context.Context, protocols []string) ([]ProtoCountersStat, error) {
return nil, errors.New("NetProtoCounters not implemented for freebsd")
return nil, common.ErrNotImplementedError
}

@ -146,20 +146,18 @@ func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) {
}
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
rr, err := common.CallLsofWithContext(ctx, invoke, p.Pid, "-FR")
out, err := common.CallLsofWithContext(ctx, invoke, p.Pid, "-FR")
if err != nil {
return nil, err
}
for _, r := range rr {
if strings.HasPrefix(r, "p") { // skip if process
continue
}
l := string(r)
v, err := strconv.Atoi(strings.Replace(l, "R", "", 1))
if err != nil {
return nil, err
for _, line := range out {
if len(line) >= 1 && line[0] == 'R' {
v, err := strconv.Atoi(line[1:])
if err != nil {
return nil, err
}
return NewProcessWithContext(ctx, int32(v))
}
return NewProcessWithContext(ctx, int32(v))
}
return nil, fmt.Errorf("could not find parent line")
}
@ -212,17 +210,18 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
}
func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
k, err := p.getKProc()
if err != nil {
return nil, err
}
return nil, common.ErrNotImplementedError
// k, err := p.getKProc()
// if err != nil {
// return nil, err
// }
groups := make([]int32, k.Eproc.Ucred.Ngroups)
for i := int16(0); i < k.Eproc.Ucred.Ngroups; i++ {
groups[i] = int32(k.Eproc.Ucred.Groups[i])
}
// groups := make([]int32, k.Eproc.Ucred.Ngroups)
// for i := int16(0); i < k.Eproc.Ucred.Ngroups; i++ {
// groups[i] = int32(k.Eproc.Ucred.Groups[i])
// }
return groups, nil
// return groups, nil
}
func (p *Process) TerminalWithContext(ctx context.Context) (string, error) {

@ -244,7 +244,7 @@ func Test_Process_Nice(t *testing.T) {
if err != nil {
t.Errorf("getting nice error %v", err)
}
if n != 0 && n != 20 && n != 8 {
if runtime.GOOS != "windows" && n != 0 && n != 20 && n != 8 {
t.Errorf("invalid nice: %d", n)
}
}

@ -269,7 +269,7 @@ func FilterCounters() ([]FilterStat, error) {
}
func FilterCountersWithContext(ctx context.Context) ([]FilterStat, error) {
return nil, errors.New("NetFilterCounters not implemented for darwin")
return nil, common.ErrNotImplementedError
}
func ConntrackStats(percpu bool) ([]ConntrackStat, error) {
@ -289,5 +289,5 @@ func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
}
func ProtoCountersWithContext(ctx context.Context, protocols []string) ([]ProtoCountersStat, error) {
return nil, errors.New("NetProtoCounters not implemented for darwin")
return nil, common.ErrNotImplementedError
}

@ -40,12 +40,12 @@ func TestParseNetstatLineHeader(t *testing.T) {
func assertLoopbackStat(t *testing.T, err error, stat *IOCountersStat) {
assert.NoError(t, err)
assert.Equal(t, 869107, stat.PacketsRecv)
assert.Equal(t, 0, stat.Errin)
assert.Equal(t, 169411755, stat.BytesRecv)
assert.Equal(t, 869108, stat.PacketsSent)
assert.Equal(t, 1, stat.Errout)
assert.Equal(t, 169411756, stat.BytesSent)
assert.Equal(t, uint64(869107), stat.PacketsRecv)
assert.Equal(t, uint64(0), stat.Errin)
assert.Equal(t, uint64(169411755), stat.BytesRecv)
assert.Equal(t, uint64(869108), stat.PacketsSent)
assert.Equal(t, uint64(1), stat.Errout)
assert.Equal(t, uint64(169411756), stat.BytesSent)
}
func TestParseNetstatLineLink(t *testing.T) {

@ -4,7 +4,6 @@ package net
import (
"context"
"errors"
"os/exec"
"strconv"
"strings"
@ -109,7 +108,7 @@ func FilterCounters() ([]FilterStat, error) {
}
func FilterCountersWithContext(ctx context.Context) ([]FilterStat, error) {
return nil, errors.New("NetFilterCounters not implemented for freebsd")
return nil, common.ErrNotImplementedError
}
func ConntrackStats(percpu bool) ([]ConntrackStat, error) {
@ -117,7 +116,7 @@ func ConntrackStats(percpu bool) ([]ConntrackStat, error) {
}
func ConntrackStatsWithContext(ctx context.Context, percpu bool) ([]ConntrackStat, error) {
return nil, errors.New("ConntrackStats not implemented for freebsd")
return nil, common.ErrNotImplementedError
}
// NetProtoCounters returns network statistics for the entire system
@ -129,5 +128,5 @@ func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
}
func ProtoCountersWithContext(ctx context.Context, protocols []string) ([]ProtoCountersStat, error) {
return nil, errors.New("NetProtoCounters not implemented for freebsd")
return nil, common.ErrNotImplementedError
}

@ -146,20 +146,18 @@ func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) {
}
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
rr, err := common.CallLsofWithContext(ctx, invoke, p.Pid, "-FR")
out, err := common.CallLsofWithContext(ctx, invoke, p.Pid, "-FR")
if err != nil {
return nil, err
}
for _, r := range rr {
if strings.HasPrefix(r, "p") { // skip if process
continue
}
l := string(r)
v, err := strconv.Atoi(strings.Replace(l, "R", "", 1))
if err != nil {
return nil, err
for _, line := range out {
if len(line) >= 1 && line[0] == 'R' {
v, err := strconv.Atoi(line[1:])
if err != nil {
return nil, err
}
return NewProcessWithContext(ctx, int32(v))
}
return NewProcessWithContext(ctx, int32(v))
}
return nil, fmt.Errorf("could not find parent line")
}
@ -212,17 +210,18 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
}
func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
k, err := p.getKProc()
if err != nil {
return nil, err
}
return nil, common.ErrNotImplementedError
// k, err := p.getKProc()
// if err != nil {
// return nil, err
// }
groups := make([]int32, k.Eproc.Ucred.Ngroups)
for i := int16(0); i < k.Eproc.Ucred.Ngroups; i++ {
groups[i] = int32(k.Eproc.Ucred.Groups[i])
}
// groups := make([]int32, k.Eproc.Ucred.Ngroups)
// for i := int16(0); i < k.Eproc.Ucred.Ngroups; i++ {
// groups[i] = int32(k.Eproc.Ucred.Groups[i])
// }
return groups, nil
// return groups, nil
}
func (p *Process) TerminalWithContext(ctx context.Context) (string, error) {

@ -198,8 +198,8 @@ func Test_Process_Status(t *testing.T) {
if len(v) == 0 {
t.Errorf("could not get state")
}
if v[0] != "R" && v[0] != "S" {
t.Errorf("get wrong state, %v", v)
if v[0] != Running && v[0] != Sleep {
t.Errorf("got wrong state, %v", v)
}
}
@ -247,7 +247,7 @@ func Test_Process_Nice(t *testing.T) {
if err != nil {
t.Errorf("getting nice error %v", err)
}
if n != 0 && n != 20 && n != 8 {
if runtime.GOOS != "windows" && n != 0 && n != 20 && n != 8 {
t.Errorf("invalid nice: %d", n)
}
}

@ -0,0 +1,10 @@
PID
245
247
248
249
254
262
264
265
267
Loading…
Cancel
Save