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

Golang assert.Must函数代码示例

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

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



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

示例1: TestItos

func TestItos(t *testing.T) {
	for i := 0; i < len(imap)*2; i++ {
		n, p := -i, i
		assert.Must(t, strconv.Itoa(n) == itos(int64(n)))
		assert.Must(t, strconv.Itoa(p) == itos(int64(p)))
	}
}
开发者ID:shitfSign,项目名称:qdb,代码行数:7,代码来源:encoder_test.go


示例2: testPipe2

func testPipe2(t *testing.T, fileName string) {
	r, w := openPipe(t, fileName)

	c := 1024 * 128
	s := "Hello world!!"

	go func() {
		for i := 0; i < c; i++ {
			m := fmt.Sprintf("[%d]%s ", i, s)
			_, err := ioutils.WriteFull(w, []byte(m))
			assert.ErrorIsNil(t, err)
		}
		assert.ErrorIsNil(t, w.Close())
	}()

	time.Sleep(time.Millisecond * 100)

	buf := make([]byte, len(s)*c*2)
	n, err := ioutils.ReadFull(r, buf)
	assert.Must(t, errors.Equal(err, io.EOF))
	buf = buf[:n]
	for i := 0; i < c; i++ {
		m := fmt.Sprintf("[%d]%s ", i, s)
		assert.Must(t, len(buf) >= len(m))
		assert.Must(t, string(buf[:len(m)]) == m)
		buf = buf[len(m):]
	}
	assert.Must(t, len(buf) == 0)
	assert.ErrorIsNil(t, r.Close())
}
开发者ID:shitfSign,项目名称:qdb,代码行数:30,代码来源:pipe_test.go


示例3: checkList

func checkList(t *testing.T, o interface{}, list []string) {
	x, ok := o.(List)
	assert.Must(t, ok)
	assert.Must(t, len(x) == len(list))
	for i, e := range x {
		assert.Must(t, string(e) == list[i])
	}
}
开发者ID:shitfSign,项目名称:qdb,代码行数:8,代码来源:encoder_test.go


示例4: checkHash

func checkHash(t *testing.T, o interface{}, m map[string]string) {
	x, ok := o.(Hash)
	assert.Must(t, ok)
	assert.Must(t, len(x) == len(m))
	for _, e := range x {
		assert.Must(t, m[string(e.Field)] == string(e.Value))
	}
}
开发者ID:shitfSign,项目名称:qdb,代码行数:8,代码来源:encoder_test.go


示例5: checkSet

func checkSet(t *testing.T, o interface{}, set []string) {
	x, ok := o.(Set)
	assert.Must(t, ok)
	assert.Must(t, len(x) == len(set))
	for i, e := range x {
		assert.Must(t, string(e) == set[i])
	}
}
开发者ID:shitfSign,项目名称:qdb,代码行数:8,代码来源:encoder_test.go


示例6: TestBytesizeError

func TestBytesizeError(t *testing.T) {
	var err error
	_, err = Parse("--1")
	assert.Must(t, errors.Equal(err, ErrBadBytesize))
	_, err = Parse("hello world")
	assert.Must(t, errors.Equal(err, ErrBadBytesize))
	_, err = Parse("123.132.32")
	assert.Must(t, errors.Equal(err, ErrBadBytesize))
}
开发者ID:shitfSign,项目名称:qdb,代码行数:9,代码来源:bytesize_test.go


示例7: TestDecodeList

/*
#!/bin/bash
for ((i=0;i<32;i++)); do
	./redis-cli rpush list $i
done
./redis-cli dump list
*/
func TestDecodeList(t *testing.T) {
	s := `
		0120c000c001c002c003c004c005c006c007c008c009c00ac00bc00cc00dc00e
		c00fc010c011c012c013c014c015c016c017c018c019c01ac01bc01cc01dc01e
		c01f0600e87781cbebc997f5
	`
	val := hexStringToObject(t, s).(List)
	assert.Must(t, len(val) == 32)
	for i := 0; i < len(val); i++ {
		assert.Must(t, string(val[i]) == strconv.Itoa(i))
	}
}
开发者ID:shitfSign,项目名称:qdb,代码行数:19,代码来源:decoder_test.go


示例8: TestDecodeListZipmap

/*
#!/bin/bash
for ((i=0;i<32;i++)); do
	./redis-cli rpush list $i
done
./redis-cli dump list
*/
func TestDecodeListZipmap(t *testing.T) {
	s := `
		0a405e5e0000005a000000200000f102f202f302f402f502f602f702f802f902
		fa02fb02fc02fd02fe0d03fe0e03fe0f03fe1003fe1103fe1203fe1303fe1403
		fe1503fe1603fe1703fe1803fe1903fe1a03fe1b03fe1c03fe1d03fe1e03fe1f
		ff060052f7f617938b332a
	`
	val := hexStringToObject(t, s).(List)
	assert.Must(t, len(val) == 32)
	for i := 0; i < len(val); i++ {
		assert.Must(t, string(val[i]) == strconv.Itoa(i))
	}
}
开发者ID:shitfSign,项目名称:qdb,代码行数:20,代码来源:decoder_test.go


示例9: TestPipeReadClose2

func TestPipeReadClose2(t *testing.T) {
	r, w := Pipe()
	c := make(chan int, 1)

	go delayClose(t, r, c, pipeTest{})

	n, err := r.Read(make([]byte, 64))
	<-c

	assert.Must(t, errors.Equal(err, io.ErrClosedPipe))
	assert.Must(t, n == 0)
	assert.ErrorIsNil(t, w.Close())
}
开发者ID:shitfSign,项目名称:qdb,代码行数:13,代码来源:pipe_test.go


示例10: TestLoadList

/*
#!/bin/bash
./redis-cli flushall
for ((i=0;i<32;i++)); do
    ./redis-cli rpush list ${i}
done
./redis-cli save && xxd -p -c 32 dump.rdb
*/
func TestLoadList(t *testing.T) {
	s := `
		524544495330303036fe0001046c69737420c000c001c002c003c004c005c006
		c007c008c009c00ac00bc00cc00dc00ec00fc010c011c012c013c014c015c016
		c017c018c019c01ac01bc01cc01dc01ec01fff756ea1fa90adefe3
	`
	entries := DecodeHexRdb(t, s, 1)
	_, obj := getobj(t, entries, "list")
	val := obj.(List)
	assert.Must(t, len(val) == 32)
	for i := 0; i < 32; i++ {
		assert.Must(t, string(val[i]) == strconv.Itoa(i))
	}
}
开发者ID:shitfSign,项目名称:qdb,代码行数:22,代码来源:loader_test.go


示例11: TestWriteNil

func TestWriteNil(t *testing.T) {
	r, w := Pipe()

	go func() {
		_, err := w.Write(nil)
		assert.ErrorIsNil(t, err)
		assert.ErrorIsNil(t, w.Close())
	}()

	buf := make([]byte, 4096)
	n, err := ioutils.ReadFull(r, buf)
	assert.Must(t, errors.Equal(err, io.EOF))
	assert.Must(t, n == 0)
	assert.ErrorIsNil(t, r.Close())
}
开发者ID:shitfSign,项目名称:qdb,代码行数:15,代码来源:pipe_test.go


示例12: getobj

func getobj(t *testing.T, entries map[string]*BinEntry, key string) (*BinEntry, interface{}) {
	e := entries[key]
	assert.Must(t, e != nil)
	o, err := DecodeDump(e.Value)
	assert.ErrorIsNil(t, err)
	return e, o
}
开发者ID:shitfSign,项目名称:qdb,代码行数:7,代码来源:loader_test.go


示例13: TestDecodeInvalidRequests

func TestDecodeInvalidRequests(t *testing.T) {
	test := []string{
		"",
		"*hello\r\n",
		"*-100\r\n",
		"*3\r\nhi",
		"*3\r\nhi\r\n",
		"*4\r\n$1",
		"*4\r\n$1\r",
		"*4\r\n$1\n",
		"*2\r\n$3\r\nget\r\n$what?\r\nx\r\n",
		"*4\r\n$3\r\nget\r\n$1\r\nx\r\n",
		"*2\r\n$3\r\nget\r\n$1\r\nx",
		"*2\r\n$3\r\nget\r\n$1\r\nx\r",
		"*2\r\n$3\r\nget\r\n$100\r\nx\r\n",
		"$6\r\nfoobar\r",
		"$0\rn\r\n",
		"$-1\n",
		"*0",
		"*2n$3\r\nfoo\r\n$3\r\nbar\r\n",
		"3\r\n:1\r\n:2\r\n:3\r\n",
		"*-\r\n",
		"+OK\n",
		"-Error message\r",
	}
	for _, s := range test {
		_, err := DecodeFromBytes([]byte(s))
		assert.Must(t, err != nil)
	}
}
开发者ID:shitfSign,项目名称:qdb,代码行数:30,代码来源:decoder_test.go


示例14: TestLoadStringTTL

/*
#!/bin/bash
./redis-cli flushall
./redis-cli set string_ttls string_ttls
./redis-cli expireat string_ttls 1500000000
./redis-cli set string_ttlms string_ttlms
./redis-cli pexpireat string_ttlms 1500000000000
./redis-cli save && xxd -p -c 32 dump.rdb
*/
func TestLoadStringTTL(t *testing.T) {
	s := `
		524544495330303036fe00fc0098f73e5d010000000c737472696e675f74746c
		6d730c737472696e675f74746c6d73fc0098f73e5d010000000b737472696e67
		5f74746c730b737472696e675f74746c73ffd15acd935a3fe949
	`
	expireat := uint64(1500000000000)
	entries := DecodeHexRdb(t, s, 2)
	keys := []string{"string_ttls", "string_ttlms"}
	for _, key := range keys {
		e, obj := getobj(t, entries, key)
		val := obj.(String)
		assert.Must(t, bytes.Equal([]byte(val), []byte(key)))
		assert.Must(t, e.ExpireAt == expireat)
	}
}
开发者ID:shitfSign,项目名称:qdb,代码行数:25,代码来源:loader_test.go


示例15: hexStringToObject

func hexStringToObject(t *testing.T, s string) interface{} {
	p, err := hex.DecodeString(strings.NewReplacer("\t", "", "\r", "", "\n", "", " ", "").Replace(s))
	assert.ErrorIsNil(t, err)
	o, err := DecodeDump(p)
	assert.ErrorIsNil(t, err)
	assert.Must(t, o != nil)
	return o
}
开发者ID:shitfSign,项目名称:qdb,代码行数:8,代码来源:decoder_test.go


示例16: testPipe1

func testPipe1(t *testing.T, fileName string) {
	r, w := openPipe(t, fileName)

	s := "Hello world!!"

	go func(data []byte) {
		_, err := ioutils.WriteFull(w, data)
		assert.ErrorIsNil(t, err)
		assert.ErrorIsNil(t, w.Close())
	}([]byte(s))

	buf := make([]byte, 64)
	n, err := ioutils.ReadFull(r, buf)
	assert.Must(t, errors.Equal(err, io.EOF))
	assert.Must(t, n == len(s))
	assert.Must(t, string(buf[:n]) == s)
	assert.ErrorIsNil(t, r.Close())
}
开发者ID:shitfSign,项目名称:qdb,代码行数:18,代码来源:pipe_test.go


示例17: TestDecodeSet

/*
#!/bin/bash
for ((i=0;i<32;i++)); do
	./redis-cli sadd set $i
done
./redis-cli dump set
*/
func TestDecodeSet(t *testing.T) {
	s := `
		0220c016c00dc01bc012c01ac004c014c002c017c01dc01cc013c019c01ec008
		c006c000c001c007c00fc009c01fc00ec003c00ac015c010c00bc018c011c00c
		c00506007bd0a89270890016
	`
	val := hexStringToObject(t, s).(Set)
	assert.Must(t, len(val) == 32)
	set := make(map[string]bool)
	for _, mem := range val {
		set[string(mem)] = true
	}
	assert.Must(t, len(val) == len(set))
	for i := 0; i < 32; i++ {
		_, ok := set[strconv.Itoa(i)]
		assert.Must(t, ok)
	}
}
开发者ID:shitfSign,项目名称:qdb,代码行数:25,代码来源:decoder_test.go


示例18: TestLoadListZipmap

/*
#!/bin/bash
./redis-cli flushall
for ((i=0;i<256;i++)); do
    ./redis-cli rpush list_lzf 0
    ./redis-cli rpush list_lzf 1
done
./redis-cli save && xxd -p -c 32 dump.rdb
*/
func TestLoadListZipmap(t *testing.T) {
	s := `
		524544495330303036fe000a086c6973745f6c7a66c31f440b040b0400000820
		0306000200f102f202e0ff03e1ff07e1ff07e1d90701f2ffff6a1c2d51c02301
		16
	`
	entries := DecodeHexRdb(t, s, 1)
	_, obj := getobj(t, entries, "list_lzf")
	val := obj.(List)
	assert.Must(t, len(val) == 512)
	for i := 0; i < 256; i++ {
		var s string = "0"
		if i%2 != 0 {
			s = "1"
		}
		assert.Must(t, string(val[i]) == s)
	}
}
开发者ID:shitfSign,项目名称:qdb,代码行数:27,代码来源:loader_test.go


示例19: testPipe3

func testPipe3(t *testing.T, fileName string) {
	r, w := openPipe(t, fileName)

	c := make(chan int)

	size := 4096

	go func() {
		buf := make([]byte, size)
		for {
			n, err := r.Read(buf)
			if errors.Equal(err, io.EOF) {
				break
			}
			assert.ErrorIsNil(t, err)
			c <- n
		}
		assert.ErrorIsNil(t, r.Close())
		c <- 0
	}()

	go func() {
		buf := make([]byte, size)
		for i := 1; i < size; i++ {
			n, err := ioutils.WriteFull(w, buf[:i])
			assert.ErrorIsNil(t, err)
			assert.Must(t, n == i)
		}
		assert.ErrorIsNil(t, w.Close())
	}()

	sum := 0
	for i := 1; i < size; i++ {
		sum += i
	}
	for {
		n := <-c
		if n == 0 {
			break
		}
		sum -= n
	}
	assert.Must(t, sum == 0)
}
开发者ID:shitfSign,项目名称:qdb,代码行数:44,代码来源:pipe_test.go


示例20: testPipe4

func testPipe4(t *testing.T, fileName string) {
	r, w := openPipe(t, fileName)

	key := []byte("spinlock aes-128")

	block := aes.BlockSize
	count := 1024 * 1024 * 128 / block

	go func() {
		buf := make([]byte, count*block)
		m, err := aes.NewCipher(key)
		assert.ErrorIsNil(t, err)
		for i := 0; i < len(buf); i++ {
			buf[i] = byte(i)
		}

		e := cipher.NewCBCEncrypter(m, make([]byte, block))
		e.CryptBlocks(buf, buf)

		n, err := ioutils.WriteFull(w, buf)
		assert.ErrorIsNil(t, err)
		assert.ErrorIsNil(t, w.Close())
		assert.Must(t, n == len(buf))
	}()

	buf := make([]byte, count*block)
	m, err := aes.NewCipher(key)
	assert.ErrorIsNil(t, err)

	_, err = ioutils.ReadFull(r, buf)
	assert.ErrorIsNil(t, err)

	e := cipher.NewCBCDecrypter(m, make([]byte, block))
	e.CryptBlocks(buf, buf)

	for i := 0; i < len(buf); i++ {
		assert.Must(t, buf[i] == byte(i))
	}
	_, err = ioutils.ReadFull(r, buf)
	assert.Must(t, errors.Equal(err, io.EOF))
	assert.ErrorIsNil(t, r.Close())
}
开发者ID:shitfSign,项目名称:qdb,代码行数:42,代码来源:pipe_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang engine.NewBatch函数代码示例发布时间:2022-05-28
下一篇:
Golang resp.NewString函数代码示例发布时间: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