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

Golang ut.AssertEqual函数代码示例

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

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



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

示例1: check

func check(t *testing.T, b *bytes.Buffer, expected []event) {
	actual := &traceFile{}
	ut.AssertEqual(t, nil, json.Unmarshal(b.Bytes(), actual))
	// Zap out .Timestamp since it is not deterministic. Convert Duration to
	// binary value, either 0 or 1 since it's value is either set or not set.
	for i := range actual.Events {
		ut.AssertEqual(t, true, actual.Events[i].Timestamp >= 0)
		actual.Events[i].Timestamp = 0
		if actual.Events[i].Duration != 0 {
			actual.Events[i].Duration = 1
		}
	}
	for i := range expected {
		if expected[i].Pid == 0 {
			expected[i].Pid = 1
		}
		if expected[i].Tid == 0 {
			expected[i].Tid = 1
		}
	}
	wd, _ := os.Getwd()
	e := &traceFile{traceContext{os.Args, wd}, expected}
	ut.AssertEqual(t, e.Context, actual.Context)
	ut.AssertEqual(t, e.Events, actual.Events)
	ut.AssertEqual(t, e, actual)
}
开发者ID:shishkander,项目名称:luci-go,代码行数:26,代码来源:tracer_test.go


示例2: TestParseDumpAsm

func TestParseDumpAsm(t *testing.T) {
	data := []string{
		"panic: reflect.Set: value of type",
		"",
		"goroutine 16 [garbage collection]:",
		"runtime.switchtoM()",
		"\t" + goroot + "/src/runtime/asm_amd64.s:198 fp=0xc20cfb80d8 sp=0xc20cfb80d0",
		"",
	}
	extra := &bytes.Buffer{}
	goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), extra)
	ut.AssertEqual(t, nil, err)
	expected := []Goroutine{
		{
			Signature: Signature{
				State: "garbage collection",
				Stack: []Call{
					{
						SourcePath: goroot + "/src/runtime/asm_amd64.s",
						Line:       198,
						Func:       Function{Raw: "runtime.switchtoM"},
					},
				},
			},
			ID:    16,
			First: true,
		},
	}
	ut.AssertEqual(t, expected, goroutines)
	ut.AssertEqual(t, "panic: reflect.Set: value of type\n\n", extra.String())
}
开发者ID:johnkewforks,项目名称:panicparse,代码行数:31,代码来源:stack_test.go


示例3: testNodesTableImpl

func testNodesTableImpl(t testing.TB, cas CasTable, nodes NodesTable) {
	items, err := EnumerateNodesAsList(nodes)
	ut.AssertEqual(t, nil, err)
	ut.AssertEqual(t, []string{}, items)

	tree1 := map[string]string{
		"file1":           "content1",
		"dir1/dir2/file2": "content2",
	}
	archiveData(t, cas, nodes, tree1)
	items, err = EnumerateNodesAsList(nodes)
	ut.AssertEqual(t, nil, err)
	ut.AssertEqual(t, 2, len(items))
	name := strings.Replace(items[0], string(filepath.Separator), "/", -1)

	body := request(t, nodes, "/", 200, "")
	ut.AssertEqual(t, 2, strings.Count(body, "<a "))
	request(t, nodes, "/foo", 404, "")
	request(t, nodes, "/foo/", 404, "")
	request(t, nodes, "/"+name, 301, "")
	request(t, nodes, "/"+name+"/", 200, "")
	request(t, nodes, "/"+name+"/file1", 200, "content1")
	request(t, nodes, "/"+name+"/dir1/dir2/file2", 200, "content2")
	request(t, nodes, "/"+name+"/dir1/dir2/file3", 404, "")
	request(t, nodes, "/"+name+"/dir1/dir2", 301, "")
}
开发者ID:maruel,项目名称:dumbcas,代码行数:26,代码来源:nodes_test.go


示例4: TestDoRetryExceeded

func TestDoRetryExceeded(t *testing.T) {
	c := &Config{1, 0, 0, 0}
	r := &retriable{errs: []error{errRetry}}
	ut.AssertEqual(t, errRetry, c.Do(r))
	ut.AssertEqual(t, 1, r.closed)
	ut.AssertEqual(t, 1, r.tries)
}
开发者ID:shishkander,项目名称:luci-go,代码行数:7,代码来源:retry_test.go


示例5: TestDoRetry

func TestDoRetry(t *testing.T) {
	c := &Config{2, 0, time.Millisecond, 0}
	r := &retriable{errs: []error{errRetry}}
	ut.AssertEqual(t, nil, c.Do(r))
	ut.AssertEqual(t, 1, r.closed)
	ut.AssertEqual(t, 2, r.tries)
}
开发者ID:shishkander,项目名称:luci-go,代码行数:7,代码来源:retry_test.go


示例6: TestDoOnce

func TestDoOnce(t *testing.T) {
	c := &Config{1, 0, 0, 0}
	r := &retriable{}
	ut.AssertEqual(t, nil, c.Do(r))
	ut.AssertEqual(t, 1, r.closed)
	ut.AssertEqual(t, 1, r.tries)
}
开发者ID:shishkander,项目名称:luci-go,代码行数:7,代码来源:retry_test.go


示例7: TestParseDumpUnavail

func TestParseDumpUnavail(t *testing.T) {
	data := []string{
		"panic: reflect.Set: value of type",
		"",
		"goroutine 24 [running]:",
		"\tgoroutine running on other thread; stack unavailable",
		"created by github.com/foo.New",
		"\t/gopath/src/github.com/foo/bar.go:131 +0x381",
		"",
	}
	extra := &bytes.Buffer{}
	goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), extra)
	ut.AssertEqual(t, nil, err)
	expected := []Goroutine{
		{
			Signature: Signature{
				State: "running",
				Stack: []Call{
					{
						SourcePath: "<unavailable>",
					},
				},
				CreatedBy: Call{
					SourcePath: "/gopath/src/github.com/foo/bar.go",
					Line:       131,
					Func:       Function{Raw: "github.com/foo.New"},
				},
			},
			ID:    24,
			First: true,
		},
	}
	ut.AssertEqual(t, expected, goroutines)
	ut.AssertEqual(t, "panic: reflect.Set: value of type\n\n", extra.String())
}
开发者ID:johnkewforks,项目名称:panicparse,代码行数:35,代码来源:stack_test.go


示例8: TestChangIgnore

func TestChangIgnore(t *testing.T) {
	t.Parallel()
	c := newChange(&dummyRepo{t, "<root>"}, nil, nil, IgnorePatterns{"*.pb.go"})
	ut.AssertEqual(t, false, c.IsIgnored("foo.go"))
	ut.AssertEqual(t, true, c.IsIgnored("foo.pb.go"))
	ut.AssertEqual(t, true, c.IsIgnored("bar/foo.pb.go"))
}
开发者ID:jjpeters67,项目名称:pre-commit-go,代码行数:7,代码来源:change_test.go


示例9: testCacheImpl

func testCacheImpl(t testing.TB, load func() (Cache, error)) {
	now := time.Now().UTC().Unix()
	{
		c, err := load()
		ut.AssertEqual(t, nil, err)
		if c.Root().CountMembers() != 1 {
			c.Root().Print(os.Stderr, "")
			t.Fatalf("Oops: %d", c.Root().CountMembers())
		}
		if c.Root().Files != nil {
			c.Root().Print(os.Stderr, "")
			t.Fatalf("Oops: %d", c.Root().CountMembers())
		}
		i := FindInCache(c, filepath.Join("foo", "bar"))
		i.Sha1 = "x"
		i.Size = 1
		i.Timestamp = 2
		i.LastTested = now
		c.Close()
	}
	{
		c, err := load()
		ut.AssertEqual(t, nil, err)
		b := &bytes.Buffer{}
		c.Root().Print(b, "")
		ut.AssertEqual(t, "- 'foo'\n  - 'bar'\n    Sha1: x\n    Size: 1\n", b.String())
		foo := c.Root().Files["foo"]
		bar := foo.Files["bar"]
		if bar.Sha1 != "x" || bar.Size != 1 || bar.Timestamp != 2 || bar.LastTested != now {
			t.Fatalf("Oops: %d", c.Root().CountMembers())
		}
		c.Close()
	}
}
开发者ID:maruel,项目名称:dumbcas,代码行数:34,代码来源:cache_test.go


示例10: TestParseDumpNoOffset

func TestParseDumpNoOffset(t *testing.T) {
	data := []string{
		"panic: runtime error: index out of range",
		"",
		"goroutine 37 [runnable]:",
		"github.com/foo.func·002()",
		"	/gopath/src/github.com/foo/bar.go:110",
		"created by github.com/foo.New",
		"	/gopath/src/github.com/foo/bar.go:113 +0x43b",
	}
	goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), &bytes.Buffer{})
	ut.AssertEqual(t, nil, err)
	expectedGR := []Goroutine{
		{
			Signature: Signature{
				State: "runnable",
				Stack: []Call{
					{
						SourcePath: "/gopath/src/github.com/foo/bar.go",
						Line:       110,
						Func:       Function{"github.com/foo.func·002"},
					},
				},
				CreatedBy: Call{
					SourcePath: "/gopath/src/github.com/foo/bar.go",
					Line:       113,
					Func:       Function{"github.com/foo.New"},
				},
			},
			ID:    37,
			First: true,
		},
	}
	ut.AssertEqual(t, expectedGR, goroutines)
}
开发者ID:johnkewforks,项目名称:panicparse,代码行数:35,代码来源:stack_test.go


示例11: TestInstalledApp

func TestInstalledApp(t *testing.T) {
	i := &InstalledApp{
		ClientID:         "C",
		ClientSecret:     "S",
		AuthURL:          "http://localhost/auth",
		TokenURL:         "http://localhost/token",
		ScopedTokenCache: make(map[string]*TokenCache),
	}
	tokReply := `{"access_token":"a", "refresh_token": "r", "id_token": "i"}`
	resp := []*http.Response{
		{StatusCode: 200, Body: asReader(tokReply)},
	}
	r := &roundTripperStub{[]*http.Request{}, resp}
	prompt := func(string) string {
		return "auth"
	}
	_, err := i.GetClientPrompt("scope", r, prompt)
	ut.AssertEqual(t, nil, err)
	ut.AssertEqual(t, 1, len(r.requests))
	i.Lock()
	defer i.Unlock()
	ut.AssertEqual(t, true, i.ShouldSave())
	i.ClearDirtyBit()
	ut.AssertEqual(t, false, i.ShouldSave())
}
开发者ID:maruel,项目名称:ofh,代码行数:25,代码来源:installedapp_test.go


示例12: TestRound

func TestRound(t *testing.T) {
	t.Parallel()
	ut.AssertEqual(t, 1500*time.Millisecond, round(1549*time.Millisecond, 100*time.Millisecond))
	ut.AssertEqual(t, 1600*time.Millisecond, round(1550*time.Millisecond, 100*time.Millisecond))
	ut.AssertEqual(t, -1500*time.Millisecond, round(-1549*time.Millisecond, 100*time.Millisecond))
	ut.AssertEqual(t, -1600*time.Millisecond, round(-1550*time.Millisecond, 100*time.Millisecond))
}
开发者ID:jjpeters67,项目名称:pre-commit-go,代码行数:7,代码来源:utils_test.go


示例13: TestCartesianProductOfValues

func TestCartesianProductOfValues(t *testing.T) {
	t.Parallel()
	set := func(vs ...string) map[variableValueKey]variableValue {
		out := map[variableValueKey]variableValue{}
		for _, v := range makeVVs(vs...) {
			out[v.key()] = v
		}
		return out
	}
	test := func(vvs variablesValuesSet, keys []string, expected ...[]variableValue) {
		res, err := vvs.cartesianProductOfValues(keys)
		ut.AssertEqual(t, nil, err)
		vvSort(expected)
		vvSort(res)
		ut.AssertEqual(t, vvToStr2D(expected), vvToStr2D(res))
	}
	keys := func(vs ...string) []string { return vs }

	vvs := variablesValuesSet{}
	test(vvs, keys())

	vvs["OS"] = set("win", "unbound")
	test(vvs, keys("OS"), makeVVs("win"), makeVVs("unbound"))

	vvs["bit"] = set("32")

	test(vvs, keys("OS"), makeVVs("win"), makeVVs("unbound")) // bit var name must be ignored.
	test(vvs, keys("bit", "OS"), makeVVs("32", "win"), makeVVs("32", "unbound"))
}
开发者ID:shishkander,项目名称:luci-go,代码行数:29,代码来源:format_test.go


示例14: TestRestore

func TestRestore(t *testing.T) {
	t.Parallel()
	f := makeDumbcasAppMock(t)
	// Force the creation of CAS and NodesTable so content can be archived in
	// memory before running the command.
	_, _ = f.MakeCasTable("")
	_, _ = f.LoadNodesTable("", f.cas)

	// Create an archive.
	tree := map[string]string{
		"dir1/bar":           "bar\n",
		"dir1/dir2/dir3/foo": "foo\n",
		"dir1/dir2/file2":    "content2",
		"file1":              "content1",
		"x":                  "x\n",
	}
	_, nodeName, _ := archiveData(f.TB, f.cas, f.nodes, tree)

	tempData := makeTempDir(t, "restore")
	defer removeDir(t, tempData)

	args := []string{"restore", "-root=\\test_archive", "-out=" + tempData, nodeName}
	f.Run(args, 0)
	f.CheckBuffer(true, false)

	actualTree, err := readTree(tempData)
	ut.AssertEqual(t, nil, err)
	ut.AssertEqual(t, tree, actualTree)
}
开发者ID:maruel,项目名称:dumbcas,代码行数:29,代码来源:restore_test.go


示例15: TestConfigYAMLBadMode

func TestConfigYAMLBadMode(t *testing.T) {
	data, err := yaml.Marshal("foo")
	ut.AssertEqual(t, nil, err)
	v := PreCommit
	ut.AssertEqual(t, errors.New("invalid mode \"foo\""), yaml.Unmarshal(data, &v))
	ut.AssertEqual(t, PreCommit, v)
}
开发者ID:jjpeters67,项目名称:pre-commit-go,代码行数:7,代码来源:config_test.go


示例16: TestCancelable

func TestCancelable(t *testing.T) {
	t.Parallel()
	c := newCanceler()
	ut.AssertEqual(t, nil, c.CancelationReason())
	select {
	case <-c.Channel():
		t.FailNow()
	default:
	}

	wg := sync.WaitGroup{}
	wg.Add(1)
	go func() {
		defer wg.Done()
		select {
		case err, isCanceled := <-c.Channel():
			ut.ExpectEqualf(t, true, isCanceled, "Closed, but shouldn't be.")
			ut.ExpectEqual(t, ErrCanceled, err)
		}
	}()
	c.Cancel(nil)
	ut.AssertEqual(t, ErrCanceled, c.CancelationReason())
	t.Log("waiting for goroutine above to end.")
	wg.Wait()
	ut.AssertEqual(t, nil, c.Close())
	assertClosed(t, c)
}
开发者ID:shishkander,项目名称:luci-go,代码行数:27,代码来源:concurrent_test.go


示例17: setup

func setup(t *testing.T, tmpDir string) {
	_, code, err := internal.Capture(tmpDir, nil, "git", "init")
	ut.AssertEqual(t, 0, code)
	ut.AssertEqual(t, nil, err)
	run(t, tmpDir, nil, "config", "user.email", "[email protected]")
	run(t, tmpDir, nil, "config", "user.name", "nobody")
}
开发者ID:jjpeters67,项目名称:pre-commit-go,代码行数:7,代码来源:repo_test.go


示例18: TestFunctionAnonymous

func TestFunctionAnonymous(t *testing.T) {
	f := Function{"main.func·001"}
	ut.AssertEqual(t, "main.func·001", f.String())
	ut.AssertEqual(t, "main.func·001", f.PkgDotName())
	ut.AssertEqual(t, "func·001", f.Name())
	ut.AssertEqual(t, "main", f.PkgName())
	ut.AssertEqual(t, false, f.IsExported())
}
开发者ID:johnkewforks,项目名称:panicparse,代码行数:8,代码来源:stack_test.go


示例19: TestCaptureOne

func TestCaptureOne(t *testing.T) {
	t.Parallel()
	wd, err := os.Getwd()
	ut.AssertEqual(t, nil, err)
	_, code, err := Capture(wd, nil, "go")
	ut.AssertEqual(t, 2, code)
	ut.AssertEqual(t, nil, err)
}
开发者ID:jjpeters67,项目名称:pre-commit-go,代码行数:8,代码来源:utils_test.go


示例20: TestFunctionGC

func TestFunctionGC(t *testing.T) {
	f := Function{"gc"}
	ut.AssertEqual(t, "gc", f.String())
	ut.AssertEqual(t, "gc", f.PkgDotName())
	ut.AssertEqual(t, "gc", f.Name())
	ut.AssertEqual(t, "", f.PkgName())
	ut.AssertEqual(t, false, f.IsExported())
}
开发者ID:johnkewforks,项目名称:panicparse,代码行数:8,代码来源:stack_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang flickr.FlickrClient类代码示例发布时间:2022-05-23
下一篇:
Golang subcommands.Application类代码示例发布时间: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