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

Golang assert.MustNoError函数代码示例

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

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



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

示例1: TestWriteAfterWriterClose

func TestWriteAfterWriterClose(t *testing.T) {
	r, w := New()

	s := "hello"

	errs := make(chan error)

	go func() {
		n, err := w.Write([]byte(s))
		assert.MustNoError(err)
		assert.Must(n == len(s))
		assert.MustNoError(w.Close())
		_, err = w.Write([]byte("world"))
		errs <- err
	}()

	buf := make([]byte, 4096)
	n, err := io.ReadFull(r, buf)
	assert.Must(errors.Equal(err, io.EOF))
	assert.Must(string(buf[:n]) == s)

	err = <-errs
	assert.Must(errors.Equal(err, io.ErrClosedPipe))
	assert.MustNoError(r.Close())
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:25,代码来源:pipe_test.go


示例2: testPipe2

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

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

	go func() {
		for i := 0; i < c; i++ {
			m := fmt.Sprintf("[%d]%s ", i, s)
			n, err := w.Write([]byte(m))
			assert.MustNoError(err)
			assert.Must(n == len(m))
		}
		assert.MustNoError(w.Close())
	}()

	time.Sleep(time.Millisecond * 10)

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


示例3: hexStringToObject

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


示例4: TestServerServe

func TestServerServe(t *testing.T) {
	h := &testHandler{make(map[string]int)}
	s, err := NewServer(h)
	assert.MustNoError(err)
	resp, err := Decode(bufio.NewReader(bytes.NewReader([]byte("*2\r\n$3\r\nset\r\n$3\r\nfoo\r\n"))))
	assert.MustNoError(err)
	_, err = s.Dispatch(nil, resp)
	assert.MustNoError(err)
	testmapcount(t, h.c, map[string]int{"foo": 1})
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:10,代码来源:server_test.go


示例5: TestDecodeSimpleRequest1

func TestDecodeSimpleRequest1(t *testing.T) {
	resp, err := DecodeFromBytes([]byte("\r\n"))
	assert.MustNoError(err)
	x, ok := resp.(*Array)
	assert.Must(ok)
	assert.Must(len(x.Value) == 0)
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:7,代码来源:decoder_test.go


示例6: TestEncodeHash

func TestEncodeHash(t *testing.T) {
	docheck := func(m map[string]string) {
		p, err := EncodeDump(toHash(m))
		assert.MustNoError(err)
		o, err := DecodeDump(p)
		assert.MustNoError(err)
		checkHash(t, o, m)
	}
	docheck(map[string]string{"": ""})
	docheck(map[string]string{"": "", "a": "", "b": "a", "c": "b", "d": "c"})
	hash := make(map[string]string)
	for i := 0; i < 65536; i++ {
		hash[strconv.Itoa(i)] = strconv.Itoa(i + 1)
	}
	docheck(hash)
}
开发者ID:hushi55,项目名称:Grep,代码行数:16,代码来源:encoder_test.go


示例7: TestEncodeList

func TestEncodeList(t *testing.T) {
	docheck := func(list ...string) {
		p, err := EncodeDump(toList(list...))
		assert.MustNoError(err)
		o, err := DecodeDump(p)
		assert.MustNoError(err)
		checkList(t, o, list)
	}
	docheck("")
	docheck("", "a", "b", "c", "d", "e")
	list := []string{}
	for i := 0; i < 65536; i++ {
		list = append(list, strconv.Itoa(i))
	}
	docheck(list...)
}
开发者ID:hushi55,项目名称:Grep,代码行数:16,代码来源:encoder_test.go


示例8: TestEncodeSet

func TestEncodeSet(t *testing.T) {
	docheck := func(set ...string) {
		p, err := EncodeDump(toSet(set...))
		assert.MustNoError(err)
		o, err := DecodeDump(p)
		assert.MustNoError(err)
		checkSet(t, o, set)
	}
	docheck("")
	docheck("", "a", "b", "c")
	set := []string{}
	for i := 0; i < 65536; i++ {
		set = append(set, strconv.Itoa(i))
	}
	docheck(set...)
}
开发者ID:hushi55,项目名称:Grep,代码行数:16,代码来源:encoder_test.go


示例9: getobj

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


示例10: testBacklog

func testBacklog(t *testing.T, bl *Backlog, size int) {
	input := randSlice(32)

	r1, err := bl.NewReader()
	assert.MustNoError(err)

	checkWriter(bl, input)
	checkReader(r1, input)
	checkReader(r1, []byte{})

	input = randSlice(size)
	checkWriter(bl, input)
	checkReader(r1, input)
	checkWriter(bl, randSlice(size))

	assert.Must(r1.IsValid() == true)

	r2, err := bl.NewReader()
	assert.MustNoError(err)

	input = []byte{0xde, 0xad, 0xbe, 0xef}
	checkWriter(bl, input)

	assert.Must(r1.IsValid() == false)

	_, err = r1.Read([]byte{0})
	assert.Must(errors.Equal(err, ErrInvalidOffset))

	b := make([]byte, len(input))
	n, err := io.ReadFull(r2, b)
	assert.MustNoError(err)
	assert.Must(n == len(b) && bytes.Equal(b, input))

	bl.Close()

	assert.Must(r1.IsValid() == false)
	assert.Must(r2.IsValid() == false)

	_, err = r1.Read([]byte{0})
	assert.Must(errors.Equal(err, ErrClosedBacklog))

	_, err = r2.Read([]byte{0})
	assert.Must(errors.Equal(err, ErrClosedBacklog))

	_, err = bl.Write([]byte{0})
	assert.Must(errors.Equal(err, ErrClosedBacklog))
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:47,代码来源:backlog_test.go


示例11: testPipe3

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

	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.MustNoError(err)
			c <- n
		}
		assert.MustNoError(r.Close())
		c <- 0
	}()

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

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


示例12: TestEncodeString

func TestEncodeString(t *testing.T) {
	docheck := func(text string) {
		p, err := EncodeDump(toString(text))
		assert.MustNoError(err)
		o, err := DecodeDump(p)
		assert.MustNoError(err)
		checkString(t, o, text)
	}
	docheck("hello world!!")
	docheck("2147483648")
	docheck("4294967296")
	docheck("")
	var b bytes.Buffer
	for i := 0; i < 1024; i++ {
		b.Write([]byte("01"))
	}
	docheck(b.String())
}
开发者ID:hushi55,项目名称:Grep,代码行数:18,代码来源:encoder_test.go


示例13: TestWriteNil

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

	go func() {
		n, err := w.Write(nil)
		assert.MustNoError(err)
		assert.Must(n == 0)
		assert.MustNoError(w.Close())
	}()

	time.Sleep(time.Millisecond * 10)

	buf := make([]byte, 4096)
	n, err := io.ReadFull(r, buf)
	assert.Must(errors.Equal(err, io.EOF))
	assert.Must(n == 0)
	assert.MustNoError(r.Close())
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:18,代码来源:pipe_test.go


示例14: TestEncodeZSet

func TestEncodeZSet(t *testing.T) {
	docheck := func(m map[string]float64) {
		p, err := EncodeDump(toZSet(m))
		assert.MustNoError(err)
		o, err := DecodeDump(p)
		assert.MustNoError(err)
		checkZSet(t, o, m)
	}
	docheck(map[string]float64{"": 0})
	zset := make(map[string]float64)
	for i := -65535; i < 65536; i++ {
		zset[strconv.Itoa(i)] = float64(i)
	}
	docheck(zset)
	zset["inf"] = math.Inf(1)
	zset["-inf"] = math.Inf(-1)
	zset["nan"] = math.NaN()
	docheck(zset)
}
开发者ID:hushi55,项目名称:Grep,代码行数:19,代码来源:encoder_test.go


示例15: delayClose

func delayClose(t *testing.T, closer Closer, c chan int, u pipeTest) {
	time.Sleep(time.Millisecond * 10)
	var err error
	if u.witherr {
		err = closer.CloseWithError(u.err)
	} else {
		err = closer.Close()
	}
	assert.MustNoError(err)
	c <- 0
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:11,代码来源:pipe_test.go


示例16: testPipe1

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

	s := "Hello world!!"

	go func(data []byte) {
		n, err := w.Write(data)
		assert.MustNoError(err)
		assert.Must(n == len(data))
		assert.MustNoError(w.Close())
	}([]byte(s))

	buf := make([]byte, 64)
	n, err := io.ReadFull(r, buf)
	assert.Must(errors.Equal(err, io.EOF))
	assert.Must(n == len(s))
	assert.Must(string(buf[:n]) == s)
	assert.MustNoError(r.Close())
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:20,代码来源:pipe_test.go


示例17: TestPipeReadClose2

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

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

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

	assert.Must(errors.Equal(err, io.ErrClosedPipe))
	assert.Must(n == 0)
	assert.MustNoError(w.Close())
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:13,代码来源:pipe_test.go


示例18: openPipe

func openPipe(t *testing.T, fileName string) (pr Reader, pw Writer, pf *os.File) {
	buffSize := 8192
	fileSize := 1024 * 1024 * 32
	if fileName == "" {
		pr, pw = NewSize(buffSize)
	} else {
		f, err := os.OpenFile(fileName, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0600)
		assert.MustNoError(err)
		pr, pw = NewFilePipe(fileSize, f)
		pf = f
	}
	return
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:13,代码来源:pipe_test.go


示例19: TestDecodeBulkBytes

func TestDecodeBulkBytes(t *testing.T) {
	test := "*2\r\n$4\r\nLLEN\r\n$6\r\nmylist\r\n"
	resp, err := DecodeFromBytes([]byte(test))
	assert.MustNoError(err)
	x, ok := resp.(*Array)
	assert.Must(ok)
	assert.Must(len(x.Value) == 2)
	s1, ok := x.Value[0].(*BulkBytes)
	assert.Must(ok)
	assert.Must(bytes.Equal(s1.Value, []byte("LLEN")))
	s2, ok := x.Value[1].(*BulkBytes)
	assert.Must(ok)
	assert.Must(bytes.Equal(s2.Value, []byte("mylist")))
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:14,代码来源:decoder_test.go


示例20: DecodeHexRdb

func DecodeHexRdb(t *testing.T, s string, n int) map[string]*BinEntry {
	p, err := hex.DecodeString(strings.NewReplacer("\t", "", "\r", "", "\n", "", " ", "").Replace(s))
	assert.MustNoError(err)
	r := bytes.NewReader(p)
	l := NewLoader(r)
	assert.MustNoError(l.Header())
	entries := make(map[string]*BinEntry)
	var i int = 0
	for {
		e, err := l.NextBinEntry()
		assert.MustNoError(err)
		if e == nil {
			break
		}
		assert.Must(e.DB == 0)
		entries[string(e.Key)] = e
		i++
	}
	assert.MustNoError(l.Footer())
	assert.Must(r.Len() == 0)
	assert.Must(len(entries) == i && i == n)
	return entries
}
开发者ID:hushi55,项目名称:Grep,代码行数:23,代码来源:loader_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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