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

Golang assert.NoError函数代码示例

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

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



在下文中一共展示了NoError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestSaveSnapshot

func TestSaveSnapshot(t *testing.T) {
	const (
		site     = "TestUpdateReadDeletePackageHistory.com"
		path     = "gcse"
		foundWay = "testing"
	)
	assert.NoError(t, UpdatePackageHistory(site, path, func(info *sppb.HistoryInfo) error {
		assert.Equal(t, "info", info, &sppb.HistoryInfo{})
		info.FoundWay = foundWay
		return nil
	}))
	h, err := ReadPackageHistory(site, path)
	assert.NoError(t, err)
	assert.Equal(t, "h", h, &sppb.HistoryInfo{FoundWay: foundWay})

	outPath := villa.Path(os.TempDir()).Join("TestSaveSnapshot").S()
	assert.NoError(t, SaveSnapshot(outPath))
	box := &bh.RefCountBox{
		DataPath: func() string {
			return outPath
		},
	}
	h, err = ReadPackageHistoryOf(box, site, path)
	assert.NoError(t, err)
	assert.Equal(t, "h", h, &sppb.HistoryInfo{FoundWay: foundWay})
}
开发者ID:xavieryang007,项目名称:gcse,代码行数:26,代码来源:history_test.go


示例2: TestInc

func TestInc(t *testing.T) {
	DataPath = "./tmp.bolt"
	FlushPeriod = time.Second
	err := os.RemoveAll(DataPath)
	if err != nil && err != os.ErrNotExist {
		assert.NoError(t, err)
		return
	}

	now := time.Now()
	Inc("abc")
	Flush()
	Process()

	names, err := ReadNames()
	assert.NoError(t, err)
	assert.Equal(t, "names", names, []string{"abc"})

	data, err := ReadDataOfName("daily", "abc")
	assert.NoError(t, err)
	assert.Equal(t, "data", data, []LabeledCounter{{
		Counter{
			Sum: 1,
			Div: 1,
		},
		now.Format("2006-01-02"),
	}})
}
开发者ID:daviddengcn,项目名称:go-easybi,代码行数:28,代码来源:bi_test.go


示例3: TestUnmarshalFile

func TestUnmarshalFile(t *testing.T) {
	fn := path.Join(os.TempDir(), "TestMarshalToFile.json")
	assert.NoError(t, ioutil.WriteFile(fn, []byte(`{"S":"abc"}`), 0644))
	var s T
	assert.NoError(t, UnmarshalFile(fn, &s))
	assert.Equal(t, "s.S", s.S, "abc")
}
开发者ID:golangplus,项目名称:encoding,代码行数:7,代码来源:json_test.go


示例4: TestForEachPackageOfSite

func TestForEachPackageOfSite(t *testing.T) {
	// Clear the database
	configs.StoreBoltPath().RemoveAll()

	const (
		site  = "TestForEachPackageOfSite.com"
		path1 = "gcse"
		name1 = "pkgname"
		path2 = "gcse2"
		name2 = "TestForEachPackageOfSite"
	)
	assert.NoError(t, UpdatePackage(site, path1, func(info *stpb.PackageInfo) error {
		info.Name = name1
		return nil
	}))
	assert.NoError(t, UpdatePackage(site, path2, func(info *stpb.PackageInfo) error {
		info.Name = name2
		return nil
	}))
	var paths, names []string
	assert.NoError(t, ForEachPackageOfSite(site, func(path string, info *stpb.PackageInfo) error {
		paths = append(paths, path)
		names = append(names, info.Name)
		return nil
	}))
	assert.Equal(t, "paths", paths, []string{path1, path2})
	assert.Equal(t, "names", names, []string{name1, name2})
}
开发者ID:xavieryang007,项目名称:gcse,代码行数:28,代码来源:store_test.go


示例5: TestIndex_DescNotIndexedBug

func TestIndex_DescNotIndexedBug(t *testing.T) {
	const (
		description = "description"
		readme      = "readme"
	)
	hits := []HitInfo{{
		DocInfo: DocInfo{
			Package:     "github.com/daviddengcn/gcse",
			Name:        "gcse",
			Description: description,
			ReadmeData:  readme,
		},
	}}
	idxs := []int{0}
	fullHitSaved := 0
	ts := &index.TokenSetSearcher{}
	assert.NoError(t, indexAndSaveHits(ts, hits, idxs, func(hit *HitInfo) error {
		fullHitSaved++
		assert.Equal(t, "Description", hit.Description, description)
		assert.Equal(t, "Readme", hit.ReadmeData, readme)
		return nil
	}))
	assert.Equal(t, "fullHitSaved", fullHitSaved, 1)
	results, err := search(ts, IndexTextField, description)
	assert.NoError(t, err)
	assert.Equal(t, "results", results, hits)

	results, err = search(ts, IndexTextField, readme)
	assert.NoError(t, err)
	assert.Equal(t, "results", results, hits)
}
开发者ID:xavieryang007,项目名称:gcse,代码行数:31,代码来源:index_test.go


示例6: TestMarshalToFile

func TestMarshalToFile(t *testing.T) {
	fn := path.Join(os.TempDir(), "TestMarshalToFile.json")
	s := T{
		S: "abc",
	}
	assert.NoError(t, MarshalToFile(s, fn))
	bs, err := ioutil.ReadFile(fn)
	assert.NoError(t, err)
	assert.Equal(t, "bs", strings.TrimSpace(string(bs)), `{"S":"abc"}`)
}
开发者ID:golangplus,项目名称:encoding,代码行数:10,代码来源:json_test.go


示例7: TestMoveData

func TestMoveData(t *testing.T) {
	DataPath = "./tmp.bolt"
	FlushPeriod = time.Second
	err := os.RemoveAll(DataPath)
	if err != nil && err != os.ErrNotExist {
		assert.NoError(t, err)
		return
	}

	now := time.Now()
	checkValue := func(tp, name string, sum, div int) {
		data, err := ReadDataOfName(tp, name)
		assert.NoError(t, err)
		if sum == 0 && div == 0 {
			assert.Equal(t, fmt.Sprintf("%v:%v", name, tp), len(data), 0)
			return
		}
		assert.Equal(t, fmt.Sprintf("%v:%v", name, tp), data, []LabeledCounter{{
			Counter{Sum: sum, Div: div},
			now.Format("2006-01-02"),
		}})
	}
	checkNames := func(exp []string) {
		names, err := ReadNames()
		assert.NoError(t, err)
		assert.Equal(t, "names", names, exp)
	}

	AddValue(Average, "TestMoveData-abc", 123)
	AddValue(Average, "TestMoveData-def", 456)
	Flush()
	Process()

	t.Log("before move")
	checkNames([]string{"TestMoveData-abc", "TestMoveData-def"})
	checkValue(Daily, "TestMoveData-abc", 123, 1)
	checkValue(Daily, "TestMoveData-def", 456, 1)

	assert.NoError(t, MoveData("TestMoveData-abc", "TestMoveData-def", Average))
	t.Log("after move from abc to def")
	checkNames([]string{"TestMoveData-def"})
	checkValue(Daily, "TestMoveData-abc", 0, 0)
	checkValue(Daily, "TestMoveData-def", 579, 2)

	assert.NoError(t, MoveData("TestMoveData-def", "TestMoveData-none", Average))
	t.Log("after move from def to none")
	checkNames([]string{"TestMoveData-none"})
	checkValue(Daily, "TestMoveData-abc", 0, 0)
	checkValue(Daily, "TestMoveData-def", 0, 0)
	checkValue(Daily, "TestMoveData-none", 579, 2)
}
开发者ID:daviddengcn,项目名称:go-easybi,代码行数:51,代码来源:bi_test.go


示例8: TestCrawlingEntry

func TestCrawlingEntry(t *testing.T) {
	src := CrawlingEntry{
		ScheduleTime: time.Now(),
		Version:      19,
		Etag:         "Hello",
	}

	var buf bytesp.Slice
	assert.NoError(t, src.WriteTo(&buf))

	var dst CrawlingEntry
	assert.NoError(t, dst.ReadFrom(&buf, -1))

	assert.StringEqual(t, "dst", dst, src)
}
开发者ID:digideskio,项目名称:gcse,代码行数:15,代码来源:crawler_test.go


示例9: TestSlice_ReadFromEOF

func TestSlice_ReadFromEOF(t *testing.T) {
	r1 := readerReturningEOFLastRead(1)
	var s Slice
	n, err := s.ReadFrom(&r1)
	assert.Equal(t, "n", n, int64(1))
	assert.NoError(t, err)
	assert.Equal(t, "s", s, Slice([]byte{1}))

	r2 := readerReturningEOFAfterLastRead(1)
	s = nil
	n, err = s.ReadFrom(&r2)
	assert.Equal(t, "n", n, int64(1))
	assert.NoError(t, err)
	assert.Equal(t, "s", s, Slice([]byte{2}))
}
开发者ID:thomasf,项目名称:alkasir,代码行数:15,代码来源:slice_test.go


示例10: TestNodeToLines_Literal

func TestNodeToLines_Literal(t *testing.T) {
	info, err := parse("", `
package main

func main() {
	a := Da {
		A: 10,
		B: 20,
	}
}

	`)
	if !assert.NoError(t, err) {
		return
	}

	lines := info.funcs.sourceLines("")
	assert.StringEqual(t, "lines", lines, strings.Split(
		`func main() {
    a := Da{
        A: 10,
        B: 20,
    }
}`, "\n"))
}
开发者ID:daviddengcn,项目名称:go-diff,代码行数:25,代码来源:godiff_test.go


示例11: TestRefCountBox_UpdateView

func TestRefCountBox_UpdateView(t *testing.T) {
	fn := path.Join(os.TempDir(), "TestRefCountBox_UpdateView.bolt")
	assert.NoError(t, os.RemoveAll(fn))

	b := RefCountBox{
		DataPath: func() string { return fn },
	}
	k := bytes.Split([]byte("a.b"), []byte("."))
	v := "hello"
	assert.NoErrorOrDie(t, b.Update(func(tx Tx) error {
		return tx.Put(k, []byte(v))
	}))
	assert.Equal(t, "b.count", b.count, 0)
	assert.ValueShould(t, "b.db.DB", b.db.DB, b.db.DB == nil, "is not nil")

	found := false
	assert.NoErrorOrDie(t, b.View(func(tx Tx) error {
		return tx.Value(k, func(bs bytesp.Slice) error {
			found = true
			assert.Equal(t, "bs", string(v), string(bs))
			return nil
		})
	}))
	assert.Equal(t, "b.count", b.count, 0)
	assert.ValueShould(t, "b.db.DB", b.db.DB, b.db.DB == nil, "is not nil")
}
开发者ID:daviddengcn,项目名称:bolthelper,代码行数:26,代码来源:box_test.go


示例12: TestRefCountBox_Basic

func TestRefCountBox_Basic(t *testing.T) {
	fn := path.Join(os.TempDir(), "TestRefCountBox.bolt")
	assert.NoError(t, os.RemoveAll(fn))

	b := RefCountBox{
		DataPath: func() string { return fn },
	}
	db, err := b.Alloc()
	assert.NoError(t, err)
	assert.ValueShould(t, "db.DB", db.DB, db.DB != nil, "is nil")
	assert.Equal(t, "b.count", b.count, 1)
	assert.ValueShould(t, "b.db.DB", b.db.DB, b.db.DB != nil, "is nil")

	b.Free()
	assert.Equal(t, "b.count", b.count, 0)
	assert.ValueShould(t, "b.db.DB", b.db.DB, b.db.DB == nil, "is not nil")
}
开发者ID:daviddengcn,项目名称:bolthelper,代码行数:17,代码来源:box_test.go


示例13: TestDocInfo

func TestDocInfo(t *testing.T) {
	src := DocInfo{
		Name:        "gcse",
		Package:     "github.com/daviddengcn/gcse",
		Author:      "github.com/daviddengcn",
		LastUpdated: time.Now(),
		StarCount:   10,
		Synopsis:    "Go Package Search Engine",
		Description: "More details about GCSE",
		ProjectURL:  "http://github.com/daviddengcn/gcse",
		ReadmeFn:    "readme.txt",
		ReadmeData:  "Just read me",
		Imports: []string{
			"github.com/daviddengcn/go-villa",
			"github.com/daviddengcn/sophie",
		},
		TestImports: []string{
			"github.com/daviddengcn/go-check",
		},
		Exported: []string{
			"DocInfo", "CheckRuneType",
		},
	}
	var buf bytesp.Slice
	assert.NoError(t, src.WriteTo(&buf))

	var dst DocInfo
	assert.NoError(t, dst.ReadFrom(&buf, -1))

	assert.StringEqual(t, "dst", dst, src)

	// checking the bug introduced by reusing slice
	dst2 := dst
	assert.StringEqual(t, "dst2.Imports[0]", dst2.Imports[0],
		"github.com/daviddengcn/go-villa")

	src.Imports[0] = "github.com/daviddengcn/go-assert"
	buf = nil
	assert.NoError(t, src.WriteTo(&buf))
	assert.NoError(t, dst.ReadFrom(&buf, -1))
	assert.StringEqual(t, "dst", dst, src)

	assert.StringEqual(t, "dst2.Imports[0]", dst2.Imports[0],
		"github.com/daviddengcn/go-villa")
}
开发者ID:digideskio,项目名称:gcse,代码行数:45,代码来源:data_test.go


示例14: TestPlusone

func TestPlusone(t *testing.T) {
	url := "http://www.google.com/"
	cnt, err := Plusone(http.DefaultClient, url)
	assert.NoError(t, err)
	t.Logf("Plusone of %s: %d", url, cnt)
	if cnt <= 0 {
		t.Errorf("Zero Plusone count for %s", url)
	}
}
开发者ID:xavieryang007,项目名称:gcse,代码行数:9,代码来源:crawler_test.go


示例15: TestRefCountBox_UnsetDataPath

func TestRefCountBox_UnsetDataPath(t *testing.T) {
	fn := path.Join(os.TempDir(), "TestRefCountBox.bolt")
	assert.NoError(t, os.RemoveAll(fn))

	b := RefCountBox{}
	db, err := b.Alloc()
	assert.Equal(t, "err", errorsp.Cause(err), ErrBoxDataPathNotSpecified)
	assert.ValueShould(t, "db.DB", db.DB, db.DB == nil, "is not nil")
	assert.ValueShould(t, "b.db.DB", b.db.DB, b.db.DB == nil, "is not nil")
	assert.Equal(t, "b.count", b.count, 0)
}
开发者ID:daviddengcn,项目名称:bolthelper,代码行数:11,代码来源:box_test.go


示例16: TestUpdateReadDeletePackage

func TestUpdateReadDeletePackage(t *testing.T) {
	const (
		site = "TestUpdateReadPackage.com"
		path = "gcse"
		name = "pkgname"
	)
	assert.NoError(t, UpdatePackage(site, path, func(info *stpb.PackageInfo) error {
		assert.Equal(t, "info", info, &stpb.PackageInfo{})
		info.Name = name
		return nil
	}))
	pkg, err := ReadPackage(site, path)
	assert.NoError(t, err)
	assert.Equal(t, "pkg", pkg, &stpb.PackageInfo{Name: name})

	assert.NoError(t, DeletePackage(site, path))

	pkg, err = ReadPackage(site, path)
	assert.NoError(t, err)
	assert.Equal(t, "pkg", pkg, &stpb.PackageInfo{})
}
开发者ID:xavieryang007,项目名称:gcse,代码行数:21,代码来源:store_test.go


示例17: TestSlice_ReadFrom

func TestSlice_ReadFrom(t *testing.T) {
	src := make([]byte, 63*1024)
	for i := range src {
		src[i] = byte(i)
	}
	b := bytes.NewBuffer(src)
	var s Slice
	n, err := s.ReadFrom(b)
	assert.Equal(t, "n", n, int64(len(src)))
	assert.NoError(t, err)
	assert.Equal(t, "s", s, Slice(src))
}
开发者ID:thomasf,项目名称:alkasir,代码行数:12,代码来源:slice_test.go


示例18: TestUpdateReadDeletePackageHistory

func TestUpdateReadDeletePackageHistory(t *testing.T) {
	const (
		site     = "TestUpdateReadDeletePackageHistory.com"
		path     = "gcse"
		foundWay = "testing"
	)
	assert.NoError(t, UpdatePackageHistory(site, path, func(info *sppb.HistoryInfo) error {
		assert.Equal(t, "info", info, &sppb.HistoryInfo{})
		info.FoundWay = foundWay
		return nil
	}))
	h, err := ReadPackageHistory(site, path)
	assert.NoError(t, err)
	assert.Equal(t, "h", h, &sppb.HistoryInfo{FoundWay: foundWay})

	assert.NoError(t, DeletePackageHistory(site, path))

	h, err = ReadPackageHistory(site, path)
	assert.NoError(t, err)
	assert.Equal(t, "h", h, &sppb.HistoryInfo{})
}
开发者ID:xavieryang007,项目名称:gcse,代码行数:21,代码来源:history_test.go


示例19: TestUpdateReadDeletePersonHistory

func TestUpdateReadDeletePersonHistory(t *testing.T) {
	const (
		site     = "TestUpdateReadDeletePersonHistory.com"
		id       = "daviddengcn"
		foundWay = "testing"
	)
	assert.NoError(t, UpdatePersonHistory(site, id, func(info *sppb.HistoryInfo) error {
		assert.Equal(t, "info", info, &sppb.HistoryInfo{})
		info.FoundWay = foundWay
		return nil
	}))
	h, err := ReadPersonHistory(site, id)
	assert.NoError(t, err)
	assert.Equal(t, "h", h, &sppb.HistoryInfo{FoundWay: foundWay})

	assert.NoError(t, DeletePersonHistory(site, id))

	h, err = ReadPersonHistory(site, id)
	assert.NoError(t, err)
	assert.Equal(t, "h", h, &sppb.HistoryInfo{})
}
开发者ID:xavieryang007,项目名称:gcse,代码行数:21,代码来源:history_test.go


示例20: TestDoFill

func TestDoFill(t *testing.T) {
	const (
		site = "github.com"
		path = "daviddengcn/gcse"
	)
	tm := time.Now().Add(-20 * timep.Day)
	cDB := gcse.LoadCrawlerDB()
	cDB.PackageDB.Put(site+"/"+path, gcse.CrawlingEntry{
		ScheduleTime: tm.Add(10 * timep.Day),
	})
	assert.NoError(t, cDB.Sync())

	assert.NoError(t, doFill())

	h, err := store.ReadPackageHistory(site, path)
	assert.NoError(t, err)
	ts, _ := ptypes.TimestampProto(tm)
	assert.Equal(t, "h", h, &sppb.HistoryInfo{
		FoundTime: ts,
		FoundWay:  "unknown",
	})
}
开发者ID:xavieryang007,项目名称:gcse,代码行数:22,代码来源:fillfound_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang assert.StringEqual函数代码示例发布时间:2022-05-23
下一篇:
Golang assert.Equal函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap