當前位置: 首頁>>代碼示例>>Golang>>正文


Golang tests.New函數代碼示例

本文整理匯總了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")

}
開發者ID:kego,項目名稱:ke,代碼行數:29,代碼來源:validate_test.go

示例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))
}
開發者ID:kego,項目名稱:ke,代碼行數:27,代碼來源:validate_test.go

示例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")
}
開發者ID:kego,項目名稱:ke,代碼行數:31,代碼來源:parser_test.go

示例4: TestStructs

func TestStructs(t *testing.T) {
	cb := tests.New().TempGopath(true)
	defer cb.Cleanup()

	testTypeCollection(t, cb)
	testTypeAlias(t, cb)
}
開發者ID:kego,項目名稱:ke,代碼行數:7,代碼來源:type_ext_test.go

示例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")

}
開發者ID:kego,項目名稱:ke,代碼行數:30,代碼來源:parser_test.go

示例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)

}
開發者ID:kego,項目名稱:ke,代碼行數:33,代碼來源:parser_test.go

示例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)

}
開發者ID:kego,項目名稱:ke,代碼行數:31,代碼來源:parser_test.go

示例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))

}
開發者ID:kego,項目名稱:ke,代碼行數:25,代碼來源:validate_test.go

示例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)

}
開發者ID:kego,項目名稱:ke,代碼行數:32,代碼來源:scanner_test.go

示例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)
}
開發者ID:kego,項目名稱:ke,代碼行數:26,代碼來源:generate_ext_test.go

示例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")
}
開發者ID:kego,項目名稱:ke,代碼行數:26,代碼來源:validate_test.go

示例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)
}
開發者ID:kego,項目名稱:ke,代碼行數:25,代碼來源:validate_test.go

示例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")

}
開發者ID:kego,項目名稱:ke,代碼行數:28,代碼來源:validate_test.go

示例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")

}
開發者ID:kego,項目名稱:ke,代碼行數:31,代碼來源:parser_test.go

示例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)

}
開發者ID:kego,項目名稱:ke,代碼行數:59,代碼來源:validate_test.go


注:本文中的kego/io/tests.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。