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


Golang assert.Nil函数代码示例

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


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

示例1: Test_FinderNode_Add_CommandString

// hmmmm: interface-wise, this tests that FinderNode.Add() returns an
// object whose CommandString() behaves sensibly... but in
// implementation terms, it's really a test of FuList.CommandString()
func Test_FinderNode_Add_CommandString(t *testing.T) {
	finder1 := NewFinderNode("*.c", "*.h")
	finder2 := NewFinderNode("doc/???.txt")
	finder3 := NewFinderNode()

	sum1, err := finder1.Add(finder2)
	assert.Nil(t, err)
	assert.Equal(t, "'*.c' '*.h' 'doc/???.txt'", sum1.CommandString())

	sum2, err := finder3.Add(sum1)
	assert.Nil(t, err)
	assert.Equal(t, "'*.c' '*.h' 'doc/???.txt'", sum2.CommandString())

	assert.False(t, sum1.Equal(sum2))

	sum2b, err := finder3.Add(sum1)
	assert.Nil(t, err)
	assert.True(t, sum2.Equal(sum2b),
		"expected equal ListNodes:\nsum2  = %T %v\nsum2b = %T %v",
		sum2, sum2, sum2b, sum2b)

	// This is a silly thing to do, and perhaps we should filter out
	// the duplicate patterns... but I don't think so. If the user
	// constructs something silly, we do something silly.
	sum3, err := sum1.Add(sum2)
	assert.Nil(t, err)
	assert.Equal(t,
		"'*.c' '*.h' 'doc/???.txt' '*.c' '*.h' 'doc/???.txt'",
		sum3.CommandString())
}
开发者ID:sbinet,项目名称:fubsy,代码行数:33,代码来源:findernode_test.go

示例2: Test_FuFunction_CheckArgs_minmax

func Test_FuFunction_CheckArgs_minmax(t *testing.T) {
	fn := NewVariadicFunction("bar", 2, 4, nil)
	val := MakeFuString("a")
	args := MakeBasicArgs(nil, []FuObject{val}, nil)
	err := fn.CheckArgs(args)
	assert.Equal(t,
		"function bar() requires at least 2 arguments (got 1)", err.Error())

	// 2 args are good
	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Nil(t, err)

	// 3 args are good
	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Nil(t, err)

	// 4 args are good
	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Nil(t, err)

	// but 5 args is *right out*
	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Equal(t,
		"function bar() takes at most 4 arguments (got 5)", err.Error())
}
开发者ID:sbinet,项目名称:fubsy,代码行数:29,代码来源:callables_test.go

示例3: Test_BuildState_BuildTargets_rebuild

// full successful build, then try some incremental rebuilds
func Test_BuildState_BuildTargets_rebuild(t *testing.T) {
	sig := []byte{0}
	db, goal, opts := fullBuild(t, sig)

	// now the rebuild, after marking all nodes unchanged
	graph, executed := setupBuild(true, sig)

	expect := []buildexpect{}
	bstate := NewBuildState(graph, db, opts)
	err := bstate.BuildTargets(goal)
	assert.Nil(t, err)
	assertBuild(t, graph, expect, *executed)

	// again, but this time change one source file (misc.h, forcing
	// rebuilds of misc.o and tool1.o -- but those two will appear
	// unchanged, so we short-circuit the build and do *not* rebuild
	// tool1)
	graph, executed = setupBuild(true, sig)
	graph.Lookup("misc.h").(*dag.StubNode).SetSignature([]byte{1})

	expect = []buildexpect{
		{"tool1.o", dag.BUILT},
		{"misc.o", dag.BUILT},
	}
	bstate = NewBuildState(graph, db, opts)
	err = bstate.BuildTargets(goal)
	assert.Nil(t, err)
	assertBuild(t, graph, expect, *executed)
}
开发者ID:sbinet,项目名称:fubsy,代码行数:30,代码来源:build_test.go

示例4: TestMirroring

func TestMirroring(t *testing.T) {
	if !IsMirrorHostDefined() {
		t.Skip("mirror host is not defined")
	}
	conn := ConnectToTestDb(t)
	if conn == nil {
		return
	}
	defer conn.Close()

	rst, err := conn.Exec("select * from authors")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.Equal(t, 1, len(rst))
	assert.Equal(t, 23, len(rst[0].Rows))
	assert.Equal(t, 23, rst[0].RowsAffected)

	err = failover(conn)
	if err != nil {
		fmt.Printf("failover error %s %s %s\n", err, conn.Error, conn.Message)
		assert.Nil(t, err)
	}
	rst, err = conn.Exec("select * from authors")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.Equal(t, 1, len(rst))
	assert.Equal(t, 23, len(rst[0].Rows))
	assert.Equal(t, 23, rst[0].RowsAffected)
}
开发者ID:upstartmobile,项目名称:gofreetds,代码行数:29,代码来源:conn_test.go

示例5: Test_FuFunction_CheckArgs_fixed

func Test_FuFunction_CheckArgs_fixed(t *testing.T) {
	val := MakeFuString("a")
	args := MakeBasicArgs(nil, []FuObject{}, nil)
	fn := NewFixedFunction("meep", 0, nil)

	err := fn.CheckArgs(args)
	assert.Nil(t, err)

	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Equal(t,
		"function meep() takes no arguments (got 1)", err.Error())

	fn = NewFixedFunction("foo", 2, nil)
	args.args = args.args[:0]
	err = fn.CheckArgs(args)
	assert.Equal(t,
		"function foo() takes exactly 2 arguments (got 0)", err.Error())

	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Equal(t,
		"function foo() takes exactly 2 arguments (got 1)", err.Error())

	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Nil(t, err)

	args.args = append(args.args, val)
	err = fn.CheckArgs(args)
	assert.Equal(t,
		"function foo() takes exactly 2 arguments (got 3)", err.Error())
}
开发者ID:sbinet,项目名称:fubsy,代码行数:33,代码来源:callables_test.go

示例6: TestExecute

func TestExecute(t *testing.T) {
	conn := ConnectToTestDb(t)
	if conn == nil {
		return
	}
	defer conn.Close()

	rst, err := conn.Exec("select 1")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.Equal(t, 1, len(rst))
	rst, err = conn.Exec("select missing")
	assert.NotNil(t, err)
	assert.Nil(t, rst)
	rst, err = conn.Exec("print 'pero'")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.True(t, strings.Contains(conn.Message, "pero"))
	assert.Equal(t, 1, len(rst))
	assert.Equal(t, 0, len(rst[0].Rows))
	rst, err = conn.Exec("sp_help 'authors'")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.Equal(t, 9, len(rst))
}
开发者ID:upstartmobile,项目名称:gofreetds,代码行数:25,代码来源:conn_test.go

示例7: TestDuplicateKeys

func TestDuplicateKeys(t *testing.T) {
	worker, err := idworker.NewIdWorker(1, 1)
	assert.Nil(t, err)

	const MAXIDS = 100000

	var ids [MAXIDS]uint64

	start := time.Now()

	for i := 0; i < MAXIDS; i++ {
		id, err := worker.Next()
		assert.Nil(t, err)

		ids[i] = id
	}

	for i := 1; i < MAXIDS; i++ {
		if ids[i-1] > ids[i] {
			t.Errorf("next id %v is smaller then previous one %v", ids[i], ids[i-1])
		}
	}

	end := time.Now()

	delta := float64(end.UnixNano()-start.UnixNano()) / float64(1000*1000)
	t.Logf("Execution time: %fms\n", delta)
	t.Logf("Ids/sec: %f\n", float64(MAXIDS)/delta)
}
开发者ID:vonwenm,项目名称:gosnowflake-1,代码行数:29,代码来源:gosnowflake_test.go

示例8: TestPathMatchHandler

func TestPathMatchHandler(t *testing.T) {

	pathPattern, _ := paths.NewPathPattern("collection/{id}/name")
	var called bool = false
	h := NewPathMatchHandler(pathPattern, HandlerExecutionFunc(func(c context.Context) error {
		called = true
		return nil
	}))

	ctx1 := context_test.MakeTestContextWithPath("/collection/123/name")
	will, _ := h.WillHandle(ctx1)
	assert.True(t, will)
	h.Handle(ctx1)
	assert.True(t, called, "Method should be called")
	assert.Equal(t, "123", ctx1.Data().Get(context.DataKeyPathParameters).(objects.Map).Get("id"))

	ctx2 := context_test.MakeTestContextWithPath("/collection")
	will, _ = h.WillHandle(ctx2)
	assert.False(t, will)
	assert.Nil(t, ctx2.Data().Get(context.DataKeyPathParameters))

	h.BreakCurrentPipeline = true
	shouldStop, handleErr := h.Handle(ctx2)
	assert.Nil(t, handleErr)
	assert.True(t, shouldStop)
	assert.True(t, called, "Handler func should get called")

}
开发者ID:smw,项目名称:goweb,代码行数:28,代码来源:path_match_handler_test.go

示例9: TestDuplicate

func TestDuplicate(t *testing.T) {

	total := 1000 * 1000
	data := make(map[uint64]int)

	sf, err := Default()
	assert.Nil(t, err)

	var id, pre uint64
	for i := 0; i < total; i++ {

		id, err = sf.Next()
		assert.Nil(t, err)

		if id < pre {
			t.Errorf("id %v is samller than previous one %v", id, pre)
		}
		pre = id

		count := data[id]
		if count > 0 {
			t.Errorf("duplicate id %v %d", id, count)
		}
		data[id] = count + 1
	}

	length := len(data)
	t.Logf("map length %v", length)
	if length != total {
		t.Errorf("legth does not match want %v actual %d", total, length)
	}

}
开发者ID:vonwenm,项目名称:gosnow,代码行数:33,代码来源:gosnow_test.go

示例10: Test_FileNode_Add

func Test_FileNode_Add(t *testing.T) {
	node0 := NewFileNode("foo/bar")
	node1 := NewFileNode("foo/baz")
	obj0 := types.MakeFuString(".c")
	obj1 := types.MakeStringList("a", "b")

	var err error
	var expect types.FuObject
	var actual types.FuObject

	// node + node = list of nodes
	expect = types.MakeFuList(node0, node1)
	actual, err = node0.Add(node1)
	assert.Nil(t, err)
	assert.True(t, expect.Equal(actual))

	// node + string = new node
	expect = NewFileNode("foo/bar.c")
	actual, err = node0.Add(obj0)
	assert.Nil(t, err)
	assert.True(t, expect.Equal(actual))

	// node + list = flattened list
	expect = types.MakeFuList(
		node0, types.MakeFuString("a"), types.MakeFuString("b"))
	actual, err = node0.Add(obj1)
	assert.Nil(t, err)
	assert.True(t, expect.Equal(actual))
}
开发者ID:sbinet,项目名称:fubsy,代码行数:29,代码来源:fsnodes_test.go

示例11: Test_FuString_Add_strings

func Test_FuString_Add_strings(t *testing.T) {
	s1 := MakeFuString("hello")
	s2 := MakeFuString("world")
	var result FuObject
	var err error

	// s1 + s1
	result, err = s1.Add(s1)
	assert.Nil(t, err)
	assert.Equal(t, "hellohello", result.(FuString).value)

	// s1 + s2
	result, err = s1.Add(s2)
	assert.Nil(t, err)
	assert.Equal(t, "helloworld", result.(FuString).value)

	// s1 + s2 + s1 + s2
	// (equivalent to ((s1.Add(s2)).Add(s1)).Add(s2), except we have
	// to worry about error handling)
	result, err = s1.Add(s2)
	assert.Nil(t, err)
	result, err = result.Add(s1)
	assert.Nil(t, err)
	result, err = result.Add(s2)
	assert.Nil(t, err)
	assert.Equal(t, "helloworldhelloworld", result.(FuString).value)

	// neither s1 nor s2 is affected by all this adding
	assert.Equal(t, "hello", s1.value)
	assert.Equal(t, "world", s2.value)
}
开发者ID:sbinet,项目名称:fubsy,代码行数:31,代码来源:basictypes_test.go

示例12: Test_FuString_ActionExpand

func Test_FuString_ActionExpand(t *testing.T) {
	ns := makeNamespace("foo", "hello", "meep", "blorf")
	input := MakeFuString("meep meep!")
	output, err := input.ActionExpand(ns, nil)
	assert.Nil(t, err)
	assert.Equal(t, input, output)

	input = MakeFuString("meep $foo blah")
	output, err = input.ActionExpand(ns, nil)
	assert.Nil(t, err)
	assert.Equal(t, "meep hello blah", output.ValueString())

	input = MakeFuString("hello ${foo} $meep")
	output, err = input.ActionExpand(ns, nil)
	assert.Nil(t, err)
	assert.Equal(t, "hello hello blorf", output.ValueString())

	ns.Assign("foo", nil)
	output, err = input.ActionExpand(ns, nil)
	assert.Nil(t, err)
	assert.Equal(t, "hello  blorf", output.ValueString())

	ns.Assign("foo", MakeFuString("ping$pong"))
	output, err = input.ActionExpand(ns, nil)
	assert.Equal(t, "undefined variable 'pong' in string", err.Error())
	assert.Nil(t, output)
}
开发者ID:sbinet,项目名称:fubsy,代码行数:27,代码来源:basictypes_test.go

示例13: TestTimeSpParams

func TestTimeSpParams(t *testing.T) {
	conn := ConnectToTestDb(t)
	err := createProcedure(conn, "test_sp_time_sp_params", `@p1 datetime as
    insert into tm (tm) values(@p1)
    select @p1, 123
    return 0`)
	assert.Nil(t, err)

	f := func(tmIn time.Time) {
		var tmOut time.Time
		var i int
		rst, err := conn.ExecSp("test_sp_time_sp_params", tmIn)
		assert.Nil(t, err)
		assert.NotNil(t, rst)
		rst.Next()
		rst.Scan(&tmOut, &i)
		assert.Equal(t, tmIn.UTC(), tmOut.UTC())
		if !tmIn.Equal(tmOut) {
			t.Errorf("%s != %s", tmIn, tmOut)
		}
	}

	f(time.Unix(1404856799, 0))
	f(time.Unix(1404856800, 0))
	f(time.Unix(1404856801, 0))

	f(time.Unix(1404856799, 0).UTC())
	f(time.Unix(1404856800, 0).UTC())
	f(time.Unix(1404856801, 0).UTC())
}
开发者ID:upstartmobile,项目名称:gofreetds,代码行数:30,代码来源:conn_sp_test.go

示例14: TestGoSqlDbQuery

func TestGoSqlDbQuery(t *testing.T) {
	db, err := open()
	assert.Nil(t, err)
	rows, err := db.Query("SELECT au_fname, au_lname name FROM authors WHERE au_lname = ? order by au_id", "Ringer")
	assert.Nil(t, err)
	testRingers(t, rows)
}
开发者ID:upstartmobile,项目名称:gofreetds,代码行数:7,代码来源:mssql_test.go

示例15: TestExecSpInputParams2

func TestExecSpInputParams2(t *testing.T) {
	conn := ConnectToTestDb(t)
	err := createProcedure(conn, "test_input_params2", "@p1 nvarchar(255), @p2 varchar(255), @p3 nvarchar(255), @p4 nchar(10), @p5 varbinary(10) as select @p1, @p2, @p3, @p4, @p5;  return")
	assert.Nil(t, err)
	want := "£¢§‹›†€"
	wantp2 := "abc"
	wantp3 := "šđčćžabc"
	wantp4 := "šđčćžabcde"
	wantp3 = "FK Ventspils v Nõmme Kalju FC"
	wantp5 := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
	rst, err := conn.ExecSp("test_input_params2", want, wantp2, wantp3, wantp4, wantp5)
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	if rst == nil {
		return
	}
	assert.True(t, rst.HasResults())
	var got, gotp2, gotp3, gotp4 string
	var gotp5 []byte
	result := rst.results[0]
	result.Next()
	result.Scan(&got, &gotp2, &gotp3, &gotp4, &gotp5)
	assert.Equal(t, want, got)
	assert.Equal(t, wantp2, gotp2)
	assert.Equal(t, wantp3, gotp3)
	assert.Equal(t, wantp4, gotp4)
	assert.Equal(t, wantp5, gotp5)
	//PrintResults(rst.Results)
}
开发者ID:upstartmobile,项目名称:gofreetds,代码行数:29,代码来源:conn_sp_test.go


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