Commit 2a74249f authored by Boris Mühmer's avatar Boris Mühmer
Browse files

added tests for getting interfaces

parent a46c4047
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
package tdmbs

import "errors"

const (
	DefaultPortCommands           = 31285
	DefaultPortEvents             = 31286
	DefaultBroadcastDiscoveryText = "{362E4489-482E-4E45-B782-43F80FF58809}"
)

type Server struct {
}

func New() *Server {
	return &Server{}
}

func (s *Server) FindLocalNetworkAdresses() error {
	return errors.New("not implemented")
}

func (s *Server) FindWithBroadcast() error {
	return errors.New("not implemented")
}
+39 −3
Original line number Diff line number Diff line
package tdmbs

import "testing"
import (
	"net"
	"testing"
)

func TestSkip(t *testing.T) {
	t.Skip("not implemented")
func TestFindLocalNetworks(t *testing.T) {
	ifaces, err := net.Interfaces()
	if err != nil {
		t.Fatalf("net.Interfaces() failed with: %s", err)
	}

	for _, ifc := range ifaces {
		if (ifc.Flags & net.FlagLoopback) == net.FlagLoopback {
			continue
		}
		if (ifc.Flags & net.FlagUp) != net.FlagUp {
			continue
		}
		if (ifc.Flags & net.FlagPointToPoint) == net.FlagPointToPoint {
			continue
		}
		if (ifc.Flags & net.FlagBroadcast) != net.FlagBroadcast {
			continue
		}

		addrs, err := ifc.Addrs()
		if err != nil {
			t.Errorf("ifc.Addrs() failed with: %s", err)
			continue
		}

		if len(addrs) < 1 {
			continue
		}

		t.Logf("- %#v", ifc)
		for _, addr := range addrs {
			t.Logf("  - %s", addr)
		}
	}
}