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


Golang assert.Must函數代碼示例

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


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

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

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

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

示例4: TestItos

func TestItos(t *testing.T) {
	for i := 0; i < len(imap)*2; i++ {
		n, p := -i, i
		assert.Must(strconv.Itoa(n) == itos(int64(n)))
		assert.Must(strconv.Itoa(p) == itos(int64(p)))
	}
}
開發者ID:TigerZhang,項目名稱:redis-port,代碼行數:7,代碼來源:encoder_test.go

示例5: checkHash

func checkHash(t *testing.T, o interface{}, m map[string]string) {
	x, ok := o.(Hash)
	assert.Must(ok)
	assert.Must(len(x) == len(m))
	for _, e := range x {
		assert.Must(m[string(e.Field)] == string(e.Value))
	}
}
開發者ID:hushi55,項目名稱:Grep,代碼行數:8,代碼來源:encoder_test.go

示例6: checkList

func checkList(t *testing.T, o interface{}, list []string) {
	x, ok := o.(List)
	assert.Must(ok)
	assert.Must(len(x) == len(list))
	for i, e := range x {
		assert.Must(string(e) == list[i])
	}
}
開發者ID:hushi55,項目名稱:Grep,代碼行數:8,代碼來源:encoder_test.go

示例7: checkSet

func checkSet(t *testing.T, o interface{}, set []string) {
	x, ok := o.(Set)
	assert.Must(ok)
	assert.Must(len(x) == len(set))
	for i, e := range x {
		assert.Must(string(e) == set[i])
	}
}
開發者ID:hushi55,項目名稱:Grep,代碼行數:8,代碼來源:encoder_test.go

示例8: TestBytesizeError

func TestBytesizeError(t *testing.T) {
	var err error
	_, err = Parse("--1")
	assert.Must(errors.Equal(err, ErrBadBytesize))
	_, err = Parse("hello world")
	assert.Must(errors.Equal(err, ErrBadBytesize))
	_, err = Parse("123.132.32")
	assert.Must(errors.Equal(err, ErrBadBytesize))
}
開發者ID:TigerZhang,項目名稱:redis-port,代碼行數:9,代碼來源:bytesize_test.go

示例9: 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(len(val) == 32)
	for i := 0; i < len(val); i++ {
		assert.Must(string(val[i]) == strconv.Itoa(i))
	}
}
開發者ID:hushi55,項目名稱:Grep,代碼行數:19,代碼來源:decoder_test.go

示例10: 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(len(val) == 32)
	for i := 0; i < len(val); i++ {
		assert.Must(string(val[i]) == strconv.Itoa(i))
	}
}
開發者ID:hushi55,項目名稱:Grep,代碼行數:20,代碼來源:decoder_test.go

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

示例12: 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(len(val) == 32)
	for i := 0; i < 32; i++ {
		assert.Must(string(val[i]) == strconv.Itoa(i))
	}
}
開發者ID:hushi55,項目名稱:Grep,代碼行數:22,代碼來源:loader_test.go

示例13: 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(bytes.Equal([]byte(val), []byte(key)))
		assert.Must(e.ExpireAt == expireat)
	}
}
開發者ID:hushi55,項目名稱:Grep,代碼行數:25,代碼來源:loader_test.go

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

示例15: TestDecodeSimpleRequest3

func TestDecodeSimpleRequest3(t *testing.T) {
	test := []string{"\r", "\n", " \n"}
	for _, s := range test {
		_, err := DecodeFromBytes([]byte(s))
		assert.Must(err != nil)
	}
}
開發者ID:TigerZhang,項目名稱:redis-port,代碼行數:7,代碼來源:decoder_test.go


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