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


Golang assert.String函数代码示例

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


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

示例1: TestHopByHopHeadersStrip

func TestHopByHopHeadersStrip(t *testing.T) {
	assert := assert.On(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.String(req.Header.Get("Foo")).Equals("foo")
	assert.String(req.Header.Get("Bar")).Equals("bar")
	assert.String(req.Header.Get("Connection")).Equals("keep-alive,Foo, Bar")
	assert.String(req.Header.Get("Proxy-Connection")).Equals("keep-alive")
	assert.String(req.Header.Get("Proxy-Authenticate")).Equals("abc")

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

示例2: TestHttpProxy

func TestHttpProxy(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:50042/")
	assert.Error(err).IsNil()
	assert.Int(resp.StatusCode).Equals(200)

	content, err := ioutil.ReadAll(resp.Body)
	assert.Error(err).IsNil()
	assert.String(string(content)).Equals("Home")

	CloseAllServers()
}
开发者ID:ylywyn,项目名称:v2ray-core,代码行数:33,代码来源:http_test.go

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

示例4: TestAccessLog

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

	entry := &AccessLog{
		From:   "test_from",
		To:     "test_to",
		Status: "Accepted",
		Reason: "test_reason",
	}

	entryStr := entry.String()
	assert.String(entryStr).Contains("test_from")
	assert.String(entryStr).Contains("test_to")
	assert.String(entryStr).Contains("test_reason")
	assert.String(entryStr).Contains("Accepted")
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:16,代码来源:log_entry_test.go

示例5: TestChinaSitesJson

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

	rule := ParseRule([]byte(`{
    "type": "chinasites",
    "outboundTag": "y"
  }`))
	assert.String(rule.Tag).Equals("y")
	cond, err := rule.BuildCondition()
	assert.Error(err).IsNil()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("v.qq.com"), 80),
	})).IsTrue()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("www.163.com"), 80),
	})).IsTrue()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("ngacn.cc"), 80),
	})).IsTrue()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("12306.cn"), 80),
	})).IsTrue()

	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("v2ray.com"), 80),
	})).IsFalse()
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:27,代码来源:router_test.go

示例6: TestBuildAndRun

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

	gopath := os.Getenv("GOPATH")
	goOS := parseOS(runtime.GOOS)
	goArch := parseArch(runtime.GOARCH)
	target := filepath.Join(gopath, "src", "v2ray_test")
	if goOS == Windows {
		target += ".exe"
	}
	err := buildV2Ray(target, "v1.0", goOS, goArch)
	assert.Error(err).IsNil()

	outBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
	errBuffer := bytes.NewBuffer(make([]byte, 0, 1024))
	configFile := filepath.Join(gopath, "src", "github.com", "v2ray", "v2ray-core", "tools", "release", "config", "vpoint_socks_vmess.json")
	cmd := exec.Command(target, "--config="+configFile)
	cmd.Stdout = outBuffer
	cmd.Stderr = errBuffer
	cmd.Start()

	<-time.After(1 * time.Second)
	cmd.Process.Kill()

	outStr := string(outBuffer.Bytes())
	errStr := string(errBuffer.Bytes())

	assert.Bool(strings.Contains(outStr, "v1.0")).IsTrue()
	assert.String(errStr).Equals("")

	os.Remove(target)
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:32,代码来源:go_test.go

示例7: TestChinaIPJson

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

	rule := ParseRule([]byte(`{
    "type": "chinaip",
    "outboundTag": "x"
  }`))
	assert.String(rule.Tag).Equals("x")
	cond, err := rule.BuildCondition()
	assert.Error(err).IsNil()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("121.14.1.189"), 80),
	})).IsTrue() // sina.com.cn
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("101.226.103.106"), 80),
	})).IsTrue() // qq.com
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("115.239.210.36"), 80),
	})).IsTrue() // image.baidu.com
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("120.135.126.1"), 80),
	})).IsTrue()

	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("8.8.8.8"), 80),
	})).IsFalse()
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:27,代码来源:router_test.go

示例8: TestSimpleRouter

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

	config := &Config{
		Rule: []*RoutingRule{
			{
				Tag: "test",
				NetworkList: &net.NetworkList{
					Network: []net.Network{net.Network_TCP},
				},
			},
		},
	}

	space := app.NewSpace()
	ctx := app.ContextWithSpace(context.Background(), space)
	assert.Error(app.AddApplicationToSpace(ctx, new(dns.Config))).IsNil()
	assert.Error(app.AddApplicationToSpace(ctx, new(dispatcher.Config))).IsNil()
	assert.Error(app.AddApplicationToSpace(ctx, new(proxyman.OutboundConfig))).IsNil()
	assert.Error(app.AddApplicationToSpace(ctx, config)).IsNil()
	assert.Error(space.Initialize()).IsNil()

	r := FromSpace(space)

	ctx = proxy.ContextWithDestination(ctx, net.TCPDestination(net.DomainAddress("v2ray.com"), 80))
	tag, err := r.TakeDetour(ctx)
	assert.Error(err).IsNil()
	assert.String(tag).Equals("test")
}
开发者ID:ylywyn,项目名称:v2ray-core,代码行数:29,代码来源:router_test.go

示例9: TestSimpleRouter

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

	config := &Config{
		Rule: []*RoutingRule{
			{
				Tag: "test",
				NetworkList: &v2net.NetworkList{
					Network: []v2net.Network{v2net.Network_TCP},
				},
			},
		},
	}

	space := app.NewSpace()
	space.BindApp(dns.APP_ID, dns.NewCacheServer(space, &dns.Config{}))
	space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
	space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, proxyman.NewDefaultOutboundHandlerManager())
	r := NewRouter(config, space)
	space.BindApp(APP_ID, r)
	assert.Error(space.Initialize()).IsNil()

	tag, err := r.TakeDetour(&proxy.SessionInfo{Destination: v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80)})
	assert.Error(err).IsNil()
	assert.String(tag).Equals("test")
}
开发者ID:xyz12810,项目名称:v2ray-core,代码行数:26,代码来源:router_test.go

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

示例11: TestBufferString

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

	buffer := NewBuffer().Clear()
	defer buffer.Release()

	buffer.AppendString("Test String")
	assert.String(buffer.String()).Equals("Test String")
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:9,代码来源:buffer_test.go

示例12: TestRandom

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

	uuid := New()
	uuid2 := New()

	assert.String(uuid.String()).NotEquals(uuid2.String())
	assert.Bytes(uuid.Bytes()).NotEquals(uuid2.Bytes())
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:9,代码来源:uuid_test.go

示例13: TestDomainParsing

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

	rawJson := "\"v2ray.com\""
	var address Address
	err := json.Unmarshal([]byte(rawJson), &address)
	assert.Error(err).IsNil()
	assert.String(address.Domain()).Equals("v2ray.com")
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:9,代码来源:common_test.go

示例14: TestBufferString

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

	buffer := New()
	defer buffer.Release()

	buffer.AppendSupplier(serial.WriteString("Test String"))
	assert.String(buffer.String()).Equals("Test String")
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:9,代码来源:buffer_test.go

示例15: TestUDPReaderWriter

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

	user := &protocol.User{
		Account: serial.ToTypedMessage(&Account{
			Password:   "test-password",
			CipherType: CipherType_CHACHA20_IEFT,
		}),
	}
	cache := buf.New()
	writer := &UDPWriter{
		Writer: cache,
		Request: &protocol.RequestHeader{
			Version: Version,
			Address: v2net.DomainAddress("v2ray.com"),
			Port:    123,
			User:    user,
			Option:  RequestOptionOneTimeAuth,
		},
	}

	reader := &UDPReader{
		Reader: cache,
		User:   user,
	}

	b := buf.New()
	b.AppendSupplier(serial.WriteString("test payload"))
	err := writer.Write(b)
	assert.Error(err).IsNil()

	payload, err := reader.Read()
	assert.Error(err).IsNil()
	assert.String(payload.String()).Equals("test payload")

	b = buf.New()
	b.AppendSupplier(serial.WriteString("test payload 2"))
	err = writer.Write(b)
	assert.Error(err).IsNil()

	payload, err = reader.Read()
	assert.Error(err).IsNil()
	assert.String(payload.String()).Equals("test payload 2")
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:44,代码来源:protocol_test.go


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