github.com/anacrolix/torrent@v1.61.0/test/unix_test.go (about)

     1  package test
     2  
     3  import (
     4  	"io"
     5  	"log"
     6  	"net"
     7  	"path/filepath"
     8  	"testing"
     9  
    10  	"github.com/anacrolix/torrent"
    11  	"github.com/anacrolix/torrent/dialer"
    12  )
    13  
    14  func TestUnixConns(t *testing.T) {
    15  	var closers []io.Closer
    16  	defer func() {
    17  		for _, c := range closers {
    18  			c.Close()
    19  		}
    20  	}()
    21  	configure := ConfigureClient{
    22  		Config: func(cfg *torrent.ClientConfig) {
    23  			cfg.DisableUTP = true
    24  			cfg.DisableTCP = true
    25  			cfg.Debug = true
    26  		},
    27  		Client: func(cl *torrent.Client) {
    28  			cl.AddDialer(torrent.NetworkDialer{Network: "unix", Dialer: dialer.Default})
    29  			l, err := net.Listen("unix", filepath.Join(t.TempDir(), "socket"))
    30  			if err != nil {
    31  				panic(err)
    32  			}
    33  			log.Printf("created listener %q", l)
    34  			closers = append(closers, l)
    35  			cl.AddListener(l)
    36  		},
    37  	}
    38  	testClientTransfer(t, testClientTransferParams{
    39  		ConfigureSeeder:  configure,
    40  		ConfigureLeecher: configure,
    41  	})
    42  }