mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-26 13:48:59 +08:00
[net] Skip tests on non-implemented platforms #446
This commit is contained in:
parent
ea86cbc3ff
commit
ab084b525c
@ -9,6 +9,12 @@ import (
|
||||
"github.com/shirou/gopsutil/internal/common"
|
||||
)
|
||||
|
||||
func skipIfNotImplementedErr(t *testing.T, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddrString(t *testing.T) {
|
||||
v := Addr{IP: "192.168.0.1", Port: 8000}
|
||||
|
||||
@ -61,10 +67,12 @@ func TestNetConnectionStatString(t *testing.T) {
|
||||
|
||||
func TestNetIOCountersAll(t *testing.T) {
|
||||
v, err := IOCounters(false)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("Could not get NetIOCounters: %v", err)
|
||||
}
|
||||
per, err := IOCounters(true)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("Could not get NetIOCounters: %v", err)
|
||||
}
|
||||
@ -85,6 +93,7 @@ func TestNetIOCountersAll(t *testing.T) {
|
||||
|
||||
func TestNetIOCountersPerNic(t *testing.T) {
|
||||
v, err := IOCounters(true)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("Could not get NetIOCounters: %v", err)
|
||||
}
|
||||
@ -113,6 +122,7 @@ func TestGetNetIOCountersAll(t *testing.T) {
|
||||
},
|
||||
}
|
||||
ret, err := getIOCountersAll(n)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -132,6 +142,7 @@ func TestGetNetIOCountersAll(t *testing.T) {
|
||||
|
||||
func TestNetInterfaces(t *testing.T) {
|
||||
v, err := Interfaces()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("Could not get NetInterfaceStat: %v", err)
|
||||
}
|
||||
@ -147,6 +158,7 @@ func TestNetInterfaces(t *testing.T) {
|
||||
|
||||
func TestNetProtoCountersStatsAll(t *testing.T) {
|
||||
v, err := ProtoCounters(nil)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not get NetProtoCounters: %v", err)
|
||||
}
|
||||
@ -165,6 +177,7 @@ func TestNetProtoCountersStatsAll(t *testing.T) {
|
||||
|
||||
func TestNetProtoCountersStats(t *testing.T) {
|
||||
v, err := ProtoCounters([]string{"tcp", "ip"})
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not get NetProtoCounters: %v", err)
|
||||
}
|
||||
@ -190,6 +203,7 @@ func TestNetConnections(t *testing.T) {
|
||||
}
|
||||
|
||||
v, err := Connections("inet")
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("could not get NetConnections: %v", err)
|
||||
}
|
||||
@ -217,6 +231,7 @@ func TestNetFilterCounters(t *testing.T) {
|
||||
}
|
||||
|
||||
v, err := FilterCounters()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("could not get NetConnections: %v", err)
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ package net
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
@ -323,7 +322,7 @@ func FilterCounters() ([]FilterStat, error) {
|
||||
}
|
||||
|
||||
func FilterCountersWithContext(ctx context.Context) ([]FilterStat, error) {
|
||||
return nil, errors.New("NetFilterCounters not implemented for windows")
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func ConntrackStats(percpu bool) ([]ConntrackStat, error) {
|
||||
@ -344,7 +343,7 @@ func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
|
||||
}
|
||||
|
||||
func ProtoCountersWithContext(ctx context.Context, protocols []string) ([]ProtoCountersStat, error) {
|
||||
return nil, errors.New("NetProtoCounters not implemented for windows")
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func getTableUintptr(family uint32, buf []byte) uintptr {
|
||||
|
Loading…
x
Reference in New Issue
Block a user