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


Golang assert.On函數代碼示例

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


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

示例1: TestSwitchAccount

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

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

	buffer := buf.New()
	err := MarshalCommand(sa, buffer)
	assert.Error(err).IsNil()

	cmd, err := UnmarshalCommand(1, buffer.BytesFrom(2))
	assert.Error(err).IsNil()

	sa2, ok := cmd.(*protocol.CommandSwitchAccount)
	assert.Bool(ok).IsTrue()
	assert.Pointer(sa.Host).IsNil()
	assert.Pointer(sa2.Host).IsNil()
	assert.Port(sa.Port).Equals(sa2.Port)
	assert.String(sa.ID.String()).Equals(sa2.ID.String())
	assert.Uint16(sa.AlterIds).Equals(sa2.AlterIds)
	assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level))
	assert.Byte(sa.ValidMin).Equals(sa2.ValidMin)
}
開發者ID:v2ray,項目名稱:v2ray-core,代碼行數:28,代碼來源:commands_test.go

示例2: TestInvalidUserJson

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

	user := new(User)
	err := json.Unmarshal([]byte(`{"email": 1234}`), user)
	assert.Error(err).IsNotNil()
}
開發者ID:v2ray,項目名稱:v2ray-core,代碼行數:7,代碼來源:common_test.go

示例3: 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

示例4: TestRevParse

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

	rev, err := RevParse("HEAD")
	assert.Error(err).IsNil()
	assert.Int(len(rev)).GreaterThan(0)
}
開發者ID:DZLZHCODE,項目名稱:v2ray-core,代碼行數:7,代碼來源:git_test.go

示例5: TestWrongProtocolVersion

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

	buffer := alloc.NewBuffer().Clear().AppendBytes(6, 1, 0)
	_, _, err := ReadAuthentication(buffer)
	assert.Error(err).Equals(proxy.ErrInvalidProtocolVersion)
}
開發者ID:xyz12810,項目名稱:v2ray-core,代碼行數:7,代碼來源:socks_test.go

示例6: TestACKSegment

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

	seg := &AckSegment{
		Conv:            1,
		ReceivingWindow: 2,
		ReceivingNext:   3,
		Timestamp:       10,
		NumberList:      []uint32{1, 3, 5, 7, 9},
	}

	nBytes := seg.ByteSize()
	bytes := make([]byte, nBytes)
	seg.Bytes()(bytes)

	assert.Int(len(bytes)).Equals(nBytes)

	iseg, _ := ReadSegment(bytes)
	seg2 := iseg.(*AckSegment)
	assert.Uint16(seg2.Conv).Equals(seg.Conv)
	assert.Uint32(seg2.ReceivingWindow).Equals(seg.ReceivingWindow)
	assert.Uint32(seg2.ReceivingNext).Equals(seg.ReceivingNext)
	assert.Int(len(seg2.NumberList)).Equals(len(seg.NumberList))
	assert.Uint32(seg2.Timestamp).Equals(seg.Timestamp)
	for i, number := range seg2.NumberList {
		assert.Uint32(number).Equals(seg.NumberList[i])
	}
}
開發者ID:ylywyn,項目名稱:v2ray-core,代碼行數:28,代碼來源:segment_test.go

示例7: 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

示例8: TestBlockHTTP

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

	httpServer := &v2http.Server{
		Port:        net.Port(50042),
		PathHandler: make(map[string]http.HandlerFunc),
	}
	_, err := httpServer.Start()
	assert.Error(err).IsNil()
	defer httpServer.Close()

	assert.Error(InitializeServerSetOnce("test_5")).IsNil()

	transport := &http.Transport{
		Proxy: func(req *http.Request) (*url.URL, error) {
			return url.Parse("http://127.0.0.1:50040/")
		},
	}

	client := &http.Client{
		Transport: transport,
	}

	resp, err := client.Get("http://127.0.0.1:50049/")
	assert.Error(err).IsNil()
	assert.Int(resp.StatusCode).Equals(403)

	CloseAllServers()
}
開發者ID:ylywyn,項目名稱:v2ray-core,代碼行數:29,代碼來源:http_test.go

示例9: TestDnsAdd

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

	space := app.NewSpace()

	outboundHandlerManager := proxyman.NewDefaultOutboundHandlerManager()
	outboundHandlerManager.SetDefaultHandler(
		freedom.NewFreedomConnection(
			&freedom.Config{},
			space,
			&proxy.OutboundHandlerMeta{
				Address: v2net.AnyIP,
				StreamSettings: &internet.StreamSettings{
					Type: internet.StreamConnectionTypeRawTCP,
				},
			}))
	space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, outboundHandlerManager)
	space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))

	domain := "local.v2ray.com"
	server := NewCacheServer(space, &Config{
		NameServers: []v2net.Destination{
			v2net.UDPDestination(v2net.IPAddress([]byte{8, 8, 8, 8}), v2net.Port(53)),
		},
	})
	space.BindApp(APP_ID, server)
	space.Initialize()

	ips := server.Get(domain)
	assert.Int(len(ips)).Equals(1)
	assert.IP(ips[0].To4()).Equals(net.IP([]byte{127, 0, 0, 1}))
}
開發者ID:DZLZHCODE,項目名稱:v2ray-core,代碼行數:32,代碼來源:server_test.go

示例10: 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

示例11: 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

示例12: 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

示例13: TestNext

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

	uuid := New()
	uuid2 := uuid.Next()
	assert.Bool(uuid.Equals(uuid2)).IsFalse()
}
開發者ID:DZLZHCODE,項目名稱:v2ray-core,代碼行數:7,代碼來源:uuid_test.go

示例14: TestBuildMacOS

func TestBuildMacOS(t *testing.T) {
	assert := assert.On(t)
	binPath = filepath.Join(os.Getenv("GOPATH"), "testing")
	cleanBinPath()

	build("macos", "amd64", true, "test", "metadata.txt")
	assert.Bool(allFilesExists(
		"v2ray-macos.zip",
		"v2ray-test-macos",
		filepath.Join("v2ray-test-macos", "config.json"),
		filepath.Join("v2ray-test-macos", "v2ray"))).IsTrue()

	build("windows", "amd64", true, "test", "metadata.txt")
	assert.Bool(allFilesExists(
		"v2ray-windows-64.zip",
		"v2ray-test-windows-64",
		filepath.Join("v2ray-test-windows-64", "config.json"),
		filepath.Join("v2ray-test-windows-64", "v2ray.exe"))).IsTrue()

	build("linux", "amd64", true, "test", "metadata.txt")
	assert.Bool(allFilesExists(
		"v2ray-linux-64.zip",
		"v2ray-test-linux-64",
		filepath.Join("v2ray-test-linux-64", "vpoint_socks_vmess.json"),
		filepath.Join("v2ray-test-linux-64", "vpoint_vmess_freedom.json"),
		filepath.Join("v2ray-test-linux-64", "v2ray"))).IsTrue()
}
開發者ID:DZLZHCODE,項目名稱:v2ray-core,代碼行數:27,代碼來源:build_test.go

示例15: TestCmdSegment

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

	seg := &CmdOnlySegment{
		Conv:         1,
		Cmd:          CommandPing,
		Option:       SegmentOptionClose,
		SendingNext:  11,
		ReceivinNext: 13,
		PeerRTO:      15,
	}

	nBytes := seg.ByteSize()
	bytes := make([]byte, nBytes)
	seg.Bytes()(bytes)

	assert.Int(len(bytes)).Equals(nBytes)

	iseg, _ := ReadSegment(bytes)
	seg2 := iseg.(*CmdOnlySegment)
	assert.Uint16(seg2.Conv).Equals(seg.Conv)
	assert.Byte(byte(seg2.Command())).Equals(byte(seg.Command()))
	assert.Byte(byte(seg2.Option)).Equals(byte(seg.Option))
	assert.Uint32(seg2.SendingNext).Equals(seg.SendingNext)
	assert.Uint32(seg2.ReceivinNext).Equals(seg.ReceivinNext)
	assert.Uint32(seg2.PeerRTO).Equals(seg.PeerRTO)
}
開發者ID:ylywyn,項目名稱:v2ray-core,代碼行數:27,代碼來源:segment_test.go


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