本文整理汇总了Golang中kego/io/tests.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestTestRulesApplyToObjects
func TestTestRulesApplyToObjects(t *testing.T) {
cb := tests.New().TempGopath(true).CopyToTemp("kego.io/process/validate/tests")
defer cb.Cleanup()
path, dir := cb.TempPackage("a", map[string]string{
"a.yml": `
type: system:package
id: a
aliases:
tests: kego.io/process/validate/tests
`,
"b.yml": `
type: tests:a
id: b
b: foobar
rules:
- selector: ".b"
type: "system:@string"
max-length: 5
`,
})
cb.Path(path).Dir(dir).Alias("tests", "kego.io/process/validate/tests").Jauto().Sauto(parser.Parse)
errors, err := ValidatePackage(cb.Ctx())
require.NoError(t, err)
assert.IsError(t, errors[0], "HLKQWDCMRN")
}
示例2: TestRulesEnforcer
func TestRulesEnforcer(t *testing.T) {
cb := tests.New().TempGopath(true).CopyToTemp("kego.io/process/validate/tests")
defer cb.Cleanup()
path, dir := cb.TempPackage("a", map[string]string{
"a.yml": `
type: system:package
id: a
aliases:
tests: kego.io/process/validate/tests
`,
"b.yml": `
type: tests:a
id: b
b: foo
rules:
-
type: tests:@a
`,
})
cb.Path(path).Dir(dir).Alias("tests", "kego.io/process/validate/tests").Jauto().Sauto(parser.Parse)
errors, err := ValidatePackage(cb.Ctx())
require.NoError(t, err)
assert.Equal(t, 0, len(errors))
}
示例3: TestRuleId
func TestRuleId(t *testing.T) {
cb := tests.New().TempGopath(true)
defer cb.Cleanup()
pathA, dirA := cb.TempPackage("a", map[string]string{
"a.json": `{
"type": "system:type",
"id": "a",
"rule": {
"type": "system:type",
"id": "foo"
}
}`,
})
cb.Path(pathA).Dir(dirA).Cmd().Sempty().Jsystem()
_, err := Parse(cb.Ctx(), pathA)
assert.IsError(t, err, "VFUNPHUFHD")
assert.HasError(t, err, "JKARKEDTIW")
cb.TempFile("a.json", `{
"type": "system:type",
"id": "a",
"rule": {
"type": "system:type"
}
}`)
_, err = Parse(cb.Ctx(), pathA)
assert.IsError(t, err, "VFUNPHUFHD")
assert.HasError(t, err, "LMALEMKFDI")
}
示例4: TestStructs
func TestStructs(t *testing.T) {
cb := tests.New().TempGopath(true)
defer cb.Cleanup()
testTypeCollection(t, cb)
testTypeAlias(t, cb)
}
示例5: TestImportSystem
func TestImportSystem(t *testing.T) {
cb := tests.New().TempGopath(true)
defer cb.Cleanup()
pathA, dirA := cb.TempPackage("a", map[string]string{
"package.json": `{
"type": "system:package",
"aliases": {
"s": "kego.io/system"
}
}`,
})
cb.Path(pathA).Dir(dirA).Cmd().Sempty().Jsystem()
_, err := Parse(cb.Ctx(), pathA)
assert.IsError(t, err, "EWMLNJDXKC")
pathB, dirB := cb.TempPackage("b", map[string]string{
"package.json": `{
"type": "system:package",
"aliases": {
"system": "a.b/c"
}
}`,
})
cb.Path(pathB).Dir(dirB)
_, err = Parse(cb.Ctx(), pathB)
assert.IsError(t, err, "EWMLNJDXKC")
}
示例6: TestImport
func TestImport(t *testing.T) {
cb := tests.New().TempGopath(true)
defer cb.Cleanup()
pathA, _ := cb.TempPackage("a", map[string]string{
"a.json": `{
"type": "system:type",
"id": "a"
}`,
})
pathB, dirB := cb.TempPackage("b", map[string]string{
"package.json": `{
"type": "system:package",
"aliases": {
"a": "` + pathA + `"
}
}`,
"b.json": `{
"type": "a:a",
"id": "a"
}`,
"c.json": `{
"type": "system:foo",
"id": "c"
}`,
})
cb.Path(pathB).Dir(dirB).Cmd().Sempty().Jsystem()
_, err := Parse(cb.Ctx(), pathB)
require.NoError(t, err)
}
示例7: TestParse1
func TestParse1(t *testing.T) {
cb := tests.New().TempGopath(true)
defer cb.Cleanup()
path, dir := cb.TempPackage("a", map[string]string{
"a.json": `{
"description": "a",
"type": "system:type",
"id": "b",
"fields": {
"c": {
"type": "system:@string"
}
}
}`,
})
cb.Path(path).Dir(dir).Cmd().Sempty().Jsystem()
_, err := Parse(cb.Ctx(), path)
require.NoError(t, err)
scache := sysctx.FromContext(cb.Ctx())
i, ok := scache.GetType(path, "b")
assert.True(t, ok)
ty, ok := i.(*system.Type)
assert.True(t, ok)
assert.Equal(t, "a", ty.Description)
}
示例8: TestValidate_NeedsTypes
func TestValidate_NeedsTypes(t *testing.T) {
cb := tests.New().TempGopath(true)
defer cb.Cleanup()
path, dir := cb.TempPackage("a", map[string]string{
"a.json": `{
"description": "a",
"type": "system:type",
"id": "a",
"fields": {
"a": {
"type": "system:@string"
}
}
}`,
})
cb.Path(path).Dir(dir).Jsystem().Sauto(parser.Parse)
errors, err := ValidatePackage(cb.Ctx())
require.NoError(t, err)
assert.Equal(t, 0, len(errors))
}
示例9: TestScanDirToFiles
func TestScanDirToFiles(t *testing.T) {
cb := tests.New().TempGopath(false)
defer cb.Cleanup()
_, dir := cb.TempPackage("a", map[string]string{
"b.json": "c",
})
// make a dir so we hit the IsRegular block
require.NoError(t, os.Mkdir(filepath.Join(dir, "d"), 0777))
// put another file in it
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "d", "e.json"), []byte("f"), 0777))
ch := ScanDirToFiles(cb.Ctx(), dir, false)
out := []File{}
for f := range ch {
require.NoError(t, f.Err)
out = append(out, f)
}
assert.Equal(t, 1, len(out))
assert.Equal(t, filepath.Join(dir, "b.json"), out[0].File)
ch = ScanDirToFiles(cb.Ctx(), dir, true)
out = []File{}
for f := range ch {
require.NoError(t, f.Err)
out = append(out, f)
}
assert.Equal(t, 2, len(out))
assert.Equal(t, filepath.Join(dir, "b.json"), out[0].File)
assert.Equal(t, filepath.Join(dir, "d", "e.json"), out[1].File)
}
示例10: testGenerated
func testGenerated(t *testing.T, path string) {
cb := tests.New().Path(path).Jauto().Sauto(parser.Parse)
pi, err := parser.Parse(cb.Ctx(), path)
require.NoError(t, err)
generatedBytes, err := generate.Structs(cb.Ctx(), pi.Env)
require.NoError(t, err)
generatedString := string(generatedBytes)
existingFilePath := filepath.Join(pi.Dir, "generated.go")
existingBytes, err := ioutil.ReadFile(existingFilePath)
require.NoError(t, err)
existingString := string(existingBytes)
// TODO: The "goimports" tool will often re-order the imports, so this is
// a kludge to remove it before comparing. This is not ideal!
importsRegex := regexp.MustCompile(`(?ms:\nimport \(\n.*\n\)\n)`)
generatedString = importsRegex.ReplaceAllString(generatedString, "-")
existingString = importsRegex.ReplaceAllString(existingString, "-")
if generatedString != existingString {
fmt.Println("Generated code for " + path + " is not what is present:")
fmt.Println(generatedString)
}
require.Equal(t, generatedString, existingString)
}
示例11: TestFieldExtraRulesObject
func TestFieldExtraRulesObject(t *testing.T) {
cb := tests.New().TempGopath(true).CopyToTemp("kego.io/process/validate/tests")
defer cb.Cleanup()
path, dir := cb.TempPackage("a", map[string]string{
"a.yml": `
type: system:package
id: a
aliases:
tests: kego.io/process/validate/tests
`,
"b.yml": `
type: tests:f
id: b
a:
type: tests:a
b: foo
`,
})
cb.Path(path).Dir(dir).Alias("tests", "kego.io/process/validate/tests").Jauto().Sauto(parser.Parse)
errors, err := ValidatePackage(cb.Ctx())
require.NoError(t, err)
assert.IsError(t, errors[0], "HLKQWDCMRN")
}
示例12: TestRuleHasExtraRules
func TestRuleHasExtraRules(t *testing.T) {
cb := tests.New().TempGopath(true).CopyToTemp("kego.io/process/validate/tests")
defer cb.Cleanup()
path, dir := cb.TempPackage("a", map[string]string{
"a.yml": `
type: system:package
id: a
aliases:
tests: kego.io/process/validate/tests
`,
"b.yml": `
type: tests:f
id: b
d: foo
`,
})
cb.Path(path).Dir(dir).Alias("tests", "kego.io/process/validate/tests").Jauto().Sauto(parser.Parse)
errors, err := ValidatePackage(cb.Ctx())
require.NoError(t, err)
assert.IsError(t, errors[0], "HLKQWDCMRN")
assert.Equal(t, "MinLength: length of \"foo\" must not be less than 7", errors[0].Description)
}
示例13: TestValidate_error1
func TestValidate_error1(t *testing.T) {
cb := tests.New().TempGopath(true)
defer cb.Cleanup()
path, dir := cb.TempPackage("b", map[string]string{
"b.json": `{
"description": "b",
"type": "system:type",
"id": "b",
"fields": {
"b": {
"type": "system:@string",
"min-length": 10,
"max-length": 5
}
}
}`,
})
cb.Path(path).Dir(dir).Jsystem().Sauto(parser.Parse)
errors, err := ValidatePackage(cb.Ctx())
// @string is invalid because minLength > maxLength
require.NoError(t, err)
assert.IsError(t, errors[0], "KULDIJUYFB")
}
示例14: TestCircularImport
func TestCircularImport(t *testing.T) {
cb := tests.New().TempGopath(true)
defer cb.Cleanup()
pathA, dirA := cb.TempPackage("a", map[string]string{})
pathB, dirB := cb.TempPackage("b", map[string]string{})
ioutil.WriteFile(filepath.Join(dirA, "package.json"), []byte(`
{
"type": "system:package",
"aliases": {
"b": "`+pathB+`"
}
}
`), 0777)
ioutil.WriteFile(filepath.Join(dirB, "package.json"), []byte(`
{
"type": "system:package",
"aliases": {
"a": "`+pathA+`"
}
}
`), 0777)
cb.Path(pathA).Dir(dirA).Cmd().Sempty().Jsystem()
_, err := Parse(cb.Ctx(), pathA)
assert.IsError(t, err, "NOVMGYKHHI")
assert.HasError(t, err, "SCSCFJPPHD")
}
示例15: TestComparePackageHash
func TestComparePackageHash(t *testing.T) {
cb := tests.New().TempGopath(true)
path, _ := cb.TempPackage("a", map[string]string{
"a.yaml": "type: system:package",
})
cb.Path(path).Jempty().Spkg(path)
// "a.b/c" not found in scache.
changes, err := comparePackageHash(cb.Ctx(), "a.b/c")
assert.IsError(t, err, "NHXWLPHCHL")
assert.False(t, changes)
// path not found in jcache
changes, err = comparePackageHash(cb.Ctx(), path)
require.NoError(t, err)
assert.True(t, changes)
cb.Jsystem().Jpkg(path, 999).Sauto(parser.Parse)
// hash changed
changes, err = comparePackageHash(cb.Ctx(), path)
require.NoError(t, err)
assert.True(t, changes)
scache := sysctx.FromContext(cb.Ctx())
pi, _ := scache.Get(path)
cb.Jpkg(path, pi.Hash)
// hash correct
changes, err = comparePackageHash(cb.Ctx(), path)
require.NoError(t, err)
assert.False(t, changes)
pi.Aliases["c"] = "a.b/c"
changes, err = comparePackageHash(cb.Ctx(), path)
assert.IsError(t, err, "DGJTLHQOCQ")
assert.False(t, changes)
pi1 := scache.Set("a.b/c")
changes, err = comparePackageHash(cb.Ctx(), path)
require.NoError(t, err)
assert.True(t, changes)
cb.Jpkg("a.b/c", 1)
pi1.Hash = 2
changes, err = comparePackageHash(cb.Ctx(), path)
require.NoError(t, err)
assert.True(t, changes)
pi1.Hash = 1
changes, err = comparePackageHash(cb.Ctx(), path)
require.NoError(t, err)
assert.False(t, changes)
}