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

Golang require.NoError函数代码示例

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

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



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

示例1: TestNode_DeleteArrayChild

func TestNode_DeleteArrayChild(t *testing.T) {
	_, n := data.Setup(t)
	test := func(t *testing.T, n *node.Node, m *data.Multi) {
		require.NoError(t, n.Map["ajs"].DeleteArrayChild(1))
		assert.Equal(t, 3, len(n.Map["ajs"].Array))
		assert.Equal(t, 0, n.Map["ajs"].Array[0].Index)
		assert.Equal(t, 1, n.Map["ajs"].Array[1].Index)
		assert.Equal(t, 2, n.Map["ajs"].Array[2].Index)
		assert.Equal(t, []string{"ajs0", "ajs2", "ajs3"}, m.Ajs)

		require.NoError(t, n.Map["ajs"].DeleteArrayChild(2))
		assert.Equal(t, 2, len(n.Map["ajs"].Array))
		assert.Equal(t, 0, n.Map["ajs"].Array[0].Index)
		assert.Equal(t, 1, n.Map["ajs"].Array[1].Index)
		assert.Equal(t, []string{"ajs0", "ajs2"}, m.Ajs)

		require.NoError(t, n.Map["ajs"].DeleteArrayChild(0))
		assert.Equal(t, 1, len(n.Map["ajs"].Array))
		assert.Equal(t, 0, n.Map["ajs"].Array[0].Index)
		assert.Equal(t, []string{"ajs2"}, m.Ajs)

		require.NoError(t, n.Map["ajs"].DeleteArrayChild(0))
		assert.Equal(t, 0, len(n.Map["ajs"].Array))
		assert.Equal(t, []string{}, m.Ajs)
	}
	data.Run(t, n, n.Value.(*data.Multi), test)
}
开发者ID:kego,项目名称:ke,代码行数:27,代码来源:node_ext_test.go


示例2: TestBoolUnmarshalJSON

func TestBoolUnmarshalJSON(t *testing.T) {

	var b *Bool

	err := b.Unpack(envctx.Empty, Pack(nil), false)
	require.NoError(t, err)
	assert.Nil(t, b)

	b = NewBool(false)
	err = b.Unpack(envctx.Empty, Pack(true), false)
	require.NoError(t, err)
	assert.NotNil(t, b)
	assert.True(t, b.Value())

	b = NewBool(false)
	err = b.Unpack(envctx.Empty, Pack(map[string]interface{}{
		"type":  "system:bool",
		"value": true,
	}), false)
	require.NoError(t, err)
	assert.NotNil(t, b)
	assert.True(t, b.Value())

	b = NewBool(true)
	err = b.Unpack(envctx.Empty, Pack(false), false)
	require.NoError(t, err)
	assert.NotNil(t, b)
	assert.False(t, b.Value())

	b = NewBool(false)
	err = b.Unpack(envctx.Empty, Pack("foo"), false)
	assert.Error(t, err)

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


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


示例4: TestNumberUnmarshalJSON

func TestNumberUnmarshalJSON(t *testing.T) {

	var n *Number

	err := n.Unpack(envctx.Empty, Pack(nil), false)
	require.NoError(t, err)
	assert.Nil(t, n)

	n = NewNumber(0.0)
	err = n.Unpack(envctx.Empty, Pack(1.2), false)
	require.NoError(t, err)
	assert.NotNil(t, n)
	assert.Equal(t, 1.2, n.Value())

	n = NewNumber(0.0)
	err = n.Unpack(envctx.Empty, Pack(map[string]interface{}{
		"type":  "system:number",
		"value": 1.2,
	}), false)
	require.NoError(t, err)
	assert.NotNil(t, n)
	assert.Equal(t, 1.2, n.Value())

	n = NewNumber(0.0)
	err = n.Unpack(envctx.Empty, Pack("foo"), false)
	assert.Error(t, err)

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


示例5: TestNode_DeleteObjectChild

func TestNode_DeleteObjectChild(t *testing.T) {
	cb, n := data.Setup(t)

	test := func(t *testing.T, n *node.Node, m *data.Multi) {
		require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "js"))
		assert.True(t, n.Map["js"].Missing)
		assert.Equal(t, "", m.Js)
		require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "ss"))
		assert.Nil(t, m.Ss)
		require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "sr"))
		assert.Nil(t, m.Sr)
		require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "jn"))
		assert.Equal(t, 0.0, m.Jn)
		require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "sn"))
		assert.Nil(t, m.Sn)
		require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "jb"))
		assert.Equal(t, false, m.Jb)
		require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "sb"))
		assert.Nil(t, m.Sb)
		require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "i"))
		assert.Nil(t, m.I)
		require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "ajs"))
		assert.Nil(t, m.Ajs)
		require.NoError(t, n.DeleteObjectChild(cb.Ctx(), "mjs"))
		assert.Nil(t, m.Mjs)

	}
	data.Run(t, n, n.Value.(*data.Multi), test)
}
开发者ID:kego,项目名称:ke,代码行数:29,代码来源:node_ext_test.go


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


示例7: TestDeleteMutation1

func TestDeleteMutation1(t *testing.T) {
	cb, n := data.Setup(t)
	test := func(t *testing.T, n *node.Node, m *data.Multi) {
		var b, d, p *node.Node
		b = node.NewNode()
		d = n.Map["am"].Array[0]
		p = n.Map["am"]
		assert.Equal(t, "amjs0", n.Map["am"].Array[0].Map["js"].ValueString)
		assert.Equal(t, "amjs1", n.Map["am"].Array[1].Map["js"].ValueString)
		assert.Equal(t, "amjs0", m.Am[0].Js)
		assert.Equal(t, "amjs1", m.Am[1].Js)
		require.NoError(t, mutateDeleteNode(cb.Ctx(), d, p, b))
		assert.Equal(t, 1, len(n.Map["am"].Array))
		assert.Equal(t, 1, len(m.Am))
		assert.Equal(t, "amjs1", n.Map["am"].Array[0].Map["js"].ValueString)
		assert.Equal(t, "amjs1", m.Am[0].Js)
		require.NoError(t, mutateRestoreNode(cb.Ctx(), d, p, b))
		assert.Equal(t, 2, len(n.Map["am"].Array))
		assert.Equal(t, 2, len(m.Am))
		assert.Equal(t, "amjs0", n.Map["am"].Array[0].Map["js"].ValueString)
		assert.Equal(t, "amjs1", n.Map["am"].Array[1].Map["js"].ValueString)
		assert.Equal(t, "amjs0", m.Am[0].Js)
		assert.Equal(t, "amjs1", m.Am[1].Js)
	}
	test(t, n.Map["m"], n.Value.(*data.Multi).M)
}
开发者ID:kego,项目名称:ke,代码行数:26,代码来源:action_ext_test.go


示例8: TestStringUnmarshalJSON

func TestStringUnmarshalJSON(t *testing.T) {

	var s *String

	err := s.Unpack(envctx.Empty, Pack(nil), false)
	require.NoError(t, err)
	assert.Nil(t, s)

	s = NewString("")
	err = s.Unpack(envctx.Empty, Pack(`foo "bar"`), false)
	require.NoError(t, err)
	assert.NotNil(t, s)
	assert.Equal(t, `foo "bar"`, s.Value())

	s = NewString("")
	err = s.Unpack(envctx.Empty, Pack(map[string]interface{}{
		"type":  "system:string",
		"value": `foo "bar"`,
	}), false)
	require.NoError(t, err)
	assert.NotNil(t, s)
	assert.Equal(t, `foo "bar"`, s.Value())

	s = NewString("")
	err = s.Unpack(envctx.Empty, Pack(1.0), false)
	assert.Error(t, err)

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


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


示例10: TestNode_Backup

func TestNode_Backup(t *testing.T) {

	cb, n := data.Setup(t)

	test := func(t *testing.T, n *node.Node, m *data.Multi) {
		var err error
		b := n.Backup()
		err = n.RecomputeHash(cb.Ctx(), true)
		require.NoError(t, err)
		err = b.RecomputeHash(cb.Ctx(), true)
		require.NoError(t, err)
		require.Equal(t, b.Hash(), n.Hash())
		require.Equal(t, b.Value, n.Value)

		r := &node.Node{}
		r.Restore(cb.Ctx(), b)
		err = r.RecomputeHash(cb.Ctx(), true)
		require.NoError(t, err)
		require.Equal(t, r.Hash(), n.Hash())
		require.Equal(t, r.Value, n.Value)

	}

	data.Run(t, n, n.Value.(*data.Multi), test)

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


示例11: TestValidateNode

func TestValidateNode(t *testing.T) {
	cb := tests.New()
	errors, err := ValidateNode(cb.Ctx(), &node.Node{Value: nil})
	require.NoError(t, err)
	assert.Equal(t, 0, len(errors))
	errors, err = ValidateNode(cb.Ctx(), &node.Node{Value: 1, Null: true})
	require.NoError(t, err)
	assert.Equal(t, 0, len(errors))
	errors, err = ValidateNode(cb.Ctx(), &node.Node{Value: 1, Missing: true})
	require.NoError(t, err)
	assert.Equal(t, 0, len(errors))
}
开发者ID:kego,项目名称:ke,代码行数:12,代码来源:validate_test.go


示例12: getUtilParser

func getUtilParser(t *testing.T) *Parser {
	cb := tests.Context("a.b/c").Ssystem(parser.Parse)
	data := `{
		"type": "system:type",
		"id": "foo"
	}`
	n, err := node.Unmarshal(cb.Ctx(), []byte(data))
	require.NoError(t, err)
	p, err := CreateParser(cb.Ctx(), n)
	require.NoError(t, err)
	return p
}
开发者ID:kego,项目名称:ke,代码行数:12,代码来源:utilities_test.go


示例13: TestUniversalProduction

func TestUniversalProduction(t *testing.T) {
	p := getParser(t)

	f := p.universalProduction("a")
	out, err := f(&node.Node{})
	require.NoError(t, err)
	assert.False(t, out)

	f = p.universalProduction("*")
	out, err = f(&node.Node{})
	require.NoError(t, err)
	assert.True(t, out)
}
开发者ID:kego,项目名称:ke,代码行数:13,代码来源:selectors_test.go


示例14: TestNodeUnpack

func TestNodeUnpack(t *testing.T) {

	ctx, _, err := process.Initialise(context.Background(), &process.Options{
		Path: "kego.io/demo/site",
	})
	require.NoError(t, err)

	j := `{"type":"system:package","aliases":{"images":"kego.io/demo/common/images","units":"kego.io/demo/common/units","words":"kego.io/demo/common/words"}}`

	_, err = node.Unmarshal(ctx, []byte(j))
	require.NoError(t, err)

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


示例15: TestReferenceMarshalJson

func TestReferenceMarshalJson(t *testing.T) {

	var r *Reference
	b, _, _, _, err := r.Repack(envctx.Empty)
	require.NoError(t, err)
	assert.Equal(t, nil, b)

	r = NewReference("a.b/c", "d")
	b, _, _, _, err = r.Repack(envctx.Empty)
	require.NoError(t, err)
	assert.Equal(t, "a.b/c:d", b)

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


示例16: TestStringMarshalJSON

func TestStringMarshalJSON(t *testing.T) {

	var s *String

	ba, _, _, _, err := s.Repack(envctx.Empty)
	require.NoError(t, err)
	assert.Equal(t, nil, ba)

	s = NewString(`foo "bar"`)
	ba, _, _, _, err = s.Repack(envctx.Empty)
	require.NoError(t, err)
	assert.Equal(t, `foo "bar"`, ba)

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


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


示例18: TestNode_DeleteMapChild

func TestNode_DeleteMapChild(t *testing.T) {
	_, n := data.Setup(t)
	test := func(t *testing.T, n *node.Node, m *data.Multi) {
		require.NoError(t, n.Map["mjs"].DeleteMapChild("a"))
		assert.Equal(t, 1, len(n.Map["mjs"].Map))
		assert.Equal(t, 1, len(m.Mjs))
		require.NoError(t, n.Map["mjs"].DeleteMapChild("b"))
		assert.Equal(t, 0, len(n.Map["mjs"].Map))
		assert.Equal(t, 0, len(m.Mjs))
		require.NoError(t, n.Map["mm"].DeleteMapChild("b"))
		assert.Equal(t, 1, len(n.Map["mm"].Map))
		assert.Equal(t, 1, len(m.Mm))
	}
	data.Run(t, n, n.Value.(*data.Multi), test)
}
开发者ID:kego,项目名称:ke,代码行数:15,代码来源:node_ext_test.go


示例19: testUnpack

func testUnpack(t *testing.T, path string) {
	ctx, _, err := process.Initialise(context.Background(), &process.Options{
		Path: path,
	})
	require.NoError(t, err)

	env := envctx.FromContext(ctx)

	files := scanner.ScanDirToFiles(ctx, env.Dir, env.Recursive)
	bytes := scanner.ScanFilesToBytes(ctx, files)
	for b := range bytes {
		_, err := node.Unmarshal(ctx, b.Bytes)
		require.NoError(t, err, b.File)
	}
}
开发者ID:kego,项目名称:ke,代码行数:15,代码来源:unpack_ext_test.go


示例20: TestNode_DisplayType

func TestNode_DisplayType(t *testing.T) {
	cb, n := data.Setup(t)

	dt, err := n.DisplayType(cb.Ctx())
	require.NoError(t, err)
	assert.Equal(t, "multi", dt)

	dt, err = n.Map["ai"].DisplayType(cb.Ctx())
	require.NoError(t, err)
	assert.Equal(t, "null", dt)

	dt, err = n.Map["ajs"].DisplayType(cb.Ctx())
	require.NoError(t, err)
	assert.Equal(t, "[]json:string", dt)
}
开发者ID:kego,项目名称:ke,代码行数:15,代码来源:node_ext_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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