magnetico/magneticod/dht/mainline/transport_test.go
Bora Alper ae691ada79 started cleaning up for v0.7.0
I've decided instead to release a minimum viable product for v0.7.0 and
get some feedback from the community, and most importantly some
motivation as well to be able to keep working on magnetico as it
currently feels like a Sisyphean where the development seem to never
going to end...
2017-11-02 23:15:13 +00:00

54 lines
1.2 KiB
Go

package mainline
import (
"net"
"strings"
"testing"
)
func TestReadFromOnClosedConn(t *testing.T) {
// Initialization
laddr, err := net.ResolveUDPAddr("udp", "0.0.0.0:0")
if err != nil {
t.Skipf("Skipping due to an error during initialization!")
}
conn, err := net.ListenUDP("udp", laddr)
if err != nil {
t.Skipf("Skipping due to an error during initialization!")
}
buffer := make([]byte, 65536)
// Setting Up
conn.Close()
// Testing
_, _, err = conn.ReadFrom(buffer)
if !(err != nil && strings.HasSuffix(err.Error(), "use of closed network connection")) {
t.Fatalf("Unexpected suffix in the error message!")
}
}
func TestWriteToOnClosedConn(t *testing.T) {
// Initialization
laddr, err := net.ResolveUDPAddr("udp", "0.0.0.0:0")
if err != nil {
t.Skipf("Skipping due to an error during initialization!")
}
conn, err := net.ListenUDP("udp", laddr)
if err != nil {
t.Skipf("Skipping due to an error during initialization!")
}
// Setting Up
conn.Close()
// Testing
_, err = conn.WriteTo([]byte("estarabim"), laddr)
if !(err != nil && strings.HasSuffix(err.Error(), "use of closed network connection")) {
t.Fatalf("Unexpected suffix in the error message!")
}
}