github.com/criyle/go-sandbox@v0.10.3/pkg/unixsocket/socket_linux_test.go (about)

     1  package unixsocket
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  )
     7  
     8  func TestBaseline(t *testing.T) {
     9  	a, b, err := NewSocketPair()
    10  	if err != nil {
    11  		t.Fatal(err)
    12  	}
    13  	m := make([]byte, 1024)
    14  
    15  	go func() {
    16  		msg := []byte("message")
    17  		a.SendMsg(msg, Msg{})
    18  	}()
    19  
    20  	n, _, err := b.RecvMsg(m)
    21  	if err != nil {
    22  		t.Fatal(err)
    23  	}
    24  
    25  	if !bytes.Equal(m[:n], []byte("message")) {
    26  		t.Fatal("not equal")
    27  	}
    28  }