當前位置: 首頁>>代碼示例>>Golang>>正文


Golang testing.Current函數代碼示例

本文整理匯總了Golang中github.com/v2ray/v2ray-core/testing.Current函數的典型用法代碼示例。如果您正苦於以下問題:Golang Current函數的具體用法?Golang Current怎麽用?Golang Current使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Current函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/v2ray/v2ray-core/testing.Current函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。