Skip to content

Commit

Permalink
[net] Skip tests on non-implemented platforms shirou#446
Browse files Browse the repository at this point in the history
  • Loading branch information
Lomanic committed Aug 29, 2020
1 parent ea86cbc commit ab084b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 15 additions & 0 deletions net/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -113,6 +122,7 @@ func TestGetNetIOCountersAll(t *testing.T) {
},
}
ret, err := getIOCountersAll(n)
skipIfNotImplementedErr(t, err)
if err != nil {
t.Error(err)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions net/net_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package net

import (
"context"
"errors"
"fmt"
"net"
"os"
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down

0 comments on commit ab084b5

Please sign in to comment.