Debian Codegraph @

common/net/destination_test.go

raw symbols SCIP
1 package net_testscip-go gomod v2ray.com/core . `v2ray.com/core/common/net_test`/
2
3 import (
4 "testingscip-go gomod github.com/golang/go/src go1.15 testing/"
5
6 "github.com/google/go-cmp/cmpscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/"
7
8 . "v2ray.com/core/common/netscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/"
9 )
10
11 func TestDestinationPropertyscip-go gomod v2ray.com/core . `v2ray.com/core/common/net_test`/TestDestinationProperty().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) {
12 testCases := []struct {
13 Input Destinationscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#
14 Network Networkscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Network#
15 String string
16 NetString string
17 }{
18 {
19 Input: TCPDestinationscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/TCPDestination().(IPAddressscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/IPAddress().([]byte{1, 2, 3, 4}), 80),
20 Network: Network_TCPscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Network_TCP.,
21 String: "tcp:1.2.3.4:80",
22 NetString: "1.2.3.4:80",
23 },
24 {
25 Input: UDPDestinationscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/UDPDestination().(IPAddressscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/IPAddress().([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}), 53),
26 Network: Network_UDPscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Network_UDP.,
27 String: "udp:[2001:4860:4860::8888]:53",
28 NetString: "[2001:4860:4860::8888]:53",
29 },
30 {
31 Input: UnixDestinationscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/UnixDestination().(DomainAddressscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/DomainAddress().("/tmp/test.sock")),
32 Network: Network_UNIXscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Network_UNIX.,
33 String: "unix:/tmp/test.sock",
34 NetString: "/tmp/test.sock",
35 },
36 }
37
38 for _, testCase := range testCases {
39 dest := testCase.Input
40 if r := cmpscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/Diff().(dest.Networkscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#Network., testCase.Network); r != "" {
41 t.Errorscip-go gomod github.com/golang/go/src go1.15 testing/common#Error().("unexpected Network in ", dest.Stringscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#String().(), ": ", r)
42 }
43 if r := cmpscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/Diff().(dest.Stringscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#String().(), testCase.String); r != "" {
44 t.Errorscip-go gomod github.com/golang/go/src go1.15 testing/common#Error().(r)
45 }
46 if r := cmpscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.5.4 `github.com/google/go-cmp/cmp`/Diff().(dest.NetAddrscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#NetAddr().(), testCase.NetString); r != "" {
47 t.Errorscip-go gomod github.com/golang/go/src go1.15 testing/common#Error().(r)
48 }
49 }
50 }
51
52 func TestDestinationParsescip-go gomod v2ray.com/core . `v2ray.com/core/common/net_test`/TestDestinationParse().(t *testingscip-go gomod github.com/golang/go/src go1.15 testing/.Tscip-go gomod github.com/golang/go/src go1.15 testing/T#) {
53 cases := []struct {
54 Input string
55 Output Destinationscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#
56 Error bool
57 }{
58 {
59 Input: "tcp:127.0.0.1:80",
60 Output: TCPDestinationscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/TCPDestination().(LocalHostIPscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/LocalHostIP., Portscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Port#(80)),
61 },
62 {
63 Input: "udp:8.8.8.8:53",
64 Output: UDPDestinationscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/UDPDestination().(IPAddressscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/IPAddress().([]byte{8, 8, 8, 8}), Portscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Port#(53)),
65 },
66 {
67 Input: "unix:/tmp/test.sock",
68 Output: UnixDestinationscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/UnixDestination().(DomainAddressscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/DomainAddress().("/tmp/test.sock")),
69 },
70 {
71 Input: "8.8.8.8:53",
72 Output: Destinationscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#{
73 Addressscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#Address.: IPAddressscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/IPAddress().([]byte{8, 8, 8, 8}),
74 Portscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#Port.: Portscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Port#(53),
75 },
76 },
77 {
78 Input: ":53",
79 Output: Destinationscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#{
80 Addressscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#Address.: AnyIPscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/AnyIP.,
81 Portscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#Port.: Portscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Port#(53),
82 },
83 },
84 {
85 Input: "8.8.8.8",
86 Error: true,
87 },
88 {
89 Input: "8.8.8.8:http",
90 Error: true,
91 },
92 {
93 Input: "/tmp/test.sock",
94 Error: true,
95 },
96 }
97
98 for _, testcase := range cases {
99 d, err := ParseDestinationscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/ParseDestination().(testcase.Input)
100 if !testcase.Error {
101 if err != nil {
102 t.Errorscip-go gomod github.com/golang/go/src go1.15 testing/common#Error().("for test case: ", testcase.Input, " expected no error, but got ", err)
103 }
104 if d != testcase.Output {
105 t.Errorscip-go gomod github.com/golang/go/src go1.15 testing/common#Error().("for test case: ", testcase.Input, " expected output: ", testcase.Output.Stringscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#String().(), " but got ", d.Stringscip-go gomod v2ray.com/core . `v2ray.com/core/common/net`/Destination#String().())
106 }
107 } else if err == nil {
108 t.Errorscip-go gomod github.com/golang/go/src go1.15 testing/common#Error().("for test case: ", testcase.Input, " expected error, but got nil")
109 }
110 }
111 }