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


Golang assert.NotNil函数代码示例

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


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

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

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

示例3: TestData

func TestData(t *testing.T) {

	c := new(WebContext)

	c.data = nil

	assert.NotNil(t, c.Data())
	assert.NotNil(t, c.data)

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

示例4: TestDoubleMountFails

func TestDoubleMountFails(t *testing.T) {
	var m = NewMemory()
	m.Mounts = []Mount{}

	first := new(MockDevice)
	second := new(MockDevice)

	assert.Nil(t, m.Mount(first, 0x0500, 0x0fff))
	assert.NotNil(t, m.Mount(second, 0x0400, 0x600))
	assert.NotNil(t, m.Mount(second, 0x0f00, 0x1000))
	assert.NotNil(t, m.Mount(second, 0x0501, 0x0f00))
}
开发者ID:samfoo,项目名称:gones,代码行数:12,代码来源:memory_test.go

示例5: TestStoredProcedureNotExists

func TestStoredProcedureNotExists(t *testing.T) {
	conn := ConnectToTestDb(t)
	err := createProcedure(conn, "test_sp_not_exists", `as return`)
	assert.Nil(t, err)
	rst, err := conn.ExecSp("test_sp_not_exists")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	_, err = conn.Exec("drop procedure test_sp_not_exists")
	assert.Nil(t, err)
	rst, err = conn.ExecSp("test_sp_not_exists")
	assert.NotNil(t, err)
	assert.Nil(t, rst)
}
开发者ID:upstartmobile,项目名称:gofreetds,代码行数:13,代码来源:conn_sp_test.go

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

示例7: Test_ParseURL_BadValue

func Test_ParseURL_BadValue(t *testing.T) {
	expected := ""
	test_string := `www.venuecom.com?beef=stew&whee=phew%C3%BC`
	parsed, err := ParseURL(test_string)
	assert.NotNil(t, err, fmt.Sprintf("unexpected nil error from ParseURL on parsed item \"%s\"", test_string))
	assert.Equal(t, parsed, expected, fmt.Sprintf("parsed item \"%s\" did not match expected \"%s\"", parsed, expected))
}
开发者ID:ThatRubenAguilar,项目名称:go-sitemaps,代码行数:7,代码来源:sitemapparsing_test.go

示例8: Test_BuildState_BuildTargets_one_failure

// full build (all targets), one action fails
func Test_BuildState_BuildTargets_one_failure(t *testing.T) {
	sig := []byte{0}
	graph, executed := setupBuild(false, sig)
	db := makeFakeDB(graph, sig)

	// fail to build misc.{c,h} -> misc.o: that will stop the build
	rule := graph.Lookup("misc.o").BuildRule().(*dag.StubRule)
	rule.SetFail(true)

	expect := []buildexpect{
		{"tool1.o", dag.BUILT},
		{"misc.o", dag.FAILED},
	}

	opts := BuildOptions{}
	bstate := NewBuildState(graph, db, opts)
	goal := graph.MakeNodeSet("tool1", "tool2")
	err := bstate.BuildTargets(goal)
	assert.NotNil(t, err)
	assertBuild(t, graph, expect, *executed)

	// we didn't even think about building util.o, tool1, etc: an
	// earlier node failed and the build terminates on first failure
	assert.Equal(t, dag.UNKNOWN, graph.Lookup("util.o").State())
	assert.Equal(t, dag.UNKNOWN, graph.Lookup("tool1").State())
	assert.Equal(t, dag.UNKNOWN, graph.Lookup("tool2").State())
}
开发者ID:sbinet,项目名称:fubsy,代码行数:28,代码来源:build_test.go

示例9: Test_SitemapPageSizeLimitations

func Test_SitemapPageSizeLimitations(t *testing.T) {
	buf := make([]byte, max_sitemap_page_size+1)

	reader := bytes.NewBuffer(buf)
	_, err := NewSitemapPage(reader)
	assert.NotNil(t, err, fmt.Sprintf("expected error from NewSitemapPage"))
}
开发者ID:ThatRubenAguilar,项目名称:go-sitemaps,代码行数:7,代码来源:sitemap_test.go

示例10: TestNewDateTypesParam

func TestNewDateTypesParam(t *testing.T) {
	conn := ConnectToTestDb(t)
	err := createProcedure(conn, "test_sp_with_datetimeoffset_param", `
    (@p1 datetimeoffset, @p2 date, @p3 time, @p4 datetime2) as
    DECLARE @datetime datetime = @p1;
    SELECT @datetime, @p1, @p2, @p3, @p4
    return `)
	assert.Nil(t, err)
	p1 := "2025-12-10 12:32:10.1237000 +01:00"
	p2 := "2025-12-10"
	p3 := "12:30"
	p4 := "2025-12-10 12:32:10"
	rst, err := conn.ExecSp("test_sp_with_datetimeoffset_param", p1, p2, p3, p4)
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	rst.Next()
	var op1, op2, op3, op4 string
	var dt time.Time
	err = rst.Scan(&dt, &op1, &op2, &op3, &op4)
	assert.Nil(t, err)
	assert.Equal(t, "2025-12-10T12:32:10+01:00", dt.Format(time.RFC3339))
	assert.Equal(t, "2025-12-10 12:32:10.1237000 +01:00", op1)
	assert.Equal(t, "2025-12-10", op2)
	assert.Equal(t, "12:30:00.0000000", op3)
	assert.Equal(t, "2025-12-10 12:32:10.0000000", op4)
}
开发者ID:upstartmobile,项目名称:gofreetds,代码行数:26,代码来源:conn_sp_test.go

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

示例12: Test_BuildState_BuildTargets_one_failure_keep_going

// full build (all targets), one action fails, --keep-going true
func Test_BuildState_BuildTargets_one_failure_keep_going(t *testing.T) {
	// this is the same as the previous test except that
	// opts.KeepGoing == true: we don't terminate the build on first
	// failure, but carry on and consider building tool1, then mark it
	// TAINTED because one of its ancestors (misc.o) failed to build

	sig := []byte{0}
	graph, executed := setupBuild(false, sig)
	db := makeFakeDB(graph, sig)

	rule := graph.Lookup("misc.o").BuildRule().(*dag.StubRule)
	rule.SetFail(true)

	expect := []buildexpect{
		{"tool1.o", dag.BUILT},
		{"misc.o", dag.FAILED},
		{"util.o", dag.BUILT},
		{"tool2.o", dag.BUILT},
		{"tool2", dag.BUILT},
	}

	opts := BuildOptions{KeepGoing: true}
	bstate := NewBuildState(graph, db, opts)
	goal := graph.MakeNodeSet("tool1", "tool2")
	err := bstate.BuildTargets(goal)
	assert.NotNil(t, err)
	assertBuild(t, graph, expect, *executed)

	assert.Equal(t, dag.TAINTED, graph.Lookup("tool1").State())
}
开发者ID:sbinet,项目名称:fubsy,代码行数:31,代码来源:build_test.go

示例13: Test_Runtime_runMainPhase_valid

func Test_Runtime_runMainPhase_valid(t *testing.T) {
	script := "" +
		"main {\n" +
		"  src = \"foo.c\"\n" +
		"  \"foo\": src {\n" +
		"    \"cc -o $TARGET $src\"\n" +
		"  }\n" +
		"}\n"
	rt := parseScript(t, "test.fubsy", script)
	errors := rt.runMainPhase()
	assert.Equal(t, 0, len(errors))
	val, ok := rt.stack.Lookup("src")
	assert.True(t, ok)
	assert.Equal(t, types.MakeFuString("foo.c"), val)
	assert.NotNil(t, rt.dag)

	// this seems *awfully* detailed and brittle, but DAG doesn't
	// provide a good way to query what's in it (yet...)
	expect := `0000: FileNode "foo" (state UNKNOWN)
  action: "cc -o $TARGET $src"
  parents:
    0001: foo.c
0001: FileNode "foo.c" (state UNKNOWN)
`
	var buf bytes.Buffer
	rt.dag.Dump(&buf, "")
	actual := buf.String()
	if expect != actual {
		t.Errorf("dag.Dump(): expected\n%v\nbut got\n%v", expect, actual)
	}
}
开发者ID:sbinet,项目名称:fubsy,代码行数:31,代码来源:runtime_test.go

示例14: Test_parseChangeFrequency_BadValue

func Test_parseChangeFrequency_BadValue(t *testing.T) {
	expected := ""
	test_string := `asdf`
	parsed, err := parseChangeFrequency(test_string)
	assert.NotNil(t, err, fmt.Sprintf("unexpected nil error from parseChangeFrequency on parsed item \"%s\"", test_string))
	assert.Equal(t, parsed, expected, fmt.Sprintf("parsed item \"%s\" did not match expected \"%s\"", parsed, expected))
}
开发者ID:ThatRubenAguilar,项目名称:go-sitemaps,代码行数:7,代码来源:sitemapparsing_test.go

示例15: TestExecSp

func TestExecSp(t *testing.T) {
	conn := ConnectToTestDb(t)
	rst, err := conn.ExecSp("sp_who")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.Equal(t, 1, len(rst.results))
}
开发者ID:upstartmobile,项目名称:gofreetds,代码行数:7,代码来源:conn_sp_test.go


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