github.com/tetratelabs/wazero@v1.2.1/imports/wasi_snapshot_preview1/sock_unit_test.go (about)

     1  package wasi_snapshot_preview1
     2  
     3  import (
     4  	"os"
     5  	"syscall"
     6  	"testing"
     7  
     8  	"github.com/tetratelabs/wazero/internal/fsapi"
     9  	"github.com/tetratelabs/wazero/internal/sock"
    10  	"github.com/tetratelabs/wazero/internal/testing/require"
    11  	"github.com/tetratelabs/wazero/internal/wasip1"
    12  )
    13  
    14  func Test_getExtendedWasiFiletype(t *testing.T) {
    15  	s := testSock{}
    16  	ftype := getExtendedWasiFiletype(s, os.ModeIrregular)
    17  	require.Equal(t, wasip1.FILETYPE_SOCKET_STREAM, ftype)
    18  
    19  	c := testConn{}
    20  	ftype = getExtendedWasiFiletype(c, os.ModeIrregular)
    21  	require.Equal(t, wasip1.FILETYPE_SOCKET_STREAM, ftype)
    22  }
    23  
    24  type testSock struct {
    25  	fsapi.UnimplementedFile
    26  }
    27  
    28  func (t testSock) Accept() (sock.TCPConn, syscall.Errno) {
    29  	panic("no-op")
    30  }
    31  
    32  type testConn struct {
    33  	fsapi.UnimplementedFile
    34  }
    35  
    36  func (t testConn) Recvfrom([]byte, int) (n int, errno syscall.Errno) {
    37  	panic("no-op")
    38  }
    39  
    40  func (t testConn) Shutdown(int) syscall.Errno {
    41  	panic("no-op")
    42  }