• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang testing.Current函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestSwitchAccount

func TestSwitchAccount(t *testing.T) {
	v2testing.Current(t)

	sa := &SwitchAccount{
		Port:       1234,
		ID:         uuid.New(),
		AlterIds:   1024,
		ValidUntil: time.Now(),
	}

	cmd, err := CreateResponseCommand(1)
	assert.Error(err).IsNil()

	buffer := bytes.NewBuffer(make([]byte, 0, 1024))
	nBytes, err := sa.Marshal(buffer)
	assert.Error(err).IsNil()
	assert.Int(nBytes).Equals(buffer.Len())

	cmd.Unmarshal(buffer.Bytes())
	sa2, ok := cmd.(*SwitchAccount)
	assert.Bool(ok).IsTrue()
	netassert.Port(sa.Port).Equals(sa2.Port)
	assert.String(sa.ID).Equals(sa2.ID.String())
	assert.Uint16(sa.AlterIds.Value()).Equals(sa2.AlterIds.Value())
	assert.Int64(sa.ValidUntil.Unix()).Equals(sa2.ValidUntil.Unix())
}
开发者ID:ibmendoza,项目名称:v2ray-core,代码行数:26,代码来源:accounts_test.go


示例2: TestIPNet

func TestIPNet(t *testing.T) {
	v2testing.Current(t)

	ipNet := NewIPNet()
	ipNet.Add(parseCIDR(("0.0.0.0/8")))
	ipNet.Add(parseCIDR(("10.0.0.0/8")))
	ipNet.Add(parseCIDR(("100.64.0.0/10")))
	ipNet.Add(parseCIDR(("127.0.0.0/8")))
	ipNet.Add(parseCIDR(("169.254.0.0/16")))
	ipNet.Add(parseCIDR(("172.16.0.0/12")))
	ipNet.Add(parseCIDR(("192.0.0.0/24")))
	ipNet.Add(parseCIDR(("192.0.2.0/24")))
	ipNet.Add(parseCIDR(("192.168.0.0/16")))
	ipNet.Add(parseCIDR(("198.18.0.0/15")))
	ipNet.Add(parseCIDR(("198.51.100.0/24")))
	ipNet.Add(parseCIDR(("203.0.113.0/24")))
	ipNet.Add(parseCIDR(("8.8.8.8/32")))
	assert.Bool(ipNet.Contains(net.ParseIP("192.168.1.1"))).IsTrue()
	assert.Bool(ipNet.Contains(net.ParseIP("192.0.0.0"))).IsTrue()
	assert.Bool(ipNet.Contains(net.ParseIP("192.0.1.0"))).IsFalse()
	assert.Bool(ipNet.Contains(net.ParseIP("0.1.0.0"))).IsTrue()
	assert.Bool(ipNet.Contains(net.ParseIP("1.0.0.1"))).IsFalse()
	assert.Bool(ipNet.Contains(net.ParseIP("8.8.8.7"))).IsFalse()
	assert.Bool(ipNet.Contains(net.ParseIP("8.8.8.8"))).IsTrue()
	assert.Bool(ipNet.Contains(net.ParseIP("2001:cdba::3257:9652"))).IsFalse()
}
开发者ID:jim1568cas,项目名称:v2ray-core,代码行数:26,代码来源:ipnet_test.go


示例3: TestSocksUdpSend

func TestSocksUdpSend(t *testing.T) {
	v2testing.Current(t)
	port := v2nettesting.PickPort()

	connInput := []byte("The data to be returned to socks server.")
	connOutput := bytes.NewBuffer(make([]byte, 0, 1024))
	och := &proxymocks.OutboundConnectionHandler{
		ConnInput:  bytes.NewReader(connInput),
		ConnOutput: connOutput,
	}

	protocol, err := proxytesting.RegisterOutboundConnectionHandlerCreator("mock_och",
		func(space app.Space, config interface{}) (v2proxy.OutboundConnectionHandler, error) {
			return och, nil
		})
	assert.Error(err).IsNil()

	config := &point.Config{
		Port: port,
		InboundConfig: &point.ConnectionConfig{
			Protocol: "socks",
			Settings: []byte(`{"auth": "noauth", "udp": true}`),
		},
		OutboundConfig: &point.ConnectionConfig{
			Protocol: protocol,
			Settings: nil,
		},
	}

	point, err := point.NewPoint(config)
	assert.Error(err).IsNil()

	err = point.Start()
	assert.Error(err).IsNil()

	conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
		IP:   []byte{127, 0, 0, 1},
		Port: int(port),
		Zone: "",
	})

	assert.Error(err).IsNil()

	data2Send := []byte("Fake DNS request")

	buffer := make([]byte, 0, 1024)
	buffer = append(buffer, 0, 0, 0)
	buffer = append(buffer, 1, 8, 8, 4, 4, 0, 53)
	buffer = append(buffer, data2Send...)

	conn.Write(buffer)

	response := make([]byte, 1024)
	nBytes, err := conn.Read(response)

	assert.Error(err).IsNil()
	assert.Bytes(response[10:nBytes]).Equals(connInput)
	assert.Bytes(data2Send).Equals(connOutput.Bytes())
	assert.StringLiteral(och.Destination.String()).Equals("udp:8.8.4.4:53")
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:60,代码来源:socks_test.go


示例4: TestPubsub

func TestPubsub(t *testing.T) {
	v2testing.Current(t)

	messages := make(map[string]app.PubsubMessage)

	pubsub := New()
	pubsub.Subscribe(&apptesting.Context{}, "t1", func(message app.PubsubMessage) {
		messages["t1"] = message
	})

	pubsub.Subscribe(&apptesting.Context{}, "t2", func(message app.PubsubMessage) {
		messages["t2"] = message
	})

	message := app.PubsubMessage([]byte("This is a pubsub message."))
	pubsub.Publish(&apptesting.Context{}, "t2", message)
	<-time.Tick(time.Second)

	_, found := messages["t1"]
	assert.Bool(found).IsFalse()

	actualMessage, found := messages["t2"]
	assert.Bool(found).IsTrue()
	assert.StringLiteral(string(actualMessage)).Equals(string(message))
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:25,代码来源:pubsub_test.go


示例5: TestDokodemoUDP

func TestDokodemoUDP(t *testing.T) {
	v2testing.Current(t)

	port := v2nettesting.PickPort()

	data2Send := "Data to be sent to remote."

	udpServer := &udp.Server{
		Port: port,
		MsgProcessor: func(data []byte) []byte {
			buffer := make([]byte, 0, 2048)
			buffer = append(buffer, []byte("Processed: ")...)
			buffer = append(buffer, data...)
			return buffer
		},
	}
	_, err := udpServer.Start()
	assert.Error(err).IsNil()

	pointPort := v2nettesting.PickPort()
	networkList := v2netjson.NetworkList([]string{"udp"})
	config := mocks.Config{
		PortValue: pointPort,
		InboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "dokodemo-door",
			SettingsValue: &json.DokodemoConfig{
				Host:         v2netjson.NewIPHost(net.ParseIP("127.0.0.1")),
				PortValue:    port,
				NetworkList:  &networkList,
				TimeoutValue: 0,
			},
		},
		OutboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "freedom",
			SettingsValue: nil,
		},
	}

	point, err := point.NewPoint(&config)
	assert.Error(err).IsNil()

	err = point.Start()
	assert.Error(err).IsNil()

	udpClient, err := net.DialUDP("udp", nil, &net.UDPAddr{
		IP:   []byte{127, 0, 0, 1},
		Port: int(pointPort),
		Zone: "",
	})
	assert.Error(err).IsNil()

	udpClient.Write([]byte(data2Send))

	response := make([]byte, 1024)
	nBytes, err := udpClient.Read(response)
	assert.Error(err).IsNil()
	udpClient.Close()

	assert.StringLiteral("Processed: " + data2Send).Equals(string(response[:nBytes]))
}
开发者ID:adoot,项目名称:v2ray-core,代码行数:60,代码来源:dokodemo_test.go


示例6: TestInvalidNetworkJson

func TestInvalidNetworkJson(t *testing.T) {
	v2testing.Current(t)

	var list NetworkList
	err := json.Unmarshal([]byte("0"), &list)
	assert.Error(err).IsNotNil()
}
开发者ID:jim1568cas,项目名称:v2ray-core,代码行数:7,代码来源:network_json_test.go


示例7: TestSwitchAccount

func TestSwitchAccount(t *testing.T) {
	v2testing.Current(t)

	sa := &SwitchAccount{
		Port:     1234,
		ID:       uuid.New(),
		AlterIds: 1024,
		Level:    128,
		ValidMin: 16,
	}

	cmd, err := CreateResponseCommand(1)
	assert.Error(err).IsNil()

	buffer := bytes.NewBuffer(make([]byte, 0, 1024))
	sa.Marshal(buffer)

	cmd.Unmarshal(buffer.Bytes())
	sa2, ok := cmd.(*SwitchAccount)
	assert.Bool(ok).IsTrue()
	assert.Pointer(sa.Host).IsNil()
	assert.Pointer(sa2.Host).IsNil()
	netassert.Port(sa.Port).Equals(sa2.Port)
	assert.String(sa.ID).Equals(sa2.ID.String())
	assert.Uint16(sa.AlterIds.Value()).Equals(sa2.AlterIds.Value())
	assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level))
	assert.Byte(sa.ValidMin).Equals(sa2.ValidMin)
}
开发者ID:airmao,项目名称:v2ray-core,代码行数:28,代码来源:accounts_test.go


示例8: TestNext

func TestNext(t *testing.T) {
	v2testing.Current(t)

	uuid := New()
	uuid2 := uuid.Next()
	assert.Bool(uuid.Equals(uuid2)).IsFalse()
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:7,代码来源:uuid_test.go


示例9: TestReadSingleByte

func TestReadSingleByte(t *testing.T) {
	v2testing.Current(t)

	reader := NewVMessRequestReader(nil)
	_, err := reader.Read(bytes.NewReader(make([]byte, 1)))
	assert.Error(err).Equals(io.EOF)
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:7,代码来源:vmess_test.go


示例10: TestInsufficientPortRequest

func TestInsufficientPortRequest(t *testing.T) {
	v2testing.Current(t)

	buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1, 1, 2, 3, 4, 5)
	_, err := ReadRequest(buffer, nil, false)
	assert.Error(err).Equals(transport.ErrorCorruptedPacket)
}
开发者ID:jim1568cas,项目名称:v2ray-core,代码行数:7,代码来源:protocol_test.go


示例11: TestSwitchAccount

func TestSwitchAccount(t *testing.T) {
	v2testing.Current(t)

	sa := &protocol.CommandSwitchAccount{
		Port:     1234,
		ID:       uuid.New(),
		AlterIds: 1024,
		Level:    128,
		ValidMin: 16,
	}

	buffer := alloc.NewBuffer().Clear()
	err := MarshalCommand(sa, buffer)
	assert.Error(err).IsNil()

	cmd, err := UnmarshalCommand(1, buffer.Value[2:])
	assert.Error(err).IsNil()

	sa2, ok := cmd.(*protocol.CommandSwitchAccount)
	assert.Bool(ok).IsTrue()
	assert.Pointer(sa.Host).IsNil()
	assert.Pointer(sa2.Host).IsNil()
	netassert.Port(sa.Port).Equals(sa2.Port)
	assert.String(sa.ID).Equals(sa2.ID.String())
	assert.Uint16(sa.AlterIds.Value()).Equals(sa2.AlterIds.Value())
	assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level))
	assert.Byte(sa.ValidMin).Equals(sa2.ValidMin)
}
开发者ID:wangyou,项目名称:v2ray-core,代码行数:28,代码来源:commands_test.go


示例12: TestDefaultIPAddress

func TestDefaultIPAddress(t *testing.T) {
	v2testing.Current(t)

	socksConfig, err := config.CreateInboundConnectionConfig("socks", []byte(`{}`))
	assert.Error(err).IsNil()
	assert.String(socksConfig.(*SocksConfig).IP()).Equals("127.0.0.1")
}
开发者ID:JohnTsaiAndroid,项目名称:v2ray-core,代码行数:7,代码来源:config_test.go


示例13: TestHopByHopHeadersStrip

func TestHopByHopHeadersStrip(t *testing.T) {
	v2testing.Current(t)

	rawRequest := `GET /pkg/net/http/ HTTP/1.1
Host: golang.org
Connection: keep-alive,Foo, Bar
Foo: foo
Bar: bar
Proxy-Connection: keep-alive
Proxy-Authenticate: abc
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; de-de) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10
Accept-Encoding: gzip
Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7
Cache-Control: no-cache
Accept-Language: de,en;q=0.7,en-us;q=0.3

`
	b := bufio.NewReader(strings.NewReader(rawRequest))
	req, err := http.ReadRequest(b)
	assert.Error(err).IsNil()
	assert.StringLiteral(req.Header.Get("Foo")).Equals("foo")
	assert.StringLiteral(req.Header.Get("Bar")).Equals("bar")
	assert.StringLiteral(req.Header.Get("Connection")).Equals("keep-alive,Foo, Bar")
	assert.StringLiteral(req.Header.Get("Proxy-Connection")).Equals("keep-alive")
	assert.StringLiteral(req.Header.Get("Proxy-Authenticate")).Equals("abc")

	StripHopByHopHeaders(req)
	assert.StringLiteral(req.Header.Get("Connection")).Equals("close")
	assert.StringLiteral(req.Header.Get("Foo")).Equals("")
	assert.StringLiteral(req.Header.Get("Bar")).Equals("")
	assert.StringLiteral(req.Header.Get("Proxy-Connection")).Equals("")
	assert.StringLiteral(req.Header.Get("Proxy-Authenticate")).Equals("")
}
开发者ID:wangyou,项目名称:v2ray-core,代码行数:33,代码来源:http_test.go


示例14: TestRepoVersion

func TestRepoVersion(t *testing.T) {
	v2testing.Current(t)

	version, err := RepoVersionHead()
	assert.Error(err).IsNil()
	assert.Int(len(version)).GreaterThan(0)
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:7,代码来源:git_test.go


示例15: TestRevParse

func TestRevParse(t *testing.T) {
	v2testing.Current(t)

	rev, err := RevParse("HEAD")
	assert.Error(err).IsNil()
	assert.Int(len(rev)).GreaterThan(0)
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:7,代码来源:git_test.go


示例16: TestRequestSerialization

func TestRequestSerialization(t *testing.T) {
	v2testing.Current(t)

	user := protocol.NewUser(
		protocol.NewID(uuid.New()),
		protocol.UserLevelUntrusted,
		0,
		"[email protected]")

	expectedRequest := &protocol.RequestHeader{
		Version: 1,
		User:    user,
		Command: protocol.RequestCommandTCP,
		Option:  protocol.RequestOption(0),
		Address: v2net.DomainAddress("www.v2ray.com"),
		Port:    v2net.Port(443),
	}

	buffer := alloc.NewBuffer().Clear()
	client := NewClientSession(protocol.DefaultIDHash)
	client.EncodeRequestHeader(expectedRequest, buffer)

	userValidator := protocol.NewTimedUserValidator(protocol.DefaultIDHash)
	userValidator.Add(user)

	server := NewServerSession(userValidator)
	actualRequest, err := server.DecodeRequestHeader(buffer)
	assert.Error(err).IsNil()

	assert.Byte(expectedRequest.Version).Equals(actualRequest.Version)
	assert.Byte(byte(expectedRequest.Command)).Equals(byte(actualRequest.Command))
	assert.Byte(byte(expectedRequest.Option)).Equals(byte(actualRequest.Option))
	netassert.Address(expectedRequest.Address).Equals(actualRequest.Address)
	netassert.Port(expectedRequest.Port).Equals(actualRequest.Port)
}
开发者ID:wangyou,项目名称:v2ray-core,代码行数:35,代码来源:encoding_test.go


示例17: TestWrongProtocolVersion

func TestWrongProtocolVersion(t *testing.T) {
	v2testing.Current(t)

	buffer := alloc.NewBuffer().Clear().AppendBytes(6, 1, 0)
	_, _, err := ReadAuthentication(buffer)
	assert.Error(err).Equals(proxy.ErrorInvalidProtocolVersion)
}
开发者ID:jim1568cas,项目名称:v2ray-core,代码行数:7,代码来源:socks_test.go


示例18: TestZeroAuthenticationMethod

func TestZeroAuthenticationMethod(t *testing.T) {
	v2testing.Current(t)

	buffer := alloc.NewBuffer().Clear().AppendBytes(5, 0)
	_, _, err := ReadAuthentication(buffer)
	assert.Error(err).Equals(proxy.ErrorInvalidAuthentication)
}
开发者ID:jim1568cas,项目名称:v2ray-core,代码行数:7,代码来源:socks_test.go


示例19: TestSingleBytePayload

func TestSingleBytePayload(t *testing.T) {
	v2testing.Current(t)

	buffer := alloc.NewSmallBuffer().Clear().AppendBytes(1)
	_, err := ReadRequest(buffer, nil, false)
	assert.Error(err).Equals(transport.ErrorCorruptedPacket)
}
开发者ID:jim1568cas,项目名称:v2ray-core,代码行数:7,代码来源:protocol_test.go


示例20: TestResponseWrite

func TestResponseWrite(t *testing.T) {
	v2testing.Current(t)

	response := Socks5Response{
		socksVersion,
		ErrorSuccess,
		AddrTypeIPv4,
		[4]byte{0x72, 0x72, 0x72, 0x72},
		"",
		[16]byte{},
		v2net.Port(53),
	}
	buffer := alloc.NewSmallBuffer().Clear()
	defer buffer.Release()

	response.Write(buffer)
	expectedBytes := []byte{
		socksVersion,
		ErrorSuccess,
		byte(0x00),
		AddrTypeIPv4,
		0x72, 0x72, 0x72, 0x72,
		byte(0x00), byte(0x035),
	}
	assert.Bytes(buffer.Value).Named("raw response").Equals(expectedBytes)
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:26,代码来源:socks_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang assert.Bool函数代码示例发布时间:2022-05-28
下一篇:
Golang point.Start函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap