Test for Devices
This commit is contained in:
parent
31f4331079
commit
608122e5a1
|
@ -4,8 +4,8 @@ import (
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
// [impl->dsn~low-level-abstraction~0]
|
// [impl->dsn~low-level-abstraction~0>>utest]
|
||||||
// [impl->dsn~list-devices~0]
|
// [impl->dsn~list-devices~0>>utest]
|
||||||
|
|
||||||
// Transmitter interface for sending packets
|
// Transmitter interface for sending packets
|
||||||
type Transmitter interface {
|
type Transmitter interface {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package devices
|
package devices
|
||||||
|
|
||||||
// [impllnx dsn~low-level-abstraction~0]
|
// [impllnx dsn~low-level-abstraction~0>>utest]
|
||||||
|
|
||||||
import "golang.org/x/sys/unix"
|
import "golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
@ -11,7 +11,8 @@ type TransmitterLinux struct {
|
||||||
|
|
||||||
// Send implements sending packets on Linux
|
// Send implements sending packets on Linux
|
||||||
func (tl TransmitterLinux) Send(data []byte) error {
|
func (tl TransmitterLinux) Send(data []byte) error {
|
||||||
return nil
|
err := unix.Send(tl.socket, data, 0)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes the transmitter socket
|
// Close closes the transmitter socket
|
||||||
|
@ -32,5 +33,6 @@ func CreateTransmitter(device string) (Transmitter, error) {
|
||||||
|
|
||||||
// CreateReceiver creates and starts the Receiver instance
|
// CreateReceiver creates and starts the Receiver instance
|
||||||
func CreateReceiver(device string) (Receiver, error) {
|
func CreateReceiver(device string) (Receiver, error) {
|
||||||
|
//TODO
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
package devices_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gitea.mmo.to/ppForge/ppforge/devices"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestListDevices(t *testing.T) {
|
||||||
|
list, err := devices.List()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Got error: ", err)
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
fmt.Printf("%s", list)
|
||||||
|
lo_in_list := false
|
||||||
|
for _, e := range list {
|
||||||
|
if e == "lo" {
|
||||||
|
lo_in_list = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !lo_in_list {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetHardwareAddress(t *testing.T) {
|
||||||
|
list, err := devices.List()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Got error: ", err)
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
fmt.Printf("%s", list)
|
||||||
|
|
||||||
|
hwaddr, err := devices.GetHardwareAddress(list[1])
|
||||||
|
fmt.Println("Hardware address: ", hwaddr)
|
||||||
|
|
||||||
|
if hwaddr == "" || err != nil {
|
||||||
|
// might have catched lo ?
|
||||||
|
fmt.Println("catched 'lo'? or error: ", err)
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetAddresses(t *testing.T) {
|
||||||
|
list, err := devices.List()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Got error: ", err)
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
fmt.Printf("%s", list)
|
||||||
|
addrlist, err := devices.GetAddresses(list[1])
|
||||||
|
fmt.Println("Addresses: ", addrlist)
|
||||||
|
|
||||||
|
if len(addrlist) == 0 || err != nil {
|
||||||
|
fmt.Println("Addrlist empty? or error: ", err)
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue