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

Golang ut.AssertEqual函数代码示例

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

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



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

示例1: 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:nodirt,项目名称:pre-commit-go,代码行数:7,代码来源:utils_test.go


示例2: 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:nodirt,项目名称:pre-commit-go,代码行数:7,代码来源:config_test.go


示例3: 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:nodirt,项目名称:pre-commit-go,代码行数:7,代码来源:change_test.go


示例4: 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:nodirt,项目名称:pre-commit-go,代码行数:7,代码来源:repo_test.go


示例5: TestConfigYAML

func TestConfigYAML(t *testing.T) {
	config := New("0.1")
	data, err := yaml.Marshal(config)
	ut.AssertEqual(t, nil, err)
	actual := &Config{}
	ut.AssertEqual(t, nil, yaml.Unmarshal(data, actual))
	ut.AssertEqual(t, config, actual)
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:8,代码来源:config_test.go


示例6: TestGetRepoNoRepo

func TestGetRepoNoRepo(t *testing.T) {
	t.Parallel()
	tmpDir, err := ioutil.TempDir("", "pre-commit-go")
	defer func() {
		if err := internal.RemoveAll(tmpDir); err != nil {
			t.Errorf("%s", err)
		}
	}()

	r, err := GetRepo(tmpDir, "")
	ut.AssertEqual(t, errors.New("failed to find git checkout root"), err)
	ut.AssertEqual(t, nil, r)
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:13,代码来源:repo_test.go


示例7: TestCoveragePrerequisites

func TestCoveragePrerequisites(t *testing.T) {
	// This test can't be parallel.
	if !IsContinuousIntegration() {
		old := os.Getenv("CI")
		defer func() {
			ut.ExpectEqual(t, nil, os.Setenv("CI", old))
		}()
		ut.AssertEqual(t, nil, os.Setenv("CI", "true"))
		ut.AssertEqual(t, true, IsContinuousIntegration())
	}
	c := Coverage{UseCoveralls: true}
	ut.AssertEqual(t, 1, len(c.GetPrerequisites()))
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:13,代码来源:coverage_test.go


示例8: run

func run(t *testing.T, tmpDir string, env []string, args ...string) string {
	internal := &git{root: tmpDir}
	out, code, err := internal.captureEnv(env, args...)
	ut.AssertEqualf(t, 0, code, "%s", out)
	ut.AssertEqual(t, nil, err)
	return out
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:7,代码来源:repo_test.go


示例9: assertHEAD

func assertHEAD(t *testing.T, r ReadOnlyRepo, expected Commit) Commit {
	if head := r.Eval(string(Head)); head != expected {
		t.Logf("%s", strings.Join(os.Environ(), "\n"))
		t.Logf("%s", run(t, r.Root(), nil, "log", "-p", "--format=fuller"))
		ut.AssertEqual(t, expected, head)
	}
	return expected
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:8,代码来源:repo_test.go


示例10: TestChecksDescriptions

func TestChecksDescriptions(t *testing.T) {
	t.Parallel()
	for _, name := range getKnownChecks() {
		c := KnownChecks[name]()
		ut.AssertEqual(t, true, c.GetDescription() != "")
		c.GetPrerequisites()
	}
}
开发者ID:Hanxueying,项目名称:pre-commit-go,代码行数:8,代码来源:checks_test.go


示例11: TestCustom

func TestCustom(t *testing.T) {
	t.Parallel()
	p := []CheckPrerequisite{
		{
			HelpCommand:      []string{"go", "version"},
			ExpectedExitCode: 0,
			URL:              "example.com.local",
		},
	}
	c := &Custom{
		Description:   "foo",
		Command:       []string{"go", "version"},
		Prerequisites: p,
	}
	ut.AssertEqual(t, "foo", c.GetDescription())
	ut.AssertEqual(t, p, c.GetPrerequisites())
}
开发者ID:Hanxueying,项目名称:pre-commit-go,代码行数:17,代码来源:checks_test.go


示例12: TestRemoveAllMissing

func TestRemoveAllMissing(t *testing.T) {
	td, err := ioutil.TempDir("", "pre-commit-go")
	ut.ExpectEqual(t, nil, err)

	foo := filepath.Join(td, "foo")
	err = ioutil.WriteFile(foo, []byte("yo"), 0600)
	ut.ExpectEqual(t, nil, err)
	ut.AssertEqual(t, nil, RemoveAll(td))
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:9,代码来源:path_test.go


示例13: TestRangeToString

func TestRangeToString(t *testing.T) {
	t.Parallel()
	ut.AssertEqual(t, "", rangeToString(nil))
	ut.AssertEqual(t, "1", rangeToString([]int{1}))
	ut.AssertEqual(t, "1-2", rangeToString([]int{1, 2}))
	ut.AssertEqual(t, "1-3", rangeToString([]int{1, 2, 3}))
	ut.AssertEqual(t, "1,3-4,6-8", rangeToString([]int{1, 3, 4, 6, 7, 8}))
	ut.AssertEqual(t, "1,3-4,6", rangeToString([]int{1, 3, 4, 6}))
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:9,代码来源:coverage_test.go


示例14: TestChecksSuccess

func TestChecksSuccess(t *testing.T) {
	// Runs all checks, they should all pass.
	t.Parallel()
	if testing.Short() {
		t.SkipNow()
	}
	td, err := ioutil.TempDir("", "pre-commit-go")
	ut.AssertEqual(t, nil, err)
	defer func() {
		if err := internal.RemoveAll(td); err != nil {
			t.Fail()
		}
	}()
	change := setup(t, td, goodFiles)
	for _, name := range getKnownChecks() {
		c := KnownChecks[name]()
		switch name {
		case "custom":
			c = &Custom{
				Description:   "foo",
				Command:       []string{"go", "version"},
				CheckExitCode: true,
				Prerequisites: []CheckPrerequisite{
					{
						HelpCommand:      []string{"go", "version"},
						ExpectedExitCode: 0,
						URL:              "example.com.local",
					},
				},
			}
		case "copyright":
			cop := c.(*Copyright)
			cop.Header = "// Foo"
		case "coverage":
			cov := c.(*Coverage)
			cov.Global.MinCoverage = 100
			cov.Global.MaxCoverage = 100
			cov.PerDirDefault.MinCoverage = 100
			cov.PerDirDefault.MaxCoverage = 100
		}
		if l, ok := c.(sync.Locker); ok {
			l.Lock()
			l.Unlock()
		}
		if err := c.Run(change, &Options{MaxDuration: 1}); err != nil {
			t.Errorf("%s failed: %s", c.GetName(), err)
		}
	}
}
开发者ID:Hanxueying,项目名称:pre-commit-go,代码行数:49,代码来源:checks_test.go


示例15: setup

func setup(t *testing.T, td string, files map[string]string) scm.Change {
	fooDir := filepath.Join(td, "src", "foo")
	ut.AssertEqual(t, nil, os.MkdirAll(fooDir, 0700))
	for f, c := range files {
		p := filepath.Join(fooDir, f)
		ut.AssertEqual(t, nil, os.MkdirAll(filepath.Dir(p), 0700))
		ut.AssertEqual(t, nil, ioutil.WriteFile(p, []byte(c), 0600))
	}
	_, code, err := internal.Capture(fooDir, nil, "git", "init")
	ut.AssertEqual(t, 0, code)
	ut.AssertEqual(t, nil, err)
	// It's important to add the files to the index, otherwise they will be
	// ignored.
	_, code, err = internal.Capture(fooDir, nil, "git", "add", ".")
	ut.AssertEqual(t, 0, code)
	ut.AssertEqual(t, nil, err)

	repo, err := scm.GetRepo(fooDir, td)
	ut.AssertEqual(t, nil, err)
	change, err := repo.Between(scm.Current, scm.GitInitialCommit, nil)
	ut.AssertEqual(t, nil, err)
	ut.AssertEqual(t, true, change != nil)
	return change
}
开发者ID:Hanxueying,项目名称:pre-commit-go,代码行数:24,代码来源:checks_test.go


示例16: TestConfigNew

func TestConfigNew(t *testing.T) {
	config := New("0.1")
	ut.AssertEqual(t, 3, len(config.Modes[PreCommit].Checks))
	ut.AssertEqual(t, 3, len(config.Modes[PrePush].Checks))
	ut.AssertEqual(t, 5, len(config.Modes[ContinuousIntegration].Checks))
	ut.AssertEqual(t, 3, len(config.Modes[Lint].Checks))
	checks, options := config.EnabledChecks([]Mode{PreCommit, PrePush, ContinuousIntegration, Lint})
	ut.AssertEqual(t, Options{MaxDuration: 120}, *options)
	ut.AssertEqual(t, 2+4+5+3, len(checks))
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:10,代码来源:config_test.go


示例17: makeTree

// makeTree creates a temporary directory and creates the files in it.
//
// Returns the root directly, all files created and the cleanup function.
func makeTree(t *testing.T, files map[string]string) (string, []string, func()) {
	td, err := ioutil.TempDir("", "pre-commit-go")
	ut.AssertEqual(t, nil, err)
	cleanup := func() {
		if err := internal.RemoveAll(td); err != nil {
			t.Fail()
		}
	}
	allFiles := make([]string, 0, len(files))
	for f, c := range files {
		allFiles = append(allFiles, f)
		p := filepath.Join(td, f)
		if err := os.MkdirAll(filepath.Dir(p), 0700); err != nil {
			cleanup()
			t.Fatal(err)
		}
		if err := ioutil.WriteFile(p, []byte(c), 0600); err != nil {
			cleanup()
			t.Fatal(err)
		}
	}
	sort.Strings(allFiles)
	return td, allFiles, cleanup
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:27,代码来源:change_test.go


示例18: TestCoverageGlobal

func TestCoverageGlobal(t *testing.T) {
	t.Parallel()
	if testing.Short() {
		t.SkipNow()
	}
	td, err := ioutil.TempDir("", "pre-commit-go")
	ut.AssertEqual(t, nil, err)
	defer func() {
		if err := internal.RemoveAll(td); err != nil {
			t.Fail()
		}
	}()
	change := setup(t, td, coverageFiles)

	c := &Coverage{
		UseGlobalInference: true,
		UseCoveralls:       false,
		Global: CoverageSettings{
			MinCoverage: 50,
			MaxCoverage: 100,
		},
		PerDirDefault: CoverageSettings{
			MinCoverage: 50,
			MaxCoverage: 100,
		},
		PerDir: map[string]*CoverageSettings{},
	}
	profile, err := c.RunProfile(change, &Options{MaxDuration: 1})
	ut.AssertEqual(t, nil, err)
	expected := CoverageProfile{
		{
			Source:    "foo.go",
			Line:      3,
			SourceRef: "foo.go:3",
			Name:      "Type.Foo",
			Covered:   2,
			Missing:   []int{},
			Total:     2,
			Percent:   100,
		},
		{
			Source:    "bar/bar.go",
			Line:      2,
			SourceRef: "bar/bar.go:2",
			Name:      "Bar",
			Covered:   2,
			Missing:   []int{7, 8},
			Total:     4,
			Percent:   50,
		},
		{
			Source:    "bar/bar.go",
			Line:      11,
			SourceRef: "bar/bar.go:11",
			Name:      "Baz",
			Covered:   2,
			Missing:   []int{16, 17},
			Total:     4,
			Percent:   50,
		},
	}
	ut.AssertEqual(t, expected, profile)
	ut.AssertEqual(t, 60., profile.CoveragePercent())
	ut.AssertEqual(t, 2, profile.PartiallyCoveredFuncs())

	expected = CoverageProfile{
		{
			Source:    "bar.go",
			Line:      2,
			SourceRef: "bar/bar.go:2",
			Name:      "Bar",
			Covered:   2,
			Missing:   []int{7, 8},
			Total:     4,
			Percent:   50,
		},
		{
			Source:    "bar.go",
			Line:      11,
			SourceRef: "bar/bar.go:11",
			Name:      "Baz",
			Covered:   2,
			Missing:   []int{16, 17},
			Total:     4,
			Percent:   50,
		},
	}
	ut.AssertEqual(t, expected, profile.Subset("bar"))

	expected = CoverageProfile{
		{
			Source:    "foo.go",
			Line:      3,
			SourceRef: "foo.go:3",
			Name:      "Type.Foo",
			Covered:   2,
			Missing:   []int{},
			Total:     2,
			Percent:   100,
		},
//.........这里部分代码省略.........
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:101,代码来源:coverage_test.go


示例19: TestGetRepoGitSlowFailures

func TestGetRepoGitSlowFailures(t *testing.T) {
	t.Parallel()
	tmpDir, err := ioutil.TempDir("", "pre-commit-go")
	defer func() {
		if err := internal.RemoveAll(tmpDir); err != nil {
			t.Errorf("%s", err)
		}
	}()

	setup(t, tmpDir)
	r, err := getRepo(tmpDir, tmpDir)
	ut.AssertEqual(t, nil, err)
	ut.AssertEqual(t, tmpDir, r.Root())
	// Remove the .git directory after calling GetRepo().
	ut.AssertEqual(t, nil, internal.RemoveAll(filepath.Join(tmpDir, ".git")))

	p, err := r.HookPath()
	ut.AssertEqual(t, errors.New("failed to find .git dir: failed to find .git dir: failed to run \"git rev-parse --git-dir\""), err)
	ut.AssertEqual(t, "", p)

	ut.AssertEqual(t, []string(nil), r.untracked())
	ut.AssertEqual(t, []string(nil), r.unstaged())

	ut.AssertEqual(t, Commit(gitInitial), r.Eval(string(Head)))
	ut.AssertEqual(t, "", r.Ref(Head))

	done, err := r.Stash()
	ut.AssertEqual(t, errors.New("failed to get list of untracked files"), err)
	ut.AssertEqual(t, false, done)
	errStr := r.Restore().Error()
	if errStr != "git reset failed:\nfatal: Not a git repository: '.git'" && errStr != "git reset failed:\nfatal: Not a git repository (or any of the parent directories): .git" {
		t.Fatalf("Unexpected error: %s", errStr)
	}

	errStr = r.Checkout(string(Initial)).Error()
	if errStr != "checkout failed:\nfatal: Not a git repository: '.git'" && errStr != "checkout failed:\nfatal: Not a git repository (or any of the parent directories): .git" {
		t.Fatalf("Unexpected error: %s", errStr)
	}
}
开发者ID:nodirt,项目名称:pre-commit-go,代码行数:39,代码来源:repo_test.go


示例20: TestCheckPrerequisite

func TestCheckPrerequisite(t *testing.T) {
	// Runs all checks, they should all pass.
	t.Parallel()
	ut.AssertEqual(t, true, (&CheckPrerequisite{HelpCommand: []string{"go", "version"}, ExpectedExitCode: 0}).IsPresent())
	ut.AssertEqual(t, false, (&CheckPrerequisite{HelpCommand: []string{"go", "version"}, ExpectedExitCode: 1}).IsPresent())
}
开发者ID:Hanxueying,项目名称:pre-commit-go,代码行数:6,代码来源:checks_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang scm.Change类代码示例发布时间:2022-05-23
下一篇:
Golang sessions.Session类代码示例发布时间: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