当前位置: 首页>>代码示例>>Golang>>正文


Golang assert.Address函数代码示例

本文整理汇总了Golang中v2ray/com/core/testing/assert.Address函数的典型用法代码示例。如果您正苦于以下问题:Golang Address函数的具体用法?Golang Address怎么用?Golang Address使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Address函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestNetIPv4Address

func TestNetIPv4Address(t *testing.T) {
	assert := assert.On(t)

	ip := net.IPv4(1, 2, 3, 4)
	addr := v2net.IPAddress(ip)
	assert.Address(addr).IsIPv4()
	assert.Address(addr).EqualsString("1.2.3.4")
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:8,代码来源:address_test.go

示例2: TestDomainAddress

func TestDomainAddress(t *testing.T) {
	assert := assert.On(t)

	domain := "v2ray.com"
	addr := v2net.DomainAddress(domain)

	assert.Address(addr).IsDomain()
	assert.Address(addr).IsNotIPv6()
	assert.Address(addr).IsNotIPv4()
	assert.String(addr.Domain()).Equals(domain)
	assert.Address(addr).EqualsString("v2ray.com")
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:12,代码来源:address_test.go

示例3: TestIPv4Address

func TestIPv4Address(t *testing.T) {
	assert := assert.On(t)

	ip := []byte{byte(1), byte(2), byte(3), byte(4)}
	addr := v2net.IPAddress(ip)

	assert.Address(addr).IsIPv4()
	assert.Address(addr).IsNotIPv6()
	assert.Address(addr).IsNotDomain()
	assert.Bytes(addr.IP()).Equals(ip)
	assert.Address(addr).EqualsString("1.2.3.4")
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:12,代码来源:address_test.go

示例4: TestIPv4AddressEquals

func TestIPv4AddressEquals(t *testing.T) {
	assert := assert.On(t)

	addr := v2net.IPAddress([]byte{1, 2, 3, 4})
	assert.Address(addr).NotEquals(nil)

	addr2 := v2net.IPAddress([]byte{1, 2, 3, 4})
	assert.Address(addr).Equals(addr2)

	addr3 := v2net.IPAddress([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
	assert.Address(addr).NotEquals(addr3)

	addr4 := v2net.IPAddress([]byte{1, 2, 3, 5})
	assert.Address(addr).NotEquals(addr4)
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:15,代码来源:address_test.go

示例5: TestUDPEncoding

func TestUDPEncoding(t *testing.T) {
	assert := assert.On(t)

	request := &protocol.RequestHeader{
		Version: Version,
		Command: protocol.RequestCommandUDP,
		Address: v2net.LocalHostIP,
		Port:    1234,
		User: &protocol.User{
			Email: "[email protected]",
			Account: serial.ToTypedMessage(&Account{
				Password:   "shadowsocks-password",
				CipherType: CipherType_AES_128_CFB,
				Ota:        Account_Disabled,
			}),
		},
	}

	data := buf.NewLocal(256)
	data.AppendSupplier(serial.WriteString("test string"))
	encodedData, err := EncodeUDPPacket(request, data)
	assert.Error(err).IsNil()

	decodedRequest, decodedData, err := DecodeUDPPacket(request.User, encodedData)
	assert.Error(err).IsNil()
	assert.Bytes(decodedData.Bytes()).Equals(data.Bytes())
	assert.Address(decodedRequest.Address).Equals(request.Address)
	assert.Port(decodedRequest.Port).Equals(request.Port)
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:29,代码来源:protocol_test.go

示例6: TestSocksInboundConfig

func TestSocksInboundConfig(t *testing.T) {
	assert := assert.On(t)

	rawJson := `{
    "auth": "password",
    "accounts": [
      {
        "user": "my-username",
        "pass": "my-password"
      }
    ],
    "udp": false,
    "ip": "127.0.0.1",
    "timeout": 5
  }`

	config := new(SocksServerConfig)
	err := json.Unmarshal([]byte(rawJson), &config)
	assert.Error(err).IsNil()

	message, err := config.Build()
	assert.Error(err).IsNil()

	iConfig, err := message.GetInstance()
	assert.Error(err).IsNil()

	socksConfig := iConfig.(*socks.ServerConfig)
	assert.Bool(socksConfig.AuthType == socks.AuthType_PASSWORD).IsTrue()
	assert.Int(len(socksConfig.Accounts)).Equals(1)
	assert.String(socksConfig.Accounts["my-username"]).Equals("my-password")
	assert.Bool(socksConfig.UdpEnabled).IsFalse()
	assert.Address(socksConfig.Address.AsAddress()).Equals(net.LocalHostIP)
	assert.Uint32(socksConfig.Timeout).Equals(5)
}
开发者ID:ylywyn,项目名称:v2ray-core,代码行数:34,代码来源:socks_test.go

示例7: TestIPResolution

func TestIPResolution(t *testing.T) {
	assert := assert.On(t)

	space := app.NewSpace()
	space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, proxyman.NewDefaultOutboundHandlerManager())
	space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
	r, _ := router.CreateRouter("rules", &rules.RouterRuleConfig{}, space)
	space.BindApp(router.APP_ID, r)
	dnsServer := dns.NewCacheServer(space, &dns.Config{
		Hosts: map[string]net.IP{
			"v2ray.com": net.IP([]byte{127, 0, 0, 1}),
		},
	})
	space.BindApp(dns.APP_ID, dnsServer)

	freedom := NewFreedomConnection(
		&Config{DomainStrategy: DomainStrategyUseIP},
		space,
		&proxy.OutboundHandlerMeta{
			Address: v2net.AnyIP,
			StreamSettings: &internet.StreamSettings{
				Type: internet.StreamConnectionTypeRawTCP,
			},
		})

	space.Initialize()

	ipDest := freedom.ResolveIP(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), v2net.Port(80)))
	assert.Destination(ipDest).IsTCP()
	assert.Address(ipDest.Address()).Equals(v2net.LocalHostIP)
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:31,代码来源:freedom_test.go

示例8: TestTCPRequest

func TestTCPRequest(t *testing.T) {
	assert := assert.On(t)

	request := &protocol.RequestHeader{
		Version: Version,
		Command: protocol.RequestCommandTCP,
		Address: v2net.LocalHostIP,
		Option:  RequestOptionOneTimeAuth,
		Port:    1234,
		User: &protocol.User{
			Email: "[email protected]",
			Account: loader.NewTypedSettings(&Account{
				Password:   "tcp-password",
				CipherType: CipherType_CHACHA20,
			}),
		},
	}

	data := alloc.NewLocalBuffer(256).Clear().AppendString("test string")
	cache := alloc.NewBuffer().Clear()

	writer, err := WriteTCPRequest(request, cache)
	assert.Error(err).IsNil()

	writer.Write(data)

	decodedRequest, reader, err := ReadTCPSession(request.User, cache)
	assert.Error(err).IsNil()
	assert.Address(decodedRequest.Address).Equals(request.Address)
	assert.Port(decodedRequest.Port).Equals(request.Port)

	decodedData, err := reader.Read()
	assert.Error(err).IsNil()
	assert.Bytes(decodedData.Value).Equals([]byte("test string"))
}
开发者ID:xyz12810,项目名称:v2ray-core,代码行数:35,代码来源:protocol_test.go

示例9: TestUDPEncoding

func TestUDPEncoding(t *testing.T) {
	assert := assert.On(t)

	request := &protocol.RequestHeader{
		Version: Version,
		Command: protocol.RequestCommandUDP,
		Address: v2net.LocalHostIP,
		Port:    1234,
		User: &protocol.User{
			Email: "[email protected]",
			Account: loader.NewTypedSettings(&Account{
				Password:   "shadowsocks-password",
				CipherType: CipherType_AES_128_CFB,
				Ota:        Account_Disabled,
			}),
		},
	}

	data := alloc.NewLocalBuffer(256).Clear().AppendString("test string")
	encodedData, err := EncodeUDPPacket(request, data)
	assert.Error(err).IsNil()

	decodedRequest, decodedData, err := DecodeUDPPacket(request.User, encodedData)
	assert.Error(err).IsNil()
	assert.Bytes(decodedData.Value).Equals(data.Value)
	assert.Address(decodedRequest.Address).Equals(request.Address)
	assert.Port(decodedRequest.Port).Equals(request.Port)
}
开发者ID:xyz12810,项目名称:v2ray-core,代码行数:28,代码来源:protocol_test.go

示例10: TestIPResolution

func TestIPResolution(t *testing.T) {
	assert := assert.On(t)

	space := app.NewSpace()
	space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, outbound.New())
	space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
	r := router.NewRouter(&router.Config{}, space)
	space.BindApp(router.APP_ID, r)
	dnsServer := dnsserver.NewCacheServer(space, &dns.Config{
		Hosts: map[string]*v2net.IPOrDomain{
			"v2ray.com": v2net.NewIPOrDomain(v2net.LocalHostIP),
		},
	})
	space.BindApp(dns.APP_ID, dnsServer)

	freedom := NewFreedomConnection(
		&Config{DomainStrategy: Config_USE_IP},
		space,
		&proxy.OutboundHandlerMeta{
			Address: v2net.AnyIP,
			StreamSettings: &internet.StreamConfig{
				Network: v2net.Network_RawTCP,
			},
		})

	space.Initialize()

	ipDest := freedom.ResolveIP(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), v2net.Port(80)))
	assert.Destination(ipDest).IsTCP()
	assert.Address(ipDest.Address).Equals(v2net.LocalHostIP)
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:31,代码来源:freedom_test.go

示例11: TestIPv6Address

func TestIPv6Address(t *testing.T) {
	assert := assert.On(t)

	ip := []byte{
		byte(1), byte(2), byte(3), byte(4),
		byte(1), byte(2), byte(3), byte(4),
		byte(1), byte(2), byte(3), byte(4),
		byte(1), byte(2), byte(3), byte(4),
	}
	addr := v2net.IPAddress(ip)

	assert.Address(addr).IsIPv6()
	assert.Address(addr).IsNotIPv4()
	assert.Address(addr).IsNotDomain()
	assert.IP(addr.IP()).Equals(net.IP(ip))
	assert.Address(addr).EqualsString("[102:304:102:304:102:304:102:304]")
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:17,代码来源:address_test.go

示例12: TestDefaultIPAddress

func TestDefaultIPAddress(t *testing.T) {
	assert := assert.On(t)

	socksConfig, err := registry.CreateInboundConfig("socks", []byte(`{
    "auth": "noauth"
  }`))
	assert.Error(err).IsNil()
	assert.Address(socksConfig.(*socks.Config).Address).EqualsString("127.0.0.1")
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:9,代码来源:server_config_json_test.go

示例13: TestIPv4Asv6

func TestIPv4Asv6(t *testing.T) {
	assert := assert.On(t)
	ip := []byte{
		byte(0), byte(0), byte(0), byte(0),
		byte(0), byte(0), byte(0), byte(0),
		byte(0), byte(0), byte(255), byte(255),
		byte(1), byte(2), byte(3), byte(4),
	}
	addr := v2net.IPAddress(ip)
	assert.Address(addr).EqualsString("1.2.3.4")
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:11,代码来源:address_test.go

示例14: TestConfigParsing

func TestConfigParsing(t *testing.T) {
	assert := assert.On(t)

	rawJson := `{
    "servers": ["8.8.8.8"]
  }`

	config := new(Config)
	err := json.Unmarshal([]byte(rawJson), config)
	assert.Error(err).IsNil()
	assert.Int(len(config.NameServers)).Equals(1)
	assert.Destination(config.NameServers[0]).IsUDP()
	assert.Address(config.NameServers[0].Address()).Equals(v2net.IPAddress([]byte{8, 8, 8, 8}))
	assert.Port(config.NameServers[0].Port()).Equals(v2net.Port(53))
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:15,代码来源:config_json_test.go

示例15: TestDomainAddressRequest

func TestDomainAddressRequest(t *testing.T) {
	assert := assert.On(t)

	payload := make([]byte, 0, 1024)
	payload = append(payload, 0, 0, 1, AddrTypeDomain, byte(len("v2ray.com")))
	payload = append(payload, []byte("v2ray.com")...)
	payload = append(payload, 0, 80)
	payload = append(payload, []byte("Actual payload")...)

	request, err := ReadUDPRequest(payload)
	assert.Error(err).IsNil()

	assert.Byte(request.Fragment).Equals(1)
	assert.Address(request.Address).EqualsString("v2ray.com")
	assert.Port(request.Port).Equals(v2net.Port(80))
	assert.String(request.Data.String()).Equals("Actual payload")
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:17,代码来源:udp_test.go


注:本文中的v2ray/com/core/testing/assert.Address函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。