当前位置: 首页>>代码示例>>Golang>>正文


Golang C.Assert方法代码示例

本文整理汇总了Golang中pkg/re/check/v1.C.Assert方法的典型用法代码示例。如果您正苦于以下问题:Golang C.Assert方法的具体用法?Golang C.Assert怎么用?Golang C.Assert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pkg/re/check/v1.C的用法示例。


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

示例1: TestParsing

func (s *KNFSuite) TestParsing(c *check.C) {
	err := Global(s.ConfigPath)

	c.Assert(err, check.IsNil)

	_, err = Reload()

	c.Assert(err, check.IsNil)
}
开发者ID:essentialkaos,项目名称:ek,代码行数:9,代码来源:knf_test.go

示例2: TestComments

func (s *KNFSuite) TestComments(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetI("comment:test1"), check.Equals, 100)
	c.Assert(GetI("comment:test2"), check.Not(check.Equals), 100)
	c.Assert(HasProp("comment:test2"), check.Equals, false)
}
开发者ID:essentialkaos,项目名称:ek,代码行数:12,代码来源:knf_test.go

示例3: TestFileMode

func (s *KNFSuite) TestFileMode(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetM("file-mode:test1"), check.Equals, os.FileMode(0644))
	c.Assert(GetM("file-mode:test2"), check.Equals, os.FileMode(0644))
	c.Assert(GetM("file-mode:test3"), check.Equals, os.FileMode(0))
	c.Assert(GetM("file-mode:test4"), check.Equals, os.FileMode(0))
	c.Assert(GetM("file-mode:test5"), check.Equals, os.FileMode(0))
}
开发者ID:essentialkaos,项目名称:ek,代码行数:14,代码来源:knf_test.go

示例4: TestProperPath

func (s *FSSuite) TestProperPath(c *check.C) {
	tmpFile := c.MkDir() + "/test.txt"

	os.OpenFile(tmpFile, os.O_CREATE, 0644)

	paths := []string{"/etc/sudoers", "/etc/passwd", tmpFile}

	c.Assert(ProperPath("DR", paths), check.Equals, "")
	c.Assert(ProperPath("FR", paths), check.Equals, "/etc/passwd")
	c.Assert(ProperPath("FRW", paths), check.Equals, tmpFile)
	c.Assert(ProperPath("FRWS", paths), check.Equals, "")
	c.Assert(ProperPath("F", paths), check.Equals, "/etc/sudoers")

	os.Remove(tmpFile)
}
开发者ID:essentialkaos,项目名称:ek,代码行数:15,代码来源:fs_test.go

示例5: TestInfo

func (s *SSLLabsSuite) TestInfo(c *check.C) {
	api, err := NewAPI("SSLScanTester", "4.0.0")

	c.Assert(api, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(api.Info.EngineVersion, check.Equals, "1.24.4")
	c.Assert(api.Info.CriteriaVersion, check.Equals, "2009l")
}
开发者ID:essentialkaos,项目名称:sslscan,代码行数:9,代码来源:sslscan_test.go

示例6: TestFormating

func (s *KNFSuite) TestFormating(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetI("formating:test1"), check.Equals, 1)
	c.Assert(GetI("formating:test2"), check.Equals, 2)
	c.Assert(GetI("formating:test3"), check.Equals, 3)
}
开发者ID:essentialkaos,项目名称:ek,代码行数:12,代码来源:knf_test.go

示例7: TestProps

func (s *KNFSuite) TestProps(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	props := Props("file-mode")

	c.Assert(props, check.HasLen, 5)
	c.Assert(
		props,
		check.DeepEquals,
		[]string{"test1", "test2", "test3", "test4", "test5"},
	)
}
开发者ID:essentialkaos,项目名称:ek,代码行数:17,代码来源:knf_test.go

示例8: TestSections

func (s *KNFSuite) TestSections(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	sections := Sections()

	c.Assert(sections, check.HasLen, 8)
	c.Assert(
		sections,
		check.DeepEquals,
		[]string{"formating", "string", "boolean", "integer", "file-mode", "comment", "macro", "k"},
	)
}
开发者ID:essentialkaos,项目名称:ek,代码行数:17,代码来源:knf_test.go

示例9: TestValidation

func (s *KNFSuite) TestValidation(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	var errs []error

	errs = Validate([]*Validator{
		{"integer:test1", Empty, nil},
		{"integer:test1", Less, 0},
		{"integer:test1", Less, 0.5},
		{"integer:test1", Greater, 10},
		{"integer:test1", Greater, 10.1},
		{"integer:test1", Equals, 10},
		{"integer:test1", Equals, 10.1},
		{"integer:test1", Equals, "123"},
	})

	c.Assert(errs, check.HasLen, 0)

	errs = Validate([]*Validator{
		{"boolean:test5", Empty, nil},
		{"integer:test1", Less, 10},
		{"integer:test1", Greater, 0},
		{"integer:test1", Equals, 1},
		{"integer:test1", Greater, "12345"},
		{"integer:test1", NotContains, []string{"A", "B", "C"}},
	})

	c.Assert(errs, check.HasLen, 6)

	c.Assert(errs[0].Error(), check.Equals, "Property boolean:test5 can't be empty")
	c.Assert(errs[1].Error(), check.Equals, "Property integer:test1 can't be less than 10")
	c.Assert(errs[2].Error(), check.Equals, "Property integer:test1 can't be greater than 0")
	c.Assert(errs[3].Error(), check.Equals, "Property integer:test1 can't be equal 1")
	c.Assert(errs[4].Error(), check.Equals, "Wrong validator for property integer:test1")
	c.Assert(errs[5].Error(), check.Equals, "Property integer:test1 doesn't contains any valid value")

	fakeConfig := &Config{
		data: map[string]string{
			"test:empty":   "",
			"test:string":  "test",
			"test:integer": "10",
			"test:float":   "10.0",
			"test:boolean": "false",
		},
	}

	c.Assert(Empty(fakeConfig, "test:empty", nil), check.NotNil)
	c.Assert(Empty(fakeConfig, "test:string", nil), check.IsNil)

	c.Assert(Less(fakeConfig, "test:integer", 30), check.NotNil)
	c.Assert(Less(fakeConfig, "test:integer", 5), check.IsNil)
	c.Assert(Less(fakeConfig, "test:float", 30.0), check.NotNil)
	c.Assert(Less(fakeConfig, "test:float", 5.0), check.IsNil)
	c.Assert(Less(fakeConfig, "test:string", "30"), check.NotNil)

	c.Assert(Greater(fakeConfig, "test:integer", 5), check.NotNil)
	c.Assert(Greater(fakeConfig, "test:integer", 30), check.IsNil)
	c.Assert(Greater(fakeConfig, "test:float", 5.0), check.NotNil)
	c.Assert(Greater(fakeConfig, "test:float", 30.0), check.IsNil)
	c.Assert(Greater(fakeConfig, "test:string", "30"), check.NotNil)

	c.Assert(Equals(fakeConfig, "test:empty", ""), check.NotNil)
	c.Assert(Equals(fakeConfig, "test:string", "test"), check.NotNil)
	c.Assert(Equals(fakeConfig, "test:integer", 10), check.NotNil)
	c.Assert(Equals(fakeConfig, "test:float", 10.0), check.NotNil)
	c.Assert(Equals(fakeConfig, "test:boolean", false), check.NotNil)

	c.Assert(Equals(fakeConfig, "test:empty", []string{}), check.NotNil)
	c.Assert(Equals(fakeConfig, "test:empty", "1"), check.IsNil)
	c.Assert(Equals(fakeConfig, "test:string", "testtest"), check.IsNil)
	c.Assert(Equals(fakeConfig, "test:integer", 15), check.IsNil)
	c.Assert(Equals(fakeConfig, "test:float", 130.0), check.IsNil)
	c.Assert(Equals(fakeConfig, "test:boolean", true), check.IsNil)

	c.Assert(NotContains(fakeConfig, "test:string", []string{"A", "B", "test"}), check.IsNil)
	c.Assert(NotContains(fakeConfig, "test:string", []string{"A", "B"}), check.NotNil)
	c.Assert(NotContains(fakeConfig, "test:string", 0), check.NotNil)
}
开发者ID:essentialkaos,项目名称:ek,代码行数:83,代码来源:knf_test.go

示例10: TestDefault

func (s *KNFSuite) TestDefault(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetS("string:test100", "fail"), check.Equals, "fail")
	c.Assert(GetB("boolean:test100", true), check.Equals, true)
	c.Assert(GetI("integer:test100", 9999), check.Equals, 9999)
	c.Assert(GetF("integer:test100", 123.45), check.Equals, 123.45)
	c.Assert(GetM("file-mode:test100", 0755), check.Equals, os.FileMode(0755))
	c.Assert(GetS("string:test6", "fail"), check.Equals, "fail")
}
开发者ID:essentialkaos,项目名称:ek,代码行数:15,代码来源:knf_test.go

示例11: TestNil

func (s *KNFSuite) TestNil(c *check.C) {
	var nilConf *Config

	c.Assert(nilConf.GetS("formating:test1"), check.Equals, "")
	c.Assert(nilConf.GetI("formating:test1"), check.Equals, 0)
	c.Assert(nilConf.GetF("formating:test1"), check.Equals, 0.0)
	c.Assert(nilConf.GetB("formating:test1"), check.Equals, false)
	c.Assert(nilConf.GetM("formating:test1"), check.Equals, os.FileMode(0))
	c.Assert(nilConf.HasSection("formating"), check.Equals, false)
	c.Assert(nilConf.HasProp("formating:test1"), check.Equals, false)
	c.Assert(nilConf.Sections(), check.HasLen, 0)
	c.Assert(nilConf.Props("formating"), check.HasLen, 0)

	_, err := nilConf.Reload()

	c.Assert(err, check.NotNil)
	c.Assert(err.Error(), check.Equals, "Config is nil")

	errs := nilConf.Validate([]*Validator{})

	c.Assert(errs, check.Not(check.HasLen), 0)
	c.Assert(errs[0].Error(), check.Equals, "Config is nil")
}
开发者ID:essentialkaos,项目名称:ek,代码行数:23,代码来源:knf_test.go

示例12: TestMacro

func (s *KNFSuite) TestMacro(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetS("macro:test1"), check.Equals, "100")
	c.Assert(GetI("macro:test1"), check.Equals, 100)
	c.Assert(GetS("macro:test2"), check.Equals, "100.50")
	c.Assert(GetS("macro:test3"), check.Equals, "Value is 100.50")
	c.Assert(GetS("macro:test4"), check.Equals, "\"Value is 100.50\"")
	c.Assert(GetS("macro:test5"), check.Equals, "{ABC}")
	c.Assert(GetS("macro:test6"), check.Equals, "{}")
}
开发者ID:essentialkaos,项目名称:ek,代码行数:16,代码来源:knf_test.go

示例13: TestWalker

func (s *FSSuite) TestWalker(c *check.C) {
	tmpDir := c.MkDir()

	os.Chdir(tmpDir)

	tmpDir, _ = os.Getwd()

	os.MkdirAll(tmpDir+"/dir1/dir2/dir3/dir4", 0755)
	os.Chdir(tmpDir)

	c.Assert(Current(), check.Equals, tmpDir)
	c.Assert(Pop(), check.Equals, tmpDir)

	dirStack = nil

	c.Assert(Push("dir1"), check.Equals, tmpDir+"/dir1")
	c.Assert(Push("dir9"), check.Equals, "")
	c.Assert(Push("dir2/dir3"), check.Equals, tmpDir+"/dir1/dir2/dir3")
	c.Assert(Push("dir4"), check.Equals, tmpDir+"/dir1/dir2/dir3/dir4")
	c.Assert(Push("dir9"), check.Equals, "")
	c.Assert(Pop(), check.Equals, tmpDir+"/dir1/dir2/dir3")
	c.Assert(Pop(), check.Equals, tmpDir+"/dir1")
	c.Assert(Pop(), check.Equals, tmpDir)
	c.Assert(Pop(), check.Equals, tmpDir)
}
开发者ID:essentialkaos,项目名称:ek,代码行数:25,代码来源:fs_test.go

示例14: TestList

func (s *FSSuite) TestList(c *check.C) {
	tmpDir := c.MkDir()

	os.Mkdir(tmpDir+"/.dir0", 0755)

	os.Create(tmpDir + "/.file0")
	os.Create(tmpDir + "/file1.mp3")
	os.Create(tmpDir + "/file2.jpg")

	os.Mkdir(tmpDir+"/dir1", 0755)
	os.Mkdir(tmpDir+"/dir2", 0755)

	os.Create(tmpDir + "/dir1/file3.mp3")
	os.Create(tmpDir + "/dir2/file4.wav")

	os.Mkdir(tmpDir+"/dir1/dir3", 0755)

	listing1 := List(tmpDir, false)
	listing2 := List(tmpDir, true)
	listing3 := ListAll(tmpDir, false)
	listing4 := ListAll(tmpDir, true)
	listing5 := ListAllDirs(tmpDir, false)
	listing6 := ListAllDirs(tmpDir, true)
	listing7 := ListAllFiles(tmpDir, false)
	listing8 := ListAllFiles(tmpDir, true)
	listing9 := ListAllFiles(tmpDir, true, &ListingFilter{MatchPatterns: []string{"*.mp3", "*.wav"}})
	listing10 := ListAllFiles(tmpDir, true, &ListingFilter{NotMatchPatterns: []string{"*.mp3"}})
	listing11 := List(tmpDir, true, &ListingFilter{Perms: "DR"})
	listing12 := List(tmpDir, true, &ListingFilter{NotPerms: "DR"})

	sort.Strings(listing1)
	sort.Strings(listing2)
	sort.Strings(listing3)
	sort.Strings(listing4)
	sort.Strings(listing5)
	sort.Strings(listing6)
	sort.Strings(listing7)
	sort.Strings(listing8)
	sort.Strings(listing9)
	sort.Strings(listing10)
	sort.Strings(listing11)
	sort.Strings(listing12)

	c.Assert(
		listing1,
		check.DeepEquals,
		[]string{".dir0", ".file0", "dir1", "dir2", "file1.mp3", "file2.jpg"},
	)

	c.Assert(
		listing2,
		check.DeepEquals,
		[]string{"dir1", "dir2", "file1.mp3", "file2.jpg"},
	)

	c.Assert(
		listing3,
		check.DeepEquals,
		[]string{".dir0", ".file0", "dir1", "dir1/dir3", "dir1/file3.mp3", "dir2", "dir2/file4.wav", "file1.mp3", "file2.jpg"},
	)

	c.Assert(
		listing4,
		check.DeepEquals,
		[]string{"dir1", "dir1/dir3", "dir1/file3.mp3", "dir2", "dir2/file4.wav", "file1.mp3", "file2.jpg"},
	)

	c.Assert(
		listing5,
		check.DeepEquals,
		[]string{".dir0", "dir1", "dir1/dir3", "dir2"},
	)

	c.Assert(
		listing6,
		check.DeepEquals,
		[]string{"dir1", "dir1/dir3", "dir2"},
	)

	c.Assert(
		listing7,
		check.DeepEquals,
		[]string{".file0", "dir1/file3.mp3", "dir2/file4.wav", "file1.mp3", "file2.jpg"},
	)

	c.Assert(
		listing8,
		check.DeepEquals,
		[]string{"dir1/file3.mp3", "dir2/file4.wav", "file1.mp3", "file2.jpg"},
	)

	c.Assert(
		listing9,
		check.DeepEquals,
		[]string{"dir1/file3.mp3", "dir2/file4.wav", "file1.mp3"},
	)

	c.Assert(
		listing10,
		check.DeepEquals,
//.........这里部分代码省略.........
开发者ID:essentialkaos,项目名称:ek,代码行数:101,代码来源:fs_test.go

示例15: TestInteger

func (s *KNFSuite) TestInteger(c *check.C) {
	var err error

	err = Global(s.ConfigPath)

	c.Assert(global, check.NotNil)
	c.Assert(err, check.IsNil)

	c.Assert(GetI("integer:test1"), check.Equals, 1)
	c.Assert(GetI("integer:test2"), check.Equals, -5)
	c.Assert(GetI("integer:test3"), check.Equals, 10000000)
	c.Assert(GetI("integer:test4"), check.Equals, 0)
	c.Assert(GetI("integer:test5"), check.Equals, 0xFF)
	c.Assert(GetF("integer:test6"), check.Equals, 123.4)
	c.Assert(GetF("integer:test7"), check.Equals, 123.456789)
	c.Assert(GetF("integer:test8"), check.Equals, 0.0)
	c.Assert(GetI("integer:test8"), check.Equals, 0)
	c.Assert(GetF("integer:test9"), check.Equals, 0.0)
}
开发者ID:essentialkaos,项目名称:ek,代码行数:19,代码来源:knf_test.go


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