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

Golang assert.IsError函数代码示例

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

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



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


示例16: TestNoTypeError

func TestNoTypeError(t *testing.T) {

	cb := tests.New().TempGopath(true)
	defer cb.Cleanup()

	pathA, dirA := cb.TempPackage("a", map[string]string{
		"a.json": `{
			"id": "a"
		}`,
	})
	cb.Path(pathA).Dir(dirA).Cmd().Sempty().Jsystem()
	_, err := Parse(cb.Ctx(), pathA)
	assert.IsError(t, err, "GJRHNGGWFD")
	assert.HasError(t, err, "MSNIGTIDIO")

	err = scanForTypesAndExports(cb.Ctx(), cb.Env(), nil, &PackageHasher{})
	assert.IsError(t, err, "NUKWIHYFMQ")

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


示例17: TestNode_extractFields

func TestNode_extractFields(t *testing.T) {
	cb := tests.Context("a.b/c").Sempty()

	ty := &system.Type{}
	f := map[string]*system.Field{}
	err := extractFields(cb.Ctx(), f, ty)
	assert.IsError(t, err, "YRFWOTIGFT")

	cb.Ssystem(parser.Parse)

	ty = &system.Type{Embed: []*system.Reference{system.NewReference("a.b/c", "d")}}
	err = extractFields(cb.Ctx(), f, ty)
	assert.IsError(t, err, "SLIRILCARQ")

	f = map[string]*system.Field{"a": nil}
	ty = &system.Type{Fields: map[string]system.RuleInterface{"a": nil}}
	err = extractFields(cb.Ctx(), f, ty)
	assert.IsError(t, err, "BARXPFXQNB")
}
开发者ID:kego,项目名称:ke,代码行数:19,代码来源:node_test.go


示例18: TestNewReferenceFromString

func TestNewReferenceFromString(t *testing.T) {
	cb := tests.Context("a.b/c")
	r, err := NewReferenceFromString(cb.Ctx(), "d")
	require.NoError(t, err)
	assert.Equal(t, NewReference("a.b/c", "d"), r)

	r, err = NewReferenceFromString(cb.Ctx(), "e:f")
	assert.IsError(t, err, "VXRGOQHWNB")

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


示例19: TestNode_SetValueZero3

func TestNode_SetValueZero3(t *testing.T) {

	n := NewNode()
	err := n.setZero(context.Background(), false, true)
	assert.IsError(t, err, "NYQULBBBHO")

	n = NewNode()
	err = n.setZero(context.Background(), true, true)
	assert.IsError(t, err, "XRYLQWRNPH")

	n = NewNode()
	err = n.setZero(context.Background(), true, false)
	assert.IsError(t, err, "ABXFQOYCBA")

	n = NewNode()
	n.Type = &system.Type{Native: system.NewString("map")}
	err = n.setZero(context.Background(), false, false)
	assert.IsError(t, err, "VGKTIRMDTJ")

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


示例20: TestArrayRule_Enforce

func TestArrayRule_Enforce(t *testing.T) {
	r := ArrayRule{MaxItems: NewInt(2)}
	fail, messages, err := r.Enforce(envctx.Empty, []int{1, 2})
	require.NoError(t, err)
	assert.Equal(t, 0, len(messages))
	assert.False(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, []int{1, 2, 3})
	require.NoError(t, err)
	assert.Equal(t, "MaxItems: length 3 should not be greater than 2", messages[0])
	assert.True(t, fail)

	r = ArrayRule{MinItems: NewInt(2)}
	fail, messages, err = r.Enforce(envctx.Empty, []int{1, 2})
	require.NoError(t, err)
	assert.Equal(t, 0, len(messages))
	assert.False(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, []int{1})
	require.NoError(t, err)
	assert.Equal(t, "MinItems: length 1 should not be less than 2", messages[0])
	assert.True(t, fail)

	r = ArrayRule{UniqueItems: true}
	fail, messages, err = r.Enforce(envctx.Empty, []int{1, 2, 3, 4})
	require.NoError(t, err)
	assert.Equal(t, 0, len(messages))
	assert.False(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, []int{1, 2, 3, 3})
	require.NoError(t, err)
	assert.Equal(t, "UniqueItems: array contains duplicate item 3", messages[0])
	assert.True(t, fail)

	fail, messages, err = r.Enforce(envctx.Empty, []string{"foo", "bar", "foo"})
	require.NoError(t, err)
	assert.Equal(t, "UniqueItems: array contains duplicate item foo", messages[0])
	assert.True(t, fail)

	r = ArrayRule{}
	fail, messages, err = r.Enforce(envctx.Empty, []int{1, 2})
	require.NoError(t, err)
	assert.Equal(t, 0, len(messages))
	assert.False(t, fail)

	r = ArrayRule{MaxItems: NewInt(2)}
	fail, messages, err = r.Enforce(envctx.Empty, map[string]int{"foo": 1, "bar": 2})
	assert.IsError(t, err, "OWTAUVVFBL")

	s := &StringRule{}
	var cr CollectionRule = &ArrayRule{Items: s}
	assert.Equal(t, s, cr.GetItemsRule())
}
开发者ID:kego,项目名称:ke,代码行数:53,代码来源:array_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang assert.NotNil函数代码示例发布时间:2022-05-23
下一篇:
Golang assert.False函数代码示例发布时间: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