本文整理汇总了Golang中github.com/stretchr/testify/assert.NotZero函数的典型用法代码示例。如果您正苦于以下问题:Golang NotZero函数的具体用法?Golang NotZero怎么用?Golang NotZero使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NotZero函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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())
}
示例2: TestSequenceMatch
func TestSequenceMatch(t *testing.T) {
//abcdjibjacLMNOPjibjac1234 => abcd LMNOP 1234
matches := sequenceMatch("abcdjibjacLMNOPjibjac1234")
assert.Len(t, matches, 3, "Lenght should be 2")
for _, match := range matches {
if match.DictionaryName == "lower" {
assert.Equal(t, 0, match.I)
assert.Equal(t, 3, match.J)
assert.Equal(t, "abcd", match.Token)
assert.NotZero(t, match.Entropy, "Entropy should be set")
} else if match.DictionaryName == "upper" {
assert.Equal(t, 10, match.I)
assert.Equal(t, 14, match.J)
assert.Equal(t, "LMNOP", match.Token)
assert.NotZero(t, match.Entropy, "Entropy should be set")
} else if match.DictionaryName == "digits" {
assert.Equal(t, 21, match.I)
assert.Equal(t, 24, match.J)
assert.Equal(t, "1234", match.Token)
assert.NotZero(t, match.Entropy, "Entropy should be set")
} else {
assert.True(t, false, "Unknow dictionary")
}
}
}
示例3: TestAddNote
func TestAddNote(t *testing.T) {
assert := assert.New(t)
dbMap := initDb()
defer dbMap.Db.Close()
ctx := context.Background()
ctx = context.WithValue(ctx, "db", dbMap)
ctx = context.WithValue(ctx, "auth", &auth.AuthContext{})
server := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
AddNote(ctx, w, r)
},
))
defer server.Close()
resp := request(t, server.URL, http.StatusOK, map[string]interface{}{
"title": "Test Title",
"content": "lorem ipsum dolor sit amet consetetur.",
"ownerId": 0,
})
assert.NotNil(resp)
note := resp.(map[string]interface{})
assert.Equal("Test Title", note["title"])
assert.Equal("lorem ipsum dolor sit amet consetetur.", note["content"])
assert.EqualValues(0, note["ownerId"])
assert.NotZero(note["createdAt"])
assert.NotZero(note["updatedAt"])
count, err := dbMap.SelectInt("SELECT COUNT(id) FROM notes")
assert.Nil(err)
assert.EqualValues(1, count)
}
示例4: 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)
}
示例5: TestCreatesCorrectly
func TestCreatesCorrectly(t *testing.T) {
registration := CreateNewRegistration("myevent", "mycallback")
assert.NotZero(t, registration.Id)
assert.NotZero(t, registration.CreationDate)
assert.Equal(t, "myevent", registration.EventName)
assert.Equal(t, "mycallback", registration.CallbackUrl)
}
示例6: TestSpatialMatchQwerty
func TestSpatialMatchQwerty(t *testing.T) {
matches := spatialMatch("qwerty")
assert.Len(t, matches, 1, "Lenght should be 1")
assert.NotZero(t, matches[0].Entropy, "Entropy should be set")
matches = spatialMatch("asdf")
assert.Len(t, matches, 1, "Lenght should be 1")
assert.NotZero(t, matches[0].Entropy, "Entropy should be set")
}
示例7: TestFillAll
func TestFillAll(t *testing.T) {
customName := struct {
Name string `fako:"full_name"`
}{}
customU := struct {
Username string `fako:"user_name"`
}{}
Fill(&customName, &customU)
assert.NotZero(t, customName.Name)
assert.NotZero(t, customU.Username)
}
示例8: TestTimestamps
func TestTimestamps(t *testing.T) {
var mockProposer mockProposer
s := NewMemoryStore(&mockProposer)
assert.NotNil(t, s)
var (
retrievedNode *api.Node
updatedNode *api.Node
)
// Create one node
n := &api.Node{
ID: "id1",
Spec: api.NodeSpec{
Annotations: api.Annotations{
Name: "name1",
},
},
}
err := s.Update(func(tx Tx) error {
assert.NoError(t, CreateNode(tx, n))
return nil
})
assert.NoError(t, err)
// Make sure our local copy got updated.
assert.NotZero(t, n.Meta.CreatedAt)
assert.NotZero(t, n.Meta.UpdatedAt)
// Since this is a new node, CreatedAt should equal UpdatedAt.
assert.Equal(t, n.Meta.CreatedAt, n.Meta.UpdatedAt)
// Fetch the node from the store and make sure timestamps match.
s.View(func(tx ReadTx) {
retrievedNode = GetNode(tx, n.ID)
})
assert.Equal(t, retrievedNode.Meta.CreatedAt, n.Meta.CreatedAt)
assert.Equal(t, retrievedNode.Meta.UpdatedAt, n.Meta.UpdatedAt)
// Make an update.
retrievedNode.Spec.Annotations.Name = "name2"
err = s.Update(func(tx Tx) error {
assert.NoError(t, UpdateNode(tx, retrievedNode))
updatedNode = GetNode(tx, n.ID)
return nil
})
assert.NoError(t, err)
// Ensure `CreatedAt` is the same after the update and `UpdatedAt` got updated.
assert.Equal(t, updatedNode.Meta.CreatedAt, n.Meta.CreatedAt)
assert.NotEqual(t, updatedNode.Meta.CreatedAt, updatedNode.Meta.UpdatedAt)
}
示例9: 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())
}
示例10: TestPulseEmitTheRightBeatFormat
func TestPulseEmitTheRightBeatFormat(t *testing.T) {
done := make(chan struct{})
NewPulse("test", newTestBackend(t,
func(t *testing.T, beat Beat) {
assert.Equal(t, "test", beat.Name)
assert.Equal(t, runtime.NumGoroutine(), beat.Values["num_goroutines"])
assert.NotZero(t, beat.Values["alloc"])
assert.NotZero(t, beat.Values["total_alloc"])
done <- struct{}{}
}),
).Tick(1 * time.Millisecond)
<-done
}
示例11: TestNtQuerySystemProcessorPerformanceInformation
func TestNtQuerySystemProcessorPerformanceInformation(t *testing.T) {
cpus, err := NtQuerySystemProcessorPerformanceInformation()
if err != nil {
t.Fatal(err)
}
assert.Len(t, cpus, runtime.NumCPU())
for i, cpu := range cpus {
assert.NotZero(t, cpu.IdleTime)
assert.NotZero(t, cpu.KernelTime)
assert.NotZero(t, cpu.UserTime)
t.Logf("CPU=%v SystemProcessorPerformanceInformation=%v", i, cpu)
}
}
示例12: TestServerTime
// TestServerTime calls the GetTime method of the messaging to test the time
func TestServerTime(t *testing.T) {
stop, _ := NewVCRNonSubscribe("fixtures/time", []string{})
defer stop()
pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "", false, "testTime")
assert := assert.New(t)
successChannel := make(chan []byte)
errorChannel := make(chan []byte)
go pubnubInstance.GetTime(successChannel, errorChannel)
select {
case value := <-successChannel:
response := string(value)
timestamp, err := strconv.Atoi(strings.Trim(response, "[]\n"))
if err != nil {
assert.Fail(err.Error())
}
assert.NotZero(timestamp)
case err := <-errorChannel:
assert.Fail(string(err))
case <-timeouts(10):
assert.Fail("Getting server timestamp timeout")
}
}
示例13: TestSendDatagram
func TestSendDatagram(t *testing.T) {
transportA, keyA, transportB, keyB := SetupAB(false, t)
defer transportA.Close()
defer transportB.Close()
testKeyC := cipher.NewPubKey([]byte{3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
assert.Zero(t, transportA.GetMaximumMessageSizeToPeer(keyA))
assert.NotZero(t, transportA.GetMaximumMessageSizeToPeer(keyB))
assert.NotZero(t, transportB.GetMaximumMessageSizeToPeer(keyA))
assert.Zero(t, transportB.GetMaximumMessageSizeToPeer(keyB))
assert.Zero(t, transportA.GetMaximumMessageSizeToPeer(testKeyC))
assert.Zero(t, transportB.GetMaximumMessageSizeToPeer(testKeyC))
sendBytesA := []byte{66, 44, 33, 2, 123, 100, 22}
sendBytesB := []byte{23, 33, 12, 88, 43, 120}
assert.Nil(t, transportA.SendMessage(keyB, sendBytesA, nil))
assert.Nil(t, transportB.SendMessage(keyA, sendBytesB, nil))
chanA := make(chan []byte, 10)
chanB := make(chan []byte, 10)
transportA.SetReceiveChannel(chanA)
transportB.SetReceiveChannel(chanB)
gotA := false
gotB := false
for !gotA || !gotB {
select {
case msg_a := <-chanA:
{
assert.Equal(t, sendBytesB, msg_a)
gotA = true
break
}
case msg_b := <-chanB:
{
assert.Equal(t, sendBytesA, msg_b)
gotB = true
break
}
case <-time.After(5 * time.Second):
panic("Test timed out")
}
}
}
示例14: TestPidOf
func TestPidOf(t *testing.T) {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
t.Skipf("not supported on GOOS=%s", runtime.GOOS)
}
pids := PidOf(filepath.Base(os.Args[0]))
assert.NotZero(t, pids)
assert.Contains(t, pids, os.Getpid())
}
示例15: Test_UploadVideo
func Test_UploadVideo(t *testing.T) {
testFile := path.Join(testFilesDir, "cat-video.mp4")
c := New()
res, err := c.UploadVideo(testFile)
assert.Nil(t, err)
assert.NotZero(t, res)
}