本文整理汇总了Golang中github.com/stretchr/testify/assert.Zero函数的典型用法代码示例。如果您正苦于以下问题:Golang Zero函数的具体用法?Golang Zero怎么用?Golang Zero使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Zero函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:Piasy,项目名称:BeegoTDDBootStrap,代码行数:29,代码来源:user_test.go
示例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)
}
开发者ID:skycoin,项目名称:skycoin,代码行数:60,代码来源:node_test.go
示例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")))
}
开发者ID:sboehmann,项目名称:envconf,代码行数:35,代码来源:envconf_test.go
示例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"))
}
开发者ID:sboehmann,项目名称:envconf,代码行数:35,代码来源:envconf_test.go
示例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())
}
开发者ID:skycoin,项目名称:skycoin,代码行数:27,代码来源:node_test.go
示例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"))
}
开发者ID:sboehmann,项目名称:envconf,代码行数:35,代码来源:envconf_test.go
示例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)
}
开发者ID:jeichorn,项目名称:telegraf,代码行数:26,代码来源:buffer_test.go
示例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())
}
开发者ID:RamiroCruzo,项目名称:extcompress,代码行数:30,代码来源:extcompress_test.go
示例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()))
}
开发者ID:software-engineering-amsterdam,项目名称:multi-ql,代码行数:8,代码来源:stmt_test.go
示例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))
}
}
开发者ID:daidodo,项目名称:monitor,代码行数:11,代码来源:attr_test.go
示例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))
}
}
开发者ID:daidodo,项目名称:monitor,代码行数:13,代码来源:attr_test.go
示例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)
}
开发者ID:tksasha,项目名称:go-balance-backend,代码行数:13,代码来源:item_test.go
示例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)
}
开发者ID:pennydb,项目名称:lex,代码行数:15,代码来源:encoding_test.go
示例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())
}
开发者ID:skycoin,项目名称:skycoin,代码行数:15,代码来源:transport_test.go
示例15: TestFireZerosPotential
func TestFireZerosPotential(t *testing.T) {
silenceLog()
na := NewNeuron("A")
na.potential = 10
na.Fire()
assert.Zero(t, na.potential)
}
开发者ID:mattbaker,项目名称:celegans,代码行数:7,代码来源:neuron_test.go
示例16: TestLobbyAdd
func TestLobbyAdd(t *testing.T) {
t.Parallel()
lobby := testhelpers.CreateLobby()
defer lobby.Close(false)
lobby.Save()
var players []*Player
for i := 0; i < 12; i++ {
player := testhelpers.CreatePlayer()
players = append(players, player)
}
// add player
err := lobby.AddPlayer(players[0], 0, "")
assert.Nil(t, err)
slot, err2 := lobby.GetPlayerSlot(players[0])
assert.Zero(t, slot)
assert.Nil(t, err2)
id, err3 := lobby.GetPlayerIDBySlot(0)
assert.Equal(t, id, players[0].ID)
assert.Nil(t, err3)
// try to switch slots
err = lobby.AddPlayer(players[0], 1, "")
assert.Nil(t, err)
slot, err2 = lobby.GetPlayerSlot(players[0])
assert.Equal(t, slot, 1)
assert.Nil(t, err2)
// this should be empty now
id, err3 = lobby.GetPlayerIDBySlot(0)
assert.NotNil(t, err3)
// try to add a second player to the same slot
err = lobby.AddPlayer(players[1], 1, "")
assert.NotNil(t, err)
// try to add a player to a wrong slot slot
err = lobby.AddPlayer(players[2], 55, "")
assert.NotNil(t, err)
lobby2 := testhelpers.CreateLobby()
defer lobby.Close(false)
lobby2.Save()
// try to add a player while they're in another lobby
//player should be substituted
lobby.State = LobbyStateInProgress
lobby.Save()
err = lobby2.AddPlayer(players[0], 1, "")
assert.Nil(t, err)
var count int
db.DB.Table("lobby_slots").Where("lobby_id = ? AND needs_sub = ?", lobby.ID, true).Count(&count)
assert.Equal(t, count, 1)
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:60,代码来源:lobby_test.go
示例17: TestDataStoreDeleteConcurrent
func TestDataStoreDeleteConcurrent(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
ds := NewDataStore(cs)
datasetID := "ds1"
datasets := ds.Datasets()
assert.Zero(datasets.Len())
// |a|
a := types.NewString("a")
aCommit := NewCommit().SetValue(a)
ds, err := ds.Commit(datasetID, aCommit)
assert.NoError(err)
// |a| <- |b|
b := types.NewString("b")
bCommit := NewCommit().SetValue(b).SetParents(NewSetOfRefOfCommit().Insert(NewRefOfCommit(aCommit.Ref())))
ds2, err := ds.Commit(datasetID, bCommit)
assert.NoError(err)
assert.True(ds.Head(datasetID).Value().Equals(a))
assert.True(ds2.Head(datasetID).Value().Equals(b))
ds, err = ds.Delete(datasetID)
assert.NoError(err)
h, present := ds.MaybeHead(datasetID)
assert.False(present, "Dataset %s should not be present, but head is %v", datasetID, h.Value())
h, present = ds2.MaybeHead(datasetID)
assert.True(present, "Dataset %s should be present", datasetID)
// Get a fresh datastore, and verify that no datastores are present
newDs := NewDataStore(cs)
datasets = newDs.Datasets()
assert.Equal(uint64(0), datasets.Len())
}
开发者ID:arv,项目名称:noms-old,代码行数:35,代码来源:datastore_test.go
示例18: TestDataStoreDelete
func TestDataStoreDelete(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewMemoryStore()
ds := NewDataStore(cs)
datasetID1, datasetID2 := "ds1", "ds2"
datasets := ds.Datasets()
assert.Zero(datasets.Len())
// |a|
a := types.NewString("a")
ds, err := ds.Commit(datasetID1, NewCommit().SetValue(a))
assert.NoError(err)
assert.True(ds.Head(datasetID1).Value().Equals(a))
// ds1; |a|, ds2: |b|
b := types.NewString("b")
ds, err = ds.Commit(datasetID2, NewCommit().SetValue(b))
assert.NoError(err)
assert.True(ds.Head(datasetID2).Value().Equals(b))
ds, err = ds.Delete(datasetID1)
assert.NoError(err)
assert.True(ds.Head(datasetID2).Value().Equals(b))
h, present := ds.MaybeHead(datasetID1)
assert.False(present, "Dataset %s should not be present, but head is %v", datasetID1, h.Value())
// Get a fresh datastore, and verify that only ds1 is present
newDs := NewDataStore(cs)
datasets = newDs.Datasets()
assert.Equal(uint64(1), datasets.Len())
_, present = ds.MaybeHead(datasetID2)
assert.True(present, "Dataset %s should be present", datasetID2)
}
开发者ID:arv,项目名称:noms-old,代码行数:34,代码来源:datastore_test.go
示例19: TestPlaying
func TestPlaying(t *testing.T) {
sut := getSut()
assert.Zero(t, sut.Data.Status)
sut.IsPlaying()
assert.Equal(t, Playing, sut.Data.Status)
}
开发者ID:avadhutp,项目名称:lazarus,代码行数:7,代码来源:feed_model_test.go
示例20: TestOptionsSetPreflightHeaders
func TestOptionsSetPreflightHeaders(t *testing.T) {
headers := http.Header{}
opts := &Options{
AllowOrigins: "https://example.com, https://foo.com",
AllowMethods: "PUT, PATCH",
AllowHeaders: "X-Ping, X-Pong",
AllowCredentials: false,
ExposeHeaders: "X-Ping, X-Pong",
MaxAge: time.Duration(100) * time.Second,
}
opts.init()
opts.setPreflightHeaders("https://bar.com", "PUT", "", headers)
assert.Zero(t, len(headers))
headers = http.Header{}
opts.setPreflightHeaders("https://foo.com", "PUT", "X-Pong", headers)
assert.Equal(t, "https://foo.com", headers.Get(headerAllowOrigin))
assert.Equal(t, "PUT, PATCH", headers.Get(headerAllowMethods))
assert.Equal(t, "100", headers.Get(headerMaxAge))
assert.Equal(t, "X-Pong", headers.Get(headerAllowHeaders))
headers = http.Header{}
opts = &Options{
AllowOrigins: "*",
AllowMethods: "*",
AllowHeaders: "*",
}
opts.init()
opts.setPreflightHeaders("https://bar.com", "PUT", "X-Pong", headers)
assert.Equal(t, "*", headers.Get(headerAllowOrigin))
assert.Equal(t, "PUT", headers.Get(headerAllowMethods))
assert.Equal(t, "X-Pong", headers.Get(headerAllowHeaders))
}
开发者ID:go-ozzo,项目名称:ozzo-routing,代码行数:33,代码来源:handler_test.go
注:本文中的github.com/stretchr/testify/assert.Zero函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论