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


Golang assert.IsError函数代码示例

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


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

示例1: TestScan_errors

func TestScan_errors(t *testing.T) {

	cb := tests.Context("").Cmd().Sempty().Jsystem().TempGopath(true)
	defer cb.Cleanup()

	_, err := Parse(cb.Ctx(), "does-not-exist")
	require.IsError(t, err, "SBALWXUPKN") // Error from ScanForEnv
	assert.HasError(t, err, "NIKCKQAKUI") // GoGet: exit status 1: package does-not-exist

	path, _ := cb.TempPackage("a", map[string]string{
		"a.json": `{
			"type": "system:package",
			"recursive": false
		}`,
		"b.json": "foo",
	})

	cb.Path(path)

	_, err = Parse(cb.Ctx(), path)
	assert.IsError(t, err, "VFUNPHUFHD")  // Error from scanForTypes
	assert.HasError(t, err, "HCYGNBDFFA") // Error trying to unmarshal a type

	path, _ = cb.TempPackage("a", map[string]string{
		"a.json": "foo",
	})

	cb.Path(path)

	_, err = Parse(cb.Ctx(), path)
	assert.IsError(t, err, "GJRHNGGWFD")  // Error from ScanForEnv
	assert.HasError(t, err, "MTDCXBYBEJ") // Error trying to scan for packages

}
开发者ID:kego,项目名称:ke,代码行数:34,代码来源:parser_test.go

示例2: 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

示例3: TestNode_DeleteArrayChild2

func TestNode_DeleteArrayChild2(t *testing.T) {
	_, n := data.Setup(t)
	err := n.DeleteArrayChild(0)
	assert.IsError(t, err, "NFVEWWCSMV")
	err = n.Map["mjs"].DeleteArrayChild(0)
	assert.IsError(t, err, "NFVEWWCSMV")
}
开发者ID:kego,项目名称:ke,代码行数:7,代码来源:node_ext_test.go

示例4: 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

示例5: TestNode_ReorderArrayChild2

func TestNode_ReorderArrayChild2(t *testing.T) {
	_, n := data.Setup(t)
	err := n.ReorderArrayChild(0, 1)
	assert.IsError(t, err, "MHEXGBUQOL")
	err = n.Map["mjs"].ReorderArrayChild(0, 1)
	assert.IsError(t, err, "MHEXGBUQOL")
}
开发者ID:kego,项目名称:ke,代码行数:7,代码来源:node_ext_test.go

示例6: TestNode_DeleteObjectChild2

func TestNode_DeleteObjectChild2(t *testing.T) {
	cb, n := data.Setup(t)
	err := n.Map["mjs"].DeleteObjectChild(cb.Ctx(), "a")
	assert.IsError(t, err, "BMUSITINTC")
	err = n.Map["ajs"].DeleteObjectChild(cb.Ctx(), "a")
	assert.IsError(t, err, "BMUSITINTC")
}
开发者ID:kego,项目名称:ke,代码行数:7,代码来源:node_ext_test.go

示例7: TestNode_DeleteMapChild2

func TestNode_DeleteMapChild2(t *testing.T) {
	_, n := data.Setup(t)
	err := n.DeleteMapChild("js")
	assert.IsError(t, err, "ACRGPCPPFK")
	err = n.Map["ajs"].DeleteMapChild("a")
	assert.IsError(t, err, "ACRGPCPPFK")
}
开发者ID:kego,项目名称:ke,代码行数:7,代码来源:node_ext_test.go

示例8: 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

示例9: TestNode_InitialiseArrayChild2

func TestNode_InitialiseArrayChild2(t *testing.T) {
	cb, n := data.Setup(t)
	c := node.NewNode()
	require.NoError(t, c.InitialiseArrayItem(cb.Ctx(), n.Map["ajs"], 5))
	err := c.AddToArray(cb.Ctx(), n.Map["ajs"], 5, true)
	assert.IsError(t, err, "GHJIDXABLL")

	// kludge the Val to be empty
	n.Map["ajs"].Val.Set(reflect.ValueOf([]string{}))
	require.NoError(t, c.InitialiseArrayItem(cb.Ctx(), n.Map["ajs"], 1))
	err = c.AddToArray(cb.Ctx(), n.Map["ajs"], 1, true)
	assert.IsError(t, err, "YFKMXFUPHY")

}
开发者ID:kego,项目名称:ke,代码行数:14,代码来源:node_ext_test.go

示例10: TestBuilder

func TestBuilder(t *testing.T) {
	g := New("a.b/c")
	b, err := g.Build()
	require.NoError(t, err)
	assert.Equal(t, "package c\n", string(b))
	g.buffer.Reset()

	g.Imports.Anonymous("e.f/g")
	b, err = g.Build()
	require.NoError(t, err)
	assert.Equal(t, "package c\n\nimport (\n\t_ \"e.f/g\"\n)\n", string(b))
	g.buffer.Reset()

	alias := g.Imports.Add("h.i/j")
	assert.Equal(t, "j", alias)

	b, err = g.Build()
	require.NoError(t, err)
	assert.Equal(t, "package c\n\nimport (\n\t_ \"e.f/g\"\n\t\"h.i/j\"\n)\n", string(b))
	g.buffer.Reset()

	g.SetPackageComment("comment")
	g.SetIntroComment("intro")
	g.Print("var ")
	g.Println("foo string")
	g.Printf("var bar int\n%s", "var baz bool")
	g.Println("")
	g.Println("func foo() {")
	g.PrintFunctionCall("k.l/m", "n", "o", "p")
	g.Println("")
	g.PrintMethodCall("a", "b", "c", "d")
	g.Println("}")
	b, err = g.Build()
	require.NoError(t, err)
	assert.Contains(t, string(b), `// comment
package c

// intro

import (
	_ "e.f/g"
	"h.i/j"
	"k.l/m"
)

var foo string
var bar int
var baz bool

func foo() {
	m.n(o, p)
	a.b(c, d)
}
`)

	g.Print("dfskjsdf")
	_, err = g.Build()
	assert.IsError(t, err, "CRBYOUOHPG") // Error formatting source

}
开发者ID:kego,项目名称:ke,代码行数:60,代码来源:builder_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: 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

示例15: 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


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