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


Golang require.NoError函数代码示例

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


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


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