github.com/anacrolix/torrent@v1.61.0/iplist/packed_test.go (about)

     1  package iplist
     2  
     3  import (
     4  	"bytes"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  // The active ingredients in the sample P2P blocklist file contents `sample`,
    12  // for reference:
    13  //
    14  // a:1.2.4.0-1.2.4.255
    15  // b:1.2.8.0-1.2.8.255
    16  // eff:1.2.8.2-1.2.8.2
    17  // something:more detail:86.59.95.195-86.59.95.195
    18  // eff:127.0.0.0-127.0.0.1`
    19  
    20  func TestWritePacked(t *testing.T) {
    21  	l, err := NewFromReader(strings.NewReader(sample))
    22  	require.NoError(t, err)
    23  	var buf bytes.Buffer
    24  	err = l.WritePacked(&buf)
    25  	require.NoError(t, err)
    26  	require.Equal(t,
    27  		"\x05\x00\x00\x00\x00\x00\x00\x00"+
    28  			"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x01\x02\x04\x00"+"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x01\x02\x04\xff"+"\x00\x00\x00\x00\x00\x00\x00\x00"+"\x01\x00\x00\x00"+
    29  			"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x01\x02\x08\x00"+"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x01\x02\x08\xff"+"\x01\x00\x00\x00\x00\x00\x00\x00"+"\x01\x00\x00\x00"+
    30  			"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x01\x02\x08\x02"+"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x01\x02\x08\x02"+"\x02\x00\x00\x00\x00\x00\x00\x00"+"\x03\x00\x00\x00"+
    31  			"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x56\x3b\x5f\xc3"+"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x56\x3b\x5f\xc3"+"\x05\x00\x00\x00\x00\x00\x00\x00"+"\x15\x00\x00\x00"+
    32  			"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x7f\x00\x00\x00"+"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x7f\x00\x00\x01"+"\x02\x00\x00\x00\x00\x00\x00\x00"+"\x03\x00\x00\x00"+
    33  			"abeffsomething:more detail",
    34  		buf.String())
    35  }