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


Golang require.EqualValues函数代码示例

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


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

示例1: TestUTPPingPong

func TestUTPPingPong(t *testing.T) {
	defer goroutineLeakCheck(t)()
	s, err := NewSocket("udp", "localhost:0")
	require.NoError(t, err)
	defer s.Close()
	pingerClosed := make(chan struct{})
	go func() {
		defer close(pingerClosed)
		b, err := Dial(s.Addr().String())
		require.NoError(t, err)
		defer b.Close()
		n, err := b.Write([]byte("ping"))
		require.NoError(t, err)
		require.EqualValues(t, 4, n)
		buf := make([]byte, 4)
		b.Read(buf)
		require.EqualValues(t, "pong", buf)
		log.Printf("got pong")
	}()
	a, err := s.Accept()
	require.NoError(t, err)
	defer a.Close()
	log.Printf("accepted %s", a)
	buf := make([]byte, 42)
	n, err := a.Read(buf)
	require.NoError(t, err)
	require.EqualValues(t, "ping", buf[:n])
	log.Print("got ping")
	n, err = a.Write([]byte("pong"))
	require.NoError(t, err)
	require.Equal(t, 4, n)
	log.Print("waiting for pinger to close")
	<-pingerClosed
}
开发者ID:diasdavid,项目名称:go-libp2p,代码行数:34,代码来源:utp_test.go

示例2: Test_DynamicUpdateRestoresGoodState

func (s *watcherTestSuite) Test_DynamicUpdateRestoresGoodState() {
	someInt := flagz.DynInt64(s.flagSet, "someint", 1337, "some int usage")
	someFloat := flagz.DynFloat64(s.flagSet, "somefloat", 1.337, "some int usage")
	s.setFlagzValue("someint", "2015")
	require.NoError(s.T(), s.watcher.Initialize())
	require.NoError(s.T(), s.watcher.Start())
	require.EqualValues(s.T(), 2015, someInt.Get(), "int flag should change value")
	require.EqualValues(s.T(), 1.337, someFloat.Get(), "float flag should not change value")

	// Bad update causing a rollback.
	s.setFlagzValue("someint", "randombleh")
	eventually(s.T(), 1*time.Second,
		assert.ObjectsAreEqualValues,
		"2015",
		func() interface{} {
			return s.getFlagzValue("someint")
		},
		"someint failure should revert etcd value to 2015")

	// Make sure we can continue updating.
	s.setFlagzValue("someint", "2016")
	s.setFlagzValue("somefloat", "3.14")
	eventually(s.T(), 1*time.Second,
		assert.ObjectsAreEqualValues, int64(2016),
		func() interface{} { return someInt.Get() },
		"someint value should change, after rolled back")
	eventually(s.T(), 1*time.Second,
		assert.ObjectsAreEqualValues, float64(3.14),
		func() interface{} { return someFloat.Get() },
		"somefloat value should change")

}
开发者ID:mwitkow,项目名称:go-flagz,代码行数:32,代码来源:watcher_test.go

示例3: TestTransactionSingleConnection

func TestTransactionSingleConnection(t *testing.T) {
	db, _ := sql.Open("sqlrpc", serverAddr)
	defer db.Close()
	db.Exec("drop table if exists a")
	tx, _ := db.Begin()
	tx.Exec("create table a(b)")
	tx.Exec("insert into a values(?)", 1)
	t.Log(time.Now())
	row := tx.QueryRow("select * from a where b < ?", 2)
	var i int
	err := row.Scan(&i)
	t.Log(time.Now())
	require.NoError(t, err)
	require.EqualValues(t, 1, i)
	tx.Exec("insert into a values(?)", 2)
	rows, err := tx.Query("select b from a where b > ?", 0)
	require.NoError(t, err)
	cols, _ := rows.Columns()
	require.EqualValues(t, []string{"b"}, cols)
	require.True(t, rows.Next())
	rows.Scan(&i)
	require.EqualValues(t, 1, i)
	require.True(t, rows.Next())
	rows.Scan(&i)
	require.EqualValues(t, 2, i)
	require.False(t, rows.Next())
	tx.Rollback()
}
开发者ID:anacrolix,项目名称:sqlrpc,代码行数:28,代码来源:sqlrpc_test.go

示例4: TestQuery

func TestQuery(t *testing.T) {
	dir1, dir2, _, err := prepare()
	require.NoError(t, err)
	defer closeAll(dir1, dir2)

	// Parse GQL into internal query representation.
	gq, _, err := gql.Parse(q0)
	require.NoError(t, err)

	ctx := context.Background()
	g, err := query.ToSubGraph(ctx, gq)
	require.NoError(t, err)

	// Test internal query representation.
	require.EqualValues(t, childAttrs(g), []string{"follows", "_xid_", "status"})
	require.EqualValues(t, childAttrs(g.Children[0]), []string{"_xid_", "status"})

	ch := make(chan error)
	go query.ProcessGraph(ctx, g, nil, ch)
	err = <-ch
	require.NoError(t, err)

	var l query.Latency
	js, err := g.ToJSON(&l)
	require.NoError(t, err)
	fmt.Println(string(js))
}
开发者ID:dgraph-io,项目名称:dgraph,代码行数:27,代码来源:main_test.go

示例5: TestSendBitfieldThenHave

// Ensure that no race exists between sending a bitfield, and a subsequent
// Have that would potentially alter it.
func TestSendBitfieldThenHave(t *testing.T) {
	r, w := io.Pipe()
	c := &connection{
		t: &Torrent{
			cl: &Client{},
		},
		rw: struct {
			io.Reader
			io.Writer
		}{r, w},
		outgoingUnbufferedMessages: list.New(),
	}
	go c.writer(time.Minute)
	c.mu().Lock()
	c.Bitfield([]bool{false, true, false})
	c.mu().Unlock()
	c.mu().Lock()
	c.Have(2)
	c.mu().Unlock()
	b := make([]byte, 15)
	n, err := io.ReadFull(r, b)
	c.mu().Lock()
	// This will cause connection.writer to terminate.
	c.closed.Set()
	c.mu().Unlock()
	require.NoError(t, err)
	require.EqualValues(t, 15, n)
	// Here we see that the bitfield doesn't have piece 2 set, as that should
	// arrive in the following Have message.
	require.EqualValues(t, "\x00\x00\x00\x02\[email protected]\x00\x00\x00\x05\x04\x00\x00\x00\x02", string(b))
}
开发者ID:jakop345,项目名称:torrent,代码行数:33,代码来源:connection_test.go

示例6: TestSnapshot

func TestSnapshot(t *testing.T) {
	path, err := ioutil.TempDir("", "storetest_")
	require.NoError(t, err)
	defer os.RemoveAll(path)

	s, err := NewStore(path)
	require.NoError(t, err)

	k := []byte("mykey")
	require.NoError(t, s.SetOne(k, []byte("neo")))

	snapshot := s.NewSnapshot() // Snapshot will contain neo, not trinity.
	require.NoError(t, s.SetOne(k, []byte("trinity")))

	// Before setting snapshot, do a get. Expect to get trinity.
	val, err := s.Get(k)
	require.NoError(t, err)
	require.EqualValues(t, val.Data(), "trinity")

	s.SetSnapshot(snapshot)
	// After setting snapshot, we expect to get neo.
	val, err = s.Get(k)
	require.NoError(t, err)
	require.EqualValues(t, val.Data(), "neo")

	s.SetSnapshot(nil)
	// After clearing snapshot, we expect to get trinity again.
	val, err = s.Get(k)
	require.NoError(t, err)
	require.EqualValues(t, val.Data(), "trinity")
}
开发者ID:dgraph-io,项目名称:dgraph,代码行数:31,代码来源:store_test.go

示例7: TestSortInts

func TestSortInts(t *testing.T) {
	list := getInput(Int32ID, []string{"22", "111", "11", "212"})
	ul := getUIDList(4)
	require.NoError(t, int32Type.Sort(list, ul, false))
	require.EqualValues(t, []uint64{300, 100, 200, 400}, ul.Uids)
	require.EqualValues(t, []string{"11", "22", "111", "212"},
		toString(t, list))
}
开发者ID:dgraph-io,项目名称:dgraph,代码行数:8,代码来源:sort_test.go

示例8: TestSortByteArrays

func TestSortByteArrays(t *testing.T) {
	list := getInput(BytesID, []string{"bb", "aaa", "aa", "bab"})
	ul := getUIDList(4)
	require.NoError(t, byteArrayType.Sort(list, ul, false))
	require.EqualValues(t, []uint64{300, 200, 400, 100}, ul.Uids)
	require.EqualValues(t, []string{"aa", "aaa", "bab", "bb"},
		toString(t, list))
}
开发者ID:dgraph-io,项目名称:dgraph,代码行数:8,代码来源:sort_test.go

示例9: TestUnmarshalPex

func TestUnmarshalPex(t *testing.T) {
	var pem peerExchangeMessage
	err := bencode.Unmarshal([]byte("d5:added12:\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0ce"), &pem)
	require.NoError(t, err)
	require.EqualValues(t, 2, len(pem.Added))
	require.EqualValues(t, 1286, pem.Added[0].Port)
	require.EqualValues(t, 0x100*0xb+0xc, pem.Added[1].Port)
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:8,代码来源:pex_test.go

示例10: TestAddMutation_jchiu3

func TestAddMutation_jchiu3(t *testing.T) {
	key := x.DataKey("value", 10)
	dir, err := ioutil.TempDir("", "storetest_")
	require.NoError(t, err)
	defer os.RemoveAll(dir)

	ps, err := store.NewStore(dir)
	require.NoError(t, err)
	Init(ps)
	ol := getNew(key, ps)

	// Set value to cars and merge to RocksDB.
	edge := &task.DirectedEdge{
		Value: []byte("cars"),
		Label: "jchiu",
	}
	addMutation(t, ol, edge, Set)
	require.Equal(t, 1, ol.Length(0))
	merged, err := ol.CommitIfDirty(context.Background())
	require.NoError(t, err)
	require.True(t, merged)
	require.EqualValues(t, 1, ol.Length(0))
	checkValue(t, ol, "cars")

	// Del a value cars and but don't merge.
	edge = &task.DirectedEdge{
		Value: []byte("cars"),
		Label: "jchiu",
	}
	addMutation(t, ol, edge, Del)
	require.Equal(t, 0, ol.Length(0))

	// Set value to newcars, but don't merge yet.
	edge = &task.DirectedEdge{
		Value: []byte("newcars"),
		Label: "jchiu",
	}
	addMutation(t, ol, edge, Set)
	require.EqualValues(t, 1, ol.Length(0))
	checkValue(t, ol, "newcars")

	// Del a value othercars and but don't merge.
	edge = &task.DirectedEdge{
		Value: []byte("othercars"),
		Label: "jchiu",
	}
	addMutation(t, ol, edge, Del)
	require.NotEqual(t, 0, ol.Length(0))
	checkValue(t, ol, "newcars")

	// Del a value newcars and but don't merge.
	edge = &task.DirectedEdge{
		Value: []byte("newcars"),
		Label: "jchiu",
	}
	addMutation(t, ol, edge, Del)
	require.Equal(t, 0, ol.Length(0))
}
开发者ID:dgraph-io,项目名称:dgraph,代码行数:58,代码来源:list_test.go

示例11: TestSortFloatsDesc

func TestSortFloatsDesc(t *testing.T) {
	list := getInput(FloatID, []string{"22.2", "11.2", "11.5", "2.12"})
	ul := getUIDList(4)
	require.NoError(t, floatType.Sort(list, ul, true))
	require.EqualValues(t, []uint64{100, 300, 200, 400}, ul.Uids)
	require.EqualValues(t,
		[]string{"2.22E+01", "1.15E+01", "1.12E+01", "2.12E+00"},
		toString(t, list))
}
开发者ID:dgraph-io,项目名称:dgraph,代码行数:9,代码来源:sort_test.go

示例12: TestSortDates

func TestSortDates(t *testing.T) {
	in := []string{"2022-01-01", "2022-02-03", "2021-01-05", "2021-01-07"}
	list := getInput(DateID, in)
	ul := getUIDList(4)
	require.NoError(t, dateType.Sort(list, ul, false))
	require.EqualValues(t, []uint64{300, 400, 100, 200}, ul.Uids)
	require.EqualValues(t,
		[]string{"2021-01-05", "2021-01-07", "2022-01-01", "2022-02-03"},
		toString(t, list))
}
开发者ID:dgraph-io,项目名称:dgraph,代码行数:10,代码来源:sort_test.go

示例13: TestMarshalAnnounceResponse

func TestMarshalAnnounceResponse(t *testing.T) {
	peers := util.CompactIPv4Peers{
		{[]byte{127, 0, 0, 1}, 2},
		{[]byte{255, 0, 0, 3}, 4},
	}
	b, err := peers.MarshalBinary()
	require.NoError(t, err)
	require.EqualValues(t,
		"\x7f\x00\x00\x01\x00\x02\xff\x00\x00\x03\x00\x04",
		b)
	require.EqualValues(t, 12, binary.Size(AnnounceResponseHeader{}))
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:12,代码来源:udp_test.go

示例14: TestDecoderConsecutive

func TestDecoderConsecutive(t *testing.T) {
	d := NewDecoder(bytes.NewReader([]byte("i1ei2e")))
	var i int
	err := d.Decode(&i)
	require.NoError(t, err)
	require.EqualValues(t, 1, i)
	err = d.Decode(&i)
	require.NoError(t, err)
	require.EqualValues(t, 2, i)
	err = d.Decode(&i)
	require.Equal(t, io.EOF, err)
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:12,代码来源:decode_test.go

示例15: TestKeys

func TestKeys(t *testing.T) {
	k, ok := Keys(map[string]string{"hi": "", "ho": ""})
	require.True(t, ok)
	require.EqualValues(t, []string{"hi", "ho"}, k)
	k, ok = Keys(map[int]string{2: "", 3: ""})
	require.False(t, ok)
	k, ok = Keys(TestStruct{})
	require.True(t, ok)
	require.EqualValues(t, []string{"A1", "A2"}, k)
	k, ok = Keys(TestStruct2{})
	require.True(t, ok)
	require.EqualValues(t, []string{"A2", "lol"}, k)
}
开发者ID:connectordb,项目名称:duck,代码行数:13,代码来源:object_test.go


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