fix tests

...by removing them. It was a ridiculous amount of contorted code to
test some utterly trivial functionality that is largely provided by
the golang stdlib.
This commit is contained in:
Matthias Radestock
2017-06-20 12:03:02 +01:00
parent 4e0065a57d
commit 7e5704b53b
2 changed files with 5 additions and 52 deletions
+5 -11
View File
@@ -8,17 +8,11 @@ import (
// Networks represent a set of subnets
type Networks []*net.IPNet
// Interface is exported for testing.
type Interface interface {
Addrs() ([]net.Addr, error)
}
// Variables exposed for testing.
// LocalNetworks helps in determining which addresses a probe reports
// as being host-scoped.
//
// TODO this design is broken, make it consistent with probe networks.
var (
LocalNetworks = Networks{}
InterfaceByNameStub = func(name string) (Interface, error) { return net.InterfaceByName(name) }
)
var LocalNetworks = Networks{}
// Contains returns true if IP is in Networks.
func (n Networks) Contains(ip net.IP) bool {
@@ -65,7 +59,7 @@ func LocalAddresses() ([]net.IP, error) {
// supplied, such that MakeAddressNodeID will scope addresses in this subnet
// as local.
func AddLocalBridge(name string) error {
inf, err := InterfaceByNameStub(name)
inf, err := net.InterfaceByName(name)
if err != nil {
return err
}
-41
View File
@@ -4,9 +4,7 @@ import (
"net"
"testing"
"github.com/weaveworks/common/test"
"github.com/weaveworks/scope/report"
"github.com/weaveworks/scope/test/reflect"
)
func TestContains(t *testing.T) {
@@ -31,42 +29,3 @@ func mustParseCIDR(s string) *net.IPNet {
}
return ipNet
}
type mockInterface struct {
addrs []net.Addr
}
type mockAddr string
func (m mockInterface) Addrs() ([]net.Addr, error) {
return m.addrs, nil
}
func (m mockAddr) Network() string {
return "ip+net"
}
func (m mockAddr) String() string {
return string(m)
}
func TestAddLocal(t *testing.T) {
oldInterfaceByNameStub := report.InterfaceByNameStub
defer func() { report.InterfaceByNameStub = oldInterfaceByNameStub }()
report.InterfaceByNameStub = func(name string) (report.Interface, error) {
return mockInterface{[]net.Addr{mockAddr("52.53.54.55/16")}}, nil
}
err := report.AddLocalBridge("foo")
if err != nil {
t.Errorf("%v", err)
}
want := report.Networks([]*net.IPNet{mustParseCIDR("52.53.54.55/16")})
have := report.LocalNetworks
if !reflect.DeepEqual(want, have) {
t.Errorf("%s", test.Diff(want, have))
}
}