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

Golang assert.NotZero函数代码示例

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

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



在下文中一共展示了NotZero函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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())
}
开发者ID:skycoin,项目名称:skycoin,代码行数:27,代码来源:node_test.go


示例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")
		}
	}
}
开发者ID:nbutton23,项目名称:zxcvbn-go,代码行数:27,代码来源:matching_test.go


示例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)
}
开发者ID:keichi,项目名称:scribble,代码行数:34,代码来源:note_handler_test.go


示例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)
}
开发者ID:skycoin,项目名称:skycoin,代码行数:60,代码来源:node_test.go


示例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)
}
开发者ID:nicholasjackson,项目名称:sorcery,代码行数:8,代码来源:registration_test.go


示例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")

}
开发者ID:nbutton23,项目名称:zxcvbn-go,代码行数:10,代码来源:matching_test.go


示例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)
}
开发者ID:wawandco,项目名称:fako,代码行数:13,代码来源:fako_test.go


示例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)
}
开发者ID:ChristianKniep,项目名称:swarmkit,代码行数:51,代码来源:memory_test.go


示例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())
}
开发者ID:skycoin,项目名称:skycoin,代码行数:15,代码来源:transport_test.go


示例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
}
开发者ID:gchaincl,项目名称:cardio,代码行数:16,代码来源:pulse_test.go


示例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)
	}
}
开发者ID:elastic,项目名称:gosigar,代码行数:16,代码来源:syscall_windows_test.go


示例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")
	}
}
开发者ID:anovikov1984,项目名称:go,代码行数:27,代码来源:pubnubTime_test.go


示例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")
		}
	}
}
开发者ID:skycoin,项目名称:skycoin,代码行数:47,代码来源:udp_test.go


示例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())
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:8,代码来源:procfs_test.go


示例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)
}
开发者ID:maxkueng,项目名称:go-streamable,代码行数:9,代码来源:streamable_test.go


示例16: TestShouldReturnFailedMethodExecutionResult

func TestShouldReturnFailedMethodExecutionResult(t *testing.T) {
	var called bool
	step := Step{
		Description: "Test description",
		Impl: func(args ...interface{}) {
			called = true
			var a []string
			fmt.Println(a[7])
		},
	}

	res := step.Execute("foo")

	assert.True(t, called)
	assert.True(t, res.GetFailed())
	assert.NotZero(t, res.GetExecutionTime())
	assert.Equal(t, "runtime error: index out of range", res.GetErrorMessage())
	assert.NotZero(t, res.GetStackTrace())
}
开发者ID:manuviswam,项目名称:gauge-go,代码行数:19,代码来源:step_test.go


示例17: TestPutBSO

func TestPutBSO(t *testing.T) {
	db, _ := getTestDB()
	assert := assert.New(t)

	cId := 1
	bId := "b0"

	// test an INSERT
	modified, err := db.PutBSO(cId, bId, String("foo"), Int(1), Int(DEFAULT_BSO_TTL))
	assert.NoError(err)
	assert.NotZero(modified)

	cModified, err := db.GetCollectionModified(cId)
	assert.NoError(err)
	assert.Equal(modified, cModified)

	bso, err := db.GetBSO(cId, bId)
	assert.NoError(err)
	assert.NotNil(bso)
	assert.Equal("foo", bso.Payload)
	assert.Equal(1, bso.SortIndex)

	// sleep a bit so we have a least a 100th of a millisecond difference
	// between the operations
	time.Sleep(19 * time.Millisecond)

	// test the UPDATE
	modified2, err := db.PutBSO(cId, bId, String("bar"), Int(2), Int(DEFAULT_BSO_TTL))
	assert.NoError(err)
	assert.NotZero(modified2)
	assert.NotEqual(modified2, modified)

	cModified, err = db.GetCollectionModified(cId)
	assert.NoError(err)
	assert.Equal(modified2, cModified)

	bso2, err := db.GetBSO(cId, bId)
	assert.NoError(err)
	assert.NotNil(bso2)
	assert.Equal("bar", bso2.Payload)
	assert.Equal(2, bso2.SortIndex)
}
开发者ID:mozilla-services,项目名称:go-syncstorage,代码行数:42,代码来源:db_test.go


示例18: TestChallengePickUsers

func TestChallengePickUsers(t *testing.T) {
	c := newChallenge()

	c.PickUsers(map[string]*User{
		"u1": {PerformanceScore: 20},
		"u2": {PerformanceScore: 40},
	})

	assert.Len(t, c.UsersShown, 2)
	assert.NotZero(t, c.RightAnswerIndex)
}
开发者ID:errows,项目名称:slick,代码行数:11,代码来源:faceoff_test.go


示例19: TestSSHCloneRegexp

func TestSSHCloneRegexp(t *testing.T) {
	assert := assert.New(t)
	segments := sshCloneRegexp.FindStringSubmatch("ssh://[email protected]:3022/at15/tongqu4.git")
	assert.NotZero(segments)
	assert.Equal(5, len(segments))
	segments = sshCloneRegexp.FindStringSubmatch("[email protected]:dyweb/Ayi.git")
	assert.Equal(5, len(segments))
	// t.Log(segments)
	// port is empty
	assert.Equal("", segments[2])
}
开发者ID:dyweb,项目名称:Ayi,代码行数:11,代码来源:remote_test.go


示例20: TestRepeatMatch

func TestRepeatMatch(t *testing.T) {
	//aaaBbBb
	matches := repeatMatch("aaabBbB")

	assert.Len(t, matches, 2, "Lenght should be 2")

	for _, match := range matches {
		if strings.ToLower(match.DictionaryName) == "b" {
			assert.Equal(t, 3, match.I)
			assert.Equal(t, 6, match.J)
			assert.Equal(t, "bBbB", match.Token)
			assert.NotZero(t, match.Entropy, "Entropy should be set")
		} else {
			assert.Equal(t, 0, match.I)
			assert.Equal(t, 2, match.J)
			assert.Equal(t, "aaa", match.Token)
			assert.NotZero(t, match.Entropy, "Entropy should be set")

		}
	}
}
开发者ID:nbutton23,项目名称:zxcvbn-go,代码行数:21,代码来源:matching_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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