本文整理汇总了Golang中github.com/stretchr/testify/assert.Zero函数的典型用法代码示例。如果您正苦于以下问题:Golang Zero函数的具体用法?Golang Zero怎么用?Golang Zero使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Zero函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUpdateUser
func TestUpdateUser(t *testing.T) {
phone := "18801234567"
secret := "8428d916f8cca9ba5971bf58b34d38da20bc3dff"
phone2 := "18801234568"
// insert two
user, err := models.CreateUserByPhone(&phone, secret)
assert.Zero(t, err)
user2, err := models.CreateUserByPhone(&phone2, secret)
assert.Zero(t, err)
weixin := "wx:piasy_umumu"
user.WeiXin = &weixin
user.Nickname = "Piasy"
user.Gender = 1
err = models.UpdateUser(user)
assert.Zero(t, err)
got, err := models.GetUserByToken(user.Token)
assert.Zero(t, err)
assertUserEquals(t, user, got)
user.Phone = &phone2
err = models.UpdateUser(user)
assert.Equal(t, utils.ERROR_CODE_SYSTEM_ERROR, err)
deleteUser(t, user.Id)
deleteUser(t, user2.Id)
}
示例2: TestRouteExpiry
func TestRouteExpiry(t *testing.T) {
allConnections := [][]int{
[]int{0, 1, 0},
[]int{1, 0, 1},
[]int{0, 1, 0},
}
nodes, toClose, transports := SetupNodes((uint)(3), allConnections, t)
defer close(toClose)
defer func() {
for _, node := range nodes {
node.Close()
}
}()
addedRouteID := domain.RouteID{}
addedRouteID[0] = 55
addedRouteID[1] = 4
assert.Nil(t, nodes[0].AddRoute(addedRouteID, nodes[1].GetConfig().PubKey))
{
lastConfirmed, err := nodes[0].GetRouteLastConfirmed(addedRouteID)
assert.Nil(t, err)
assert.Zero(t, lastConfirmed.Unix())
}
assert.Nil(t, nodes[0].ExtendRoute(addedRouteID, nodes[2].GetConfig().PubKey, time.Second))
assert.NotZero(t, nodes[1].DebugCountRoutes())
var afterExtendConfirmedTime time.Time
{
lastConfirmed, err := nodes[0].GetRouteLastConfirmed(addedRouteID)
assert.Nil(t, err)
afterExtendConfirmedTime = lastConfirmed
}
time.Sleep(5 * time.Second)
assert.NotZero(t, nodes[1].DebugCountRoutes())
var afterWaitConfirmedTime time.Time
{
lastConfirmed, err := nodes[0].GetRouteLastConfirmed(addedRouteID)
assert.Nil(t, err)
afterWaitConfirmedTime = lastConfirmed
}
// Don't allow refreshes to get thru
transports[0].SetIgnoreSendStatus(true)
time.Sleep(5 * time.Second)
var afterIgnoreConfirmedTime time.Time
{
lastConfirmed, err := nodes[0].GetRouteLastConfirmed(addedRouteID)
assert.Nil(t, err)
afterIgnoreConfirmedTime = lastConfirmed
}
assert.Zero(t, nodes[1].DebugCountRoutes())
assert.NotZero(t, afterExtendConfirmedTime)
assert.NotZero(t, afterWaitConfirmedTime)
assert.NotEqual(t, afterExtendConfirmedTime, afterWaitConfirmedTime)
assert.Equal(t, afterWaitConfirmedTime, afterIgnoreConfirmedTime)
}
示例3: TestFloat64
func TestFloat64(t *testing.T) {
assert := assert.New(t)
UnsetKey("envconf_test1")
UnsetKey("envconf_test2")
v, ok := GetFloat64("envconf_test1")
assert.False(ok)
assert.Zero(v)
assert.Panics(func() { MustGetFloat64("envconf_test1") })
SetString("envconf_test1", "blahBlah")
v, ok = GetFloat64("envconf_test1")
assert.False(ok)
assert.Zero(v)
assert.Panics(func() { MustGetFloat64("envconf_test1") })
SetString("envconf_test1", "83.3")
v, ok = GetFloat64("envconf_test1")
assert.True(ok)
assert.True(floatEquals(83.3, v))
assert.True(floatEquals(83.3, MustGetFloat64("envconf_test1")))
SetDefaultFloat64("envconf_test1", -434.43202)
v, ok = GetFloat64("envconf_test1")
assert.True(ok)
assert.True(floatEquals(83.3, v))
assert.True(floatEquals(83.3, MustGetFloat64("envconf_test1")))
SetDefaultFloat64("envconf_test2", -0.3424562)
v, ok = GetFloat64("envconf_test2")
assert.True(ok)
assert.True(floatEquals(-0.3424562, v))
assert.True(floatEquals(-0.3424562, MustGetFloat64("envconf_test2")))
}
示例4: TestInt
func TestInt(t *testing.T) {
assert := assert.New(t)
UnsetKey("envconf_test1")
UnsetKey("envconf_test2")
v, ok := GetInt("envconf_test1")
assert.False(ok)
assert.Zero(v)
assert.Panics(func() { MustGetInt("envconf_test1") })
SetString("envconf_test1", "blahBlah")
v, ok = GetInt("envconf_test1")
assert.False(ok)
assert.Zero(v)
assert.Panics(func() { MustGetInt("envconf_test1") })
SetString("envconf_test1", "42")
v, ok = GetInt("envconf_test1")
assert.True(ok)
assert.Equal(42, v)
assert.Equal(42, MustGetInt("envconf_test1"))
SetDefaultInt("envconf_test1", -5)
v, ok = GetInt("envconf_test1")
assert.True(ok)
assert.Equal(42, v)
assert.Equal(42, MustGetInt("envconf_test1"))
SetDefaultInt("envconf_test2", -33)
v, ok = GetInt("envconf_test2")
assert.True(ok)
assert.Equal(-33, v)
assert.Equal(-33, MustGetInt("envconf_test2"))
}
示例5: TestDeleteRoute
func TestDeleteRoute(t *testing.T) {
allConnections := [][]int{
[]int{0, 1, 0},
[]int{1, 0, 1},
[]int{0, 1, 0},
}
nodes, toClose, _ := SetupNodes((uint)(3), allConnections, t)
defer close(toClose)
defer func() {
for _, node := range nodes {
node.Close()
}
}()
addedRouteID := domain.RouteID{}
addedRouteID[0] = 55
addedRouteID[1] = 4
assert.Nil(t, nodes[0].AddRoute(addedRouteID, nodes[1].GetConfig().PubKey))
assert.Nil(t, nodes[0].ExtendRoute(addedRouteID, nodes[2].GetConfig().PubKey, time.Second))
time.Sleep(5 * time.Second)
assert.NotZero(t, nodes[0].DebugCountRoutes())
assert.NotZero(t, nodes[1].DebugCountRoutes())
assert.Nil(t, nodes[0].DeleteRoute(addedRouteID))
time.Sleep(1 * time.Second)
assert.Zero(t, nodes[0].DebugCountRoutes())
assert.Zero(t, nodes[1].DebugCountRoutes())
}
示例6: TestDuration
func TestDuration(t *testing.T) {
assert := assert.New(t)
UnsetKey("envconf_test1")
UnsetKey("envconf_test2")
v, ok := GetDuration("envconf_test1")
assert.False(ok)
assert.Zero(v)
assert.Panics(func() { MustGetDuration("envconf_test1") })
SetString("envconf_test1", "blahBlah")
v, ok = GetDuration("envconf_test1")
assert.False(ok)
assert.Zero(v)
assert.Panics(func() { MustGetDuration("envconf_test1") })
SetString("envconf_test1", "15s")
v, ok = GetDuration("envconf_test1")
assert.True(ok)
assert.Equal(15*time.Second, v)
assert.Equal(15*time.Second, MustGetDuration("envconf_test1"))
SetDefaultDuration("envconf_test1", 12*time.Millisecond)
v, ok = GetDuration("envconf_test1")
assert.True(ok)
assert.Equal(15*time.Second, v)
assert.Equal(15*time.Second, MustGetDuration("envconf_test1"))
SetDefaultDuration("envconf_test2", 33*time.Millisecond)
v, ok = GetDuration("envconf_test2")
assert.True(ok)
assert.Equal(33*time.Millisecond, v)
assert.Equal(33*time.Millisecond, MustGetDuration("envconf_test2"))
}
示例7: TestGettingBatches
func TestGettingBatches(t *testing.T) {
b := NewBuffer(20)
// Verify that the buffer returned is smaller than requested when there are
// not as many items as requested.
b.Add(metricList...)
batch := b.Batch(10)
assert.Len(t, batch, 5)
// Verify that the buffer is now empty
assert.True(t, b.IsEmpty())
assert.Zero(t, b.Len())
assert.Zero(t, b.Drops())
assert.Equal(t, b.Total(), 5)
// Verify that the buffer returned is not more than the size requested
b.Add(metricList...)
batch = b.Batch(3)
assert.Len(t, batch, 3)
// Verify that buffer is not empty
assert.False(t, b.IsEmpty())
assert.Equal(t, b.Len(), 2)
assert.Equal(t, b.Drops(), 0)
assert.Equal(t, b.Total(), 10)
}
示例8: TestPipeChaining
func TestPipeChaining(t *testing.T) {
tmpdir := setupTestDir(t)
defer os.RemoveAll(tmpdir)
h, err := GetExternalHandlerFromMimeType("text/plain")
assert.Nil(t, err)
mh, err := GetExternalHandlerFromMimeType("application/x-bzip2")
assert.Nil(t, err)
fh, err := ioutil.TempFile(tmpdir, "outfile")
assert.Nil(t, err)
start_r, err := h.Decompress(path.Join(tmpdir, "pipechaining"))
assert.Nil(t, err)
mr, err := mh.CompressStream(start_r)
assert.Nil(t, err)
_, err = io.Copy(fh, mr)
assert.Nil(t, err)
//fh.Close()
//start_r.Close()
//mr.Close()
// Check job results
assert.Zero(t, start_r.Result())
assert.Zero(t, mr.Result())
}
示例9: TestFormWithEmptyContent
func TestFormWithEmptyContent(t *testing.T) {
identifier := vari.NewVarID("TestForm")
exampleForm := NewForm(identifier, NewEmptyStmtList())
assert.Equal(t, exampleForm.Identifier(), identifier)
assert.Zero(t, len(exampleForm.Content().Questions()))
assert.Zero(t, len(exampleForm.Content().Conditionals()))
}
示例10: TestSet
func TestSet(t *testing.T) {
assert.Zero(t, getValue(0))
Set(0, 1)
assert.Zero(t, getValue(0))
const attr = 23456
for i := 0; i < 10; i++ {
Set(attr, uint64(i))
assert.Equal(t, uint64(i), getValue(attr))
}
}
示例11: TestAdd
func TestAdd(t *testing.T) {
assert.Zero(t, getValue(0))
Add(0, 1)
assert.Zero(t, getValue(0))
const attr = 123456
val := getValue(attr)
for i := 0; i < 10; i++ {
Add(attr, uint64(i))
val += uint64(i)
assert.Equal(t, val, getValue(attr))
}
}
示例12: TestBuildWithoutParams
func TestBuildWithoutParams(t *testing.T) {
item := new(Item)
item.Build(Values)
assert.True(t, item.Date.IsZero())
assert.Zero(t, item.CategoryID)
assert.Zero(t, item.Sum)
assert.Empty(t, item.Description)
}
示例13: TestString_ZeroAllocs
func TestString_ZeroAllocs(t *testing.T) {
v := "jumped over the lazy dog"
b := make([]byte, len(v)+1)
assert.Zero(t, testing.AllocsPerRun(1, func() { PutString(b, v) }))
assert.Zero(t, testing.AllocsPerRun(1, func() { String(b) }))
//Note that while the String function requires zero allocations,
//the decoded string can still escape...
var x string
assert.Equal(t, 1.0, testing.AllocsPerRun(1, func() {
s := String(b)
x = s
}))
assert.Equal(t, v, x)
}
示例14: TestExpiry
func TestExpiry(t *testing.T) {
_, testKeyB, _, _,
transportA, transportB,
_, _ := SetupTwoPeers(t)
testContents := []byte{4, 3, 22, 6, 88, 99}
assert.Nil(t, transportA.SendMessage(testKeyB, testContents, nil))
time.Sleep(time.Second)
assert.NotZero(t, transportA.debug_countMapItems())
assert.NotZero(t, transportB.debug_countMapItems())
time.Sleep(7 * time.Second)
assert.Zero(t, transportA.debug_countMapItems())
assert.Zero(t, transportB.debug_countMapItems())
}
示例15: TestFireZerosPotential
func TestFireZerosPotential(t *testing.T) {
silenceLog()
na := NewNeuron("A")
na.potential = 10
na.Fire()
assert.Zero(t, na.potential)
}