github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/proxy/reality/client_test.go (about) 1 package reality 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/Asutorufa/yuhaiin/pkg/net/netapi" 8 "github.com/Asutorufa/yuhaiin/pkg/net/proxy/simple" 9 "github.com/Asutorufa/yuhaiin/pkg/protos/node/protocol" 10 "github.com/Asutorufa/yuhaiin/pkg/utils/assert" 11 ) 12 13 func TestClient(t *testing.T) { 14 sm := simple.NewClient(&protocol.Protocol_Simple{ 15 Simple: &protocol.Simple{ 16 Host: "127.0.0.1", 17 Port: 2096, 18 }, 19 }) 20 21 c := NewRealityClient( 22 &protocol.Protocol_Reality{ 23 Reality: &protocol.Reality{ 24 ServerName: "www.baidu.com", 25 ShortId: "123456", 26 PublicKey: "SOW7P-17ibm_-kz-QUQwGGyitSbsa5wOmRGAigGvDH8", 27 }, 28 }, 29 ) 30 31 pp, err := sm(nil) 32 assert.NoError(t, err) 33 pp, err = c(pp) 34 assert.NoError(t, err) 35 36 conn, err := pp.Conn(context.Background(), netapi.EmptyAddr) 37 assert.NoError(t, err) 38 defer conn.Close() 39 40 _, _ = conn.Write([]byte("aaa")) 41 42 buf := make([]byte, 1024) 43 n, err := conn.Read(buf) 44 assert.NoError(t, err) 45 46 t.Log(string(buf[:n])) 47 }