當前位置: 首頁>>代碼示例>>Golang>>正文


Golang assert.New函數代碼示例

本文整理匯總了Golang中gopkg/in/stretchr/testify/v1/assert.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestSelectDocRow

func TestSelectDocRow(t *testing.T) {
	assert := assert.New(t)
	type Post struct {
		ID    int
		Title string
	}

	type Person struct {
		ID    int
		Name  string
		Posts []*Post
	}

	var person Person
	err := testDB.
		SelectDoc("id", "name").
		Many("posts", `SELECT id, title FROM posts WHERE user_id = people.id`).
		From("people").
		Where("id = $1", 1).
		QueryStruct(&person)

	assert.NoError(err)
	assert.Equal("Mario", person.Name)
	assert.Equal(1, person.ID)

	assert.Equal(2, len(person.Posts))
	assert.Equal("Day 1", person.Posts[0].Title)
	assert.Equal("Day 2", person.Posts[1].Title)
}
開發者ID:syreclabs,項目名稱:dat,代碼行數:29,代碼來源:select_doc_test.go

示例2: TestParseHeaderList

func TestParseHeaderList(t *testing.T) {
	assert := assert.New(t)

	assert.Equal(
		[]string{"From", "To", "Subject"},
		ParseHeaderList("	from,to , subject"))
}
開發者ID:zoni,項目名稱:email2pushover,代碼行數:7,代碼來源:email2pushover_test.go

示例3: TestSelectDocNested

func TestSelectDocNested(t *testing.T) {
	assert := assert.New(t)

	var obj jo.Object

	posts := dat.SelectDoc("id", "title").
		Many("comments", `SELECT * FROM comments WHERE comments.id = posts.id`).
		From("posts").
		Where("user_id = people.id")

	err := testDB.
		SelectDoc("id", "name").
		Many("posts", posts).
		From("people").
		Where("id = $1", 1).
		SetIsInterpolated(true).
		QueryStruct(&obj)

	assert.NoError(err)
	assert.Equal("Mario", obj.AsString("name"))
	assert.Equal(1, obj.AsInt("id"))

	assert.Equal("A very good day", obj.AsString("posts[0].comments[0].comment"))
	assert.Equal("Yum. Apple pie.", obj.AsString("posts[1].comments[0].comment"))
}
開發者ID:syreclabs,項目名稱:dat,代碼行數:25,代碼來源:select_doc_test.go

示例4: TestCapitalize

func TestCapitalize(t *testing.T) {
	assert := assert.New(t)

	assert.Equal("Hello", Capitalize("hello"))
	assert.Equal("Hello", Capitalize("Hello"))
	assert.Equal("Hello world", Capitalize("hello world"))
	assert.Equal("Èllo", Capitalize("èllo"))
}
開發者ID:zoni,項目名稱:email2pushover,代碼行數:8,代碼來源:email2pushover_test.go

示例5: TestEmptyConfig

func TestEmptyConfig(t *testing.T) {
	a := assert.New(t)

	cfg, err := ReadConfig(strings.NewReader(""))
	require.Nil(t, err)

	a.Equal(0, len(cfg.Checks))
	a.Equal(0, len(cfg.Publishers))
}
開發者ID:zoni,項目名稱:nagios-check-runner,代碼行數:9,代碼來源:config_test.go

示例6: TestRegularConfig

func TestRegularConfig(t *testing.T) {
	a := assert.New(t)
	r := require.New(t)

	cfg, err := ReadConfig(bytes.NewReader(defaultConfig))
	r.Nil(err)

	a.Equal(5, len(cfg.Checks))
	a.Equal(1, len(cfg.Publishers))
}
開發者ID:zoni,項目名稱:nagios-check-runner,代碼行數:10,代碼來源:config_test.go

示例7: TestPublisherInit

func TestPublisherInit(t *testing.T) {
	a := assert.New(t)
	r := require.New(t)

	runner, err := NewRunnerFromFile("testdata/config.yml")
	r.Nil(err)
	r.Equal(1, len(runner.publishers))

	expectType := reflect.TypeOf(&MemoryPublisher{})
	realType := reflect.TypeOf(runner.publishers["memory"])
	a.Equal(expectType, realType)
}
開發者ID:eBayClassifiedsGroup,項目名稱:nagios-check-runner,代碼行數:12,代碼來源:runner_test.go

示例8: TestInsertMultipleRecords

func TestInsertMultipleRecords(t *testing.T) {
	assert := assert.New(t)

	s := beginTxWithFixtures()
	defer s.AutoRollback()

	res, err := s.
		InsertInto("people").
		Columns("name", "email").
		Values("apple", "[email protected]").
		Values("orange", "[email protected]").
		Values("pear", "[email protected]").
		Exec()
	assert.NoError(err)
	assert.EqualValues(res.RowsAffected, 3)

	person1 := Person{Name: "john_timr"}
	person2 := Person{Name: "jane_timr"}

	res, err = s.InsertInto("people").
		Columns("name", "email").
		Record(&person1).
		Record(&person2).
		Exec()
	assert.NoError(err)
	n := res.RowsAffected
	assert.EqualValues(n, 2)

	people := []Person{}
	err = s.
		Select("name").
		From("people").
		Where("name like $1", "%_timr").
		QueryStructs(&people)
	assert.NoError(err)
	assert.Equal(len(people), 2)

	n = 0
	for _, person := range people {
		if person.Name == "john_timr" {
			n++
		}
		if person.Name == "jane_timr" {
			n++
		}
	}
	assert.EqualValues(n, 2)
}
開發者ID:syreclabs,項目名稱:dat,代碼行數:48,代碼來源:insert_exec_test.go

示例9: TestTaskArgs

func TestTaskArgs(t *testing.T) {
	assert := assert.New(t)
	result := ""
	tasks := func(p *Project) {
		p.Task1("foo", func(c *Context) {
			name := c.Args.MustString("name")
			result = name
		})
	}

	execCLI(tasks, []string{"foo", "--", "--name=gopher"}, nil)
	assert.Equal("gopher", result)
	assert.Panics(func() {
		runTask(tasks, "foo")
	})
}
開發者ID:coreroller,項目名稱:coreroller,代碼行數:16,代碼來源:project_test.go

示例10: TestExtractHeadersFromMail

func TestExtractHeadersFromMail(t *testing.T) {
	assert := assert.New(t)

	email, err := os.Open("test.eml")
	if err != nil {
		t.Fatal(err)
	}

	expected := make(map[string]string)
	expected["From"] = "Fictious sender <[email protected]>"
	expected["To"] = "\"Fictious recipient\" <[email protected]>"
	expected["Subject"] = "Example subject"
	expected["No_such_header"] = ""

	headerlist := ParseHeaderList("from,to,subject,no_such_header")
	headers, err := extractHeadersFromMail(email, headerlist)
	assert.Nil(err)
	assert.Equal(expected, headers)
}
開發者ID:zoni,項目名稱:email2pushover,代碼行數:19,代碼來源:email2pushover_test.go

示例11: TestSelectDoc

func TestSelectDoc(t *testing.T) {
	assert := assert.New(t)

	type Person struct {
		ID    int
		Name  string
		Posts []*Post
	}

	var person Person
	err := testDB.
		SelectDoc("id", "name").
		From("people").
		Where("id = $1", 1).
		QueryStruct(&person)

	assert.NoError(err)
	assert.Equal("Mario", person.Name)
	assert.Equal(1, person.ID)
}
開發者ID:syreclabs,項目名稱:dat,代碼行數:20,代碼來源:select_doc_test.go

示例12: TestConstructMessageBody

func TestConstructMessageBody(t *testing.T) {
	assert := assert.New(t)

	headerlist := []string{"From", "To", "Subject"}

	headers := make(map[string]string)
	headers["From"] = "Fictious sender <[email protected]>"
	headers["To"] = "\"Fictious recipient\" <[email protected]>"
	headers["Subject"] = "Example subject"

	expected_body := "From: Fictious sender <[email protected]>\n" +
		"To: \"Fictious recipient\" <[email protected]>\n" +
		"Subject: Example subject"

	assert.Equal(expected_body, constructMessageBody(headers, headerlist))

	assert.Panics(func() {
		constructMessageBody(headers, []string{"Missing key"})
	})
}
開發者ID:zoni,項目名稱:email2pushover,代碼行數:20,代碼來源:email2pushover_test.go

示例13: TestSelectDocRows

func TestSelectDocRows(t *testing.T) {
	assert := assert.New(t)
	type Post struct {
		ID    int
		Title string
	}

	type Person struct {
		ID    int
		Name  string
		Posts []*Post
	}

	var people []*Person
	err := testDB.
		SelectDoc("id", "name").
		Many("posts", `SELECT id, title FROM posts WHERE user_id = people.id`).
		From("people").
		Where("id in $1", []int{1, 2}).
		SetIsInterpolated(true).
		QueryStructs(&people)

	assert.NoError(err)

	person := people[0]
	assert.Equal("Mario", person.Name)
	assert.Equal(1, person.ID)

	assert.Equal(2, len(person.Posts))
	assert.Equal("Day 1", person.Posts[0].Title)
	assert.Equal("Day 2", person.Posts[1].Title)

	person = people[1]
	assert.Equal("John", person.Name)
	assert.Equal(2, person.ID)

	assert.Equal(2, len(person.Posts))
	assert.Equal("Apple", person.Posts[0].Title)
	assert.Equal("Orange", person.Posts[1].Title)
}
開發者ID:syreclabs,項目名稱:dat,代碼行數:40,代碼來源:select_doc_test.go

示例14: TestSelectDocNil

func TestSelectDocNil(t *testing.T) {
	assert := assert.New(t)
	type Post struct {
		ID    int
		Title string
	}

	type Person struct {
		ID    int
		Name  string
		Posts []*Post
	}

	var person Person
	err := testDB.
		SelectDoc("id", "name").
		Many("posts", `SELECT id, title FROM posts WHERE user_id = people.id`).
		From("people").
		Where("id = $1", 1000).
		QueryStruct(&person)
	assert.Equal(sql.ErrNoRows, err)
}
開發者ID:syreclabs,項目名稱:dat,代碼行數:22,代碼來源:select_doc_test.go

示例15: TestSelectDocRowsNil

func TestSelectDocRowsNil(t *testing.T) {
	assert := assert.New(t)
	type Post struct {
		ID    int
		Title string
	}

	type Person struct {
		ID    int
		Name  string
		Posts []*Post
	}

	var people []*Person
	err := testDB.
		SelectDoc("id", "name").
		Many("posts", `SELECT id, title FROM posts WHERE user_id = people.id`).
		From("people").
		Where("id in $1", []int{2000, 2001}).
		SetIsInterpolated(true).
		QueryStructs(&people)
	assert.Equal(sql.ErrNoRows, err)
}
開發者ID:syreclabs,項目名稱:dat,代碼行數:23,代碼來源:select_doc_test.go


注:本文中的gopkg/in/stretchr/testify/v1/assert.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。