Test for Devices
Go / lint (push) Failing after 49s Details
Go / build (push) Failing after 3m23s Details

This commit is contained in:
Marcel M. Otte 2023-09-10 23:10:10 +02:00
parent 31f4331079
commit 608122e5a1
3 changed files with 66 additions and 4 deletions

View File

@ -4,8 +4,8 @@ import (
"net"
)
// [impl->dsn~low-level-abstraction~0]
// [impl->dsn~list-devices~0]
// [impl->dsn~low-level-abstraction~0>>utest]
// [impl->dsn~list-devices~0>>utest]
// Transmitter interface for sending packets
type Transmitter interface {

View File

@ -1,6 +1,6 @@
package devices
// [impllnx dsn~low-level-abstraction~0]
// [impllnx dsn~low-level-abstraction~0>>utest]
import "golang.org/x/sys/unix"
@ -11,7 +11,8 @@ type TransmitterLinux struct {
// Send implements sending packets on Linux
func (tl TransmitterLinux) Send(data []byte) error {
return nil
err := unix.Send(tl.socket, data, 0)
return err
}
// Close closes the transmitter socket
@ -32,5 +33,6 @@ func CreateTransmitter(device string) (Transmitter, error) {
// CreateReceiver creates and starts the Receiver instance
func CreateReceiver(device string) (Receiver, error) {
//TODO
return nil, nil
}

60
devices/devices_test.go Normal file
View File

@ -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()
}
}