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


Golang assrt.NewAssert函数代码示例

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


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

示例1: doTestQueryMap

func doTestQueryMap(t *testing.T, mg *Migration, q *Qbs) {
	defer closeMigrationAndQbs(mg, q)
	assert := assrt.NewAssert(t)
	type types struct {
		Id      int64
		Name    string `qbs:"size:64"`
		Created time.Time
	}
	tp := new(types)
	mg.dropTableIfExists(tp)
	mg.CreateTableIfNotExists(tp)
	result, err := q.QueryMap("SELECT * FROM types")
	assert.Nil(result)
	assert.Equal(sql.ErrNoRows, err)
	for i := 0; i < 3; i++ {
		tp.Id = 0
		tp.Name = "abc"
		q.Save(tp)
	}
	result, err = q.QueryMap("SELECT * FROM types")
	assert.NotNil(result)
	assert.Equal(1, result["id"])
	assert.Equal("abc", result["name"])
	if _, sql3 := q.Dialect.(*sqlite3); !sql3 {
		_, ok := result["created"].(time.Time)
		assert.True(ok)
	} else {
		_, ok := result["created"].(string)
		assert.True(ok)
	}
	results, err := q.QueryMapSlice("SELECT * FROM types")
	assert.Equal(3, len(results))
}
开发者ID:robfig,项目名称:qbs,代码行数:33,代码来源:testutil_db.go

示例2: TestInterfaceToModel

func TestInterfaceToModel(t *testing.T) {
	assert := assrt.NewAssert(t)
	now := time.Now()
	table1 := &indexedTable{
		ColPrimary: 6,
		ColVarChar: "orange",
		ColTime:    now,
	}
	m := structPtrToModel(table1, true)
	assert.Equal("col_primary", m.Pk.Name)
	assert.Equal(4, len(m.Fields))
	assert.Equal(2, len(m.Indexes))
	assert.Equal("col_primary_col_time", m.Indexes[0].Name)
	assert.True(!m.Indexes[0].Unique)
	assert.Equal("col_var_char_col_time", m.Indexes[1].Name)
	assert.True(m.Indexes[1].Unique)

	f := m.Fields[0]
	id, _ := f.Value.(Id)
	assert.Equal(6, id)
	assert.True(f.PrimaryKey())

	f = m.Fields[1]
	assert.Equal("'banana'", f.Default())

	f = m.Fields[2]
	str, _ := f.Value.(string)
	assert.Equal("orange", str)
	assert.Equal(64, f.Size())

	f = m.Fields[3]
	tm, _ := f.Value.(time.Time)
	assert.Equal(now, tm)
}
开发者ID:cgolang,项目名称:qbs,代码行数:34,代码来源:model_test.go

示例3: TestGrep

func TestGrep(t *testing.T) {
	assert := assrt.NewAssert(t)

	cmd := exec.Command("grep", "--color=auto", "bar")
	host := siphon.NewHost(cmd, siphon.NewInternalAddr())
	host.Start()

	go func() {
		stdin := host.StdinPipe()
		stdin.Write([]byte("foo\nbar\nbaz\n"))
		stdin.Write([]byte{4}) // EOT
	}()

	outBuffer := new(bytes.Buffer)
	io.Copy(outBuffer, host.StdoutPipe())
	out := string(outBuffer.Bytes())

	expected := // I have no idea where the CR characters come from.
		"foo\r\n" +
			"bar\r\n" +
			"baz\r\n" +
			"[01;31m[Kbar[m[K\r\n"

	assert.Equal(
		expected,
		out,
	)
}
开发者ID:nk23x,项目名称:siphon-cli,代码行数:28,代码来源:siphon_test.go

示例4: doTestCreateIndexSQL

func doTestCreateIndexSQL(t *testing.T, info dialectSyntax) {
	assert := assrt.NewAssert(t)
	sql := info.dialect.createIndexSql("iname", "itable", true, "a", "b", "c")
	assert.Equal(info.createUniqueIndexSql, sql)
	sql = info.dialect.createIndexSql("iname2", "itable2", false, "d", "e")
	assert.Equal(info.createIndexSql, sql)
}
开发者ID:hyl87,项目名称:qbs,代码行数:7,代码来源:testutil_syntax.go

示例5: TestGoshDoesNotReportSigStopOrContinueAsExit

func TestGoshDoesNotReportSigStopOrContinueAsExit(t *testing.T) {
	assert := assrt.NewAssert(t)

	cmdr := NewRunningCommand(
		exec.Command("bash", "-c", "sleep 1; exit 4;"),
	)
	cmdr.Start()
	NewRunningCommand(exec.Command("kill", "-SIGSTOP", Itoa(cmdr.Pid()))).Start().Wait()

	// the command shouldn't be able to return while stopped, regardless of how short the sleep call is.
	assert.Equal(
		false,
		cmdr.WaitSoon(1500*time.Millisecond),
	)

	NewRunningCommand(exec.Command("kill", "-SIGCONT", Itoa(cmdr.Pid()))).Start().Wait()

	assert.Equal(
		4,
		cmdr.GetExitCode(),
	)
	assert.Equal(
		nil,
		cmdr.err,
	)
	assert.Equal(
		FINISHED,
		cmdr.State(),
	)
}
开发者ID:heavenlyhash,项目名称:pogo,代码行数:30,代码来源:command_test.go

示例6: TestPtySanity

/**
Expect:
 - all of the input to come back out, because terminals default to echo mode.
 - then the grep'd string should come out, because the command recieved it and matched.
 - the grep'd string should come out surrounded by the escape codes for color, since grep's auto mode should detect that we're in a terminal.
*/
func TestPtySanity(t *testing.T) {
	assert := assrt.NewAssert(t)

	c := exec.Command("grep", "--color=auto", "bar")
	f, err := pty.Start(c)
	if err != nil {
		t.Fatal(err)
	}

	go func() {
		f.Write([]byte("foo\nbar\nbaz\n"))
		/*
			All of the input must be written in a single call to prevent this test from occationally failing nondeterministically, because:
			grep operates stream-wise and will start printing output before it has all of its input,
			and 3/4ths of the output lines are actually from the terminal operating in echo mode on the same channel.
			So there's actually a race between the terminal itself (somewhere down in kernel land I suppose?) and the output of grep.
		*/
		f.Write([]byte{4}) // EOT
	}()

	outBuffer := new(bytes.Buffer)
	io.Copy(outBuffer, f)
	out := string(outBuffer.Bytes())

	expected := // I have no idea where the CR characters come from.
		"foo\r\n" +
			"bar\r\n" +
			"baz\r\n" +
			"[01;31m[Kbar[m[K\r\n"

	assert.Equal(
		expected,
		out,
	)
}
开发者ID:nk23x,项目名称:siphon-cli,代码行数:41,代码来源:siphon_test.go

示例7: Template

func Template(t *testing.T) {
	assert := assrt.NewAssert(t)
	assert.Equal(
		"yes",
		"no",
	)
}
开发者ID:nk23x,项目名称:siphon-cli,代码行数:7,代码来源:siphon_test.go

示例8: TestIntegration_ShStreamingInputAndOutputWithStringChan

func TestIntegration_ShStreamingInputAndOutputWithStringChan(t *testing.T) {
	assert := assrt.NewAssert(t)

	msg1 := "bees\n"
	msg2 := "knees\n"
	in := make(chan string, 1)
	out := make(chan string, 1)
	catCmd := Sh("cat")("-")(Opts{In: in, Out: out}).Start()

	in <- msg1
	assert.Equal(
		msg1,
		<-out,
	)
	in <- msg2
	assert.Equal(
		msg2,
		<-out,
	)
	close(in)
	assert.Equal(
		0,
		catCmd.GetExitCode(),
	)
}
开发者ID:heavenlyhash,项目名称:pogo,代码行数:25,代码来源:integration_test.go

示例9: doTestTransaction

func doTestTransaction(t *testing.T, mg *Migration, q *Qbs) {
	defer closeMigrationAndQbs(mg, q)
	assert := assrt.NewAssert(t)
	type txModel struct {
		Id int64
		A  string
	}
	table := txModel{
		A: "A",
	}
	mg.dropTableIfExists(&table)
	mg.CreateTableIfNotExists(&table)
	q.Begin()
	assert.NotNil(q.Tx)
	_, err := q.Save(&table)
	assert.Nil(err)
	err = q.Rollback()
	assert.Nil(err)
	out := new(txModel)
	err = q.Find(out)
	assert.Equal(sql.ErrNoRows, err)
	q.Begin()
	table.Id = 0
	_, err = q.Save(&table)
	assert.Nil(err)
	err = q.Commit()
	assert.Nil(err)
	out.Id = table.Id
	err = q.Find(out)
	assert.Nil(err)
	assert.Equal("A", out.A)
}
开发者ID:hyl87,项目名称:qbs,代码行数:32,代码来源:testutil_db.go

示例10: TestInterfaceToModel

func TestInterfaceToModel(t *testing.T) {
	assert := assrt.NewAssert(t)
	now := time.Now()
	table1 := &indexedTable{
		ColPrimary: 6,
		ColVarChar: "orange",
		ColTime:    now,
	}
	m := structPtrToModel(table1, true, nil)
	assert.Equal("col_primary", m.pk.name)
	assert.Equal(4, len(m.fields))
	assert.Equal(2, len(m.indexes))
	assert.Equal("col_primary_col_time", m.indexes[0].name)
	assert.True(!m.indexes[0].unique)
	assert.Equal("col_var_char_col_time", m.indexes[1].name)
	assert.True(m.indexes[1].unique)

	f := m.fields[0]
	assert.Equal(6, f.value)
	assert.True(f.pk)

	f = m.fields[1]
	assert.Equal("'banana'", f.dfault())

	f = m.fields[2]
	str, _ := f.value.(string)
	assert.Equal("orange", str)
	assert.Equal(64, f.size())

	f = m.fields[3]
	tm, _ := f.value.(time.Time)
	assert.Equal(now, tm)
}
开发者ID:sywxf,项目名称:qbs,代码行数:33,代码来源:model_test.go

示例11: TestPublishNewOrphanLineage

func TestPublishNewOrphanLineage(t *testing.T) {
	do(func() {
		assert := assrt.NewAssert(t)

		g := NewGraph(".")
		lineage := "line"
		ancestor := ""

		g.Publish(
			lineage,
			ancestor,
			&GraphStoreRequest_Tar{
				Tarstream: fsSetA(),
			},
		)

		assert.Equal(
			3,
			strings.Count(
				g.cmd("ls-tree", git_branch_ref_prefix+hroot_image_ref_prefix+lineage).Output(),
				"\n",
			),
		)

		assert.Equal(
			`{"Name":"a","Type":"F","Mode":644,"ModTime":"1970-01-12T13:48:20Z"}`+"\n"+
				`{"Name":"b","Type":"F","Mode":640}`+"\n",
			g.cmd("show", git_branch_ref_prefix+hroot_image_ref_prefix+lineage+":"+".guitar").Output(),
		)
	})
}
开发者ID:polydawn,项目名称:hroot,代码行数:31,代码来源:graph_integration_test.go

示例12: doTestUpdate

func doTestUpdate(t *testing.T, mg *Migration, q *Qbs) {
	defer closeMigrationAndQbs(mg, q)
	assert := assrt.NewAssert(t)
	mg.dropTableIfExists(&basic{})
	mg.CreateTableIfNotExists(&basic{})
	_, err := q.Save(&basic{Name: "a", State: 1})
	_, err = q.Save(&basic{Name: "b", State: 1})
	_, err = q.Save(&basic{Name: "c", State: 0})
	assert.MustNil(err)
	{
		// define a temporary struct in a block to update partial columns of a table
		// as the type is in a block, so it will not conflict with other types with the same name in the same method
		type basic struct {
			Name string
		}
		affected, err := q.WhereEqual("state", 1).Update(&basic{Name: "d"})
		assert.MustNil(err)
		assert.Equal(2, affected)

		var datas []*basic
		q.WhereEqual("state", 1).FindAll(&datas)
		assert.MustEqual(2, len(datas))
		assert.Equal("d", datas[0].Name)
		assert.Equal("d", datas[1].Name)
	}

	// if choose basic table type to update, all zero value in the struct will be updated too.
	// this may be cause problems, so define a temporary struct to update table is the recommended way.
	affected, err := q.Where("state = ?", 1).Update(&basic{Name: "e"})
	assert.MustNil(err)
	assert.Equal(2, affected)
	var datas []*basic
	q.WhereEqual("state", 1).FindAll(&datas)
	assert.MustEqual(0, len(datas))
}
开发者ID:robfig,项目名称:qbs,代码行数:35,代码来源:testutil_db.go

示例13: TestExtract

func TestExtract(t *testing.T) {
	setUpOnce.Do(setUp)
	defer tearDownOnce.Do(tearDown)
	assert = assrt.NewAssert(t)
	c := NewClient("")

	mockRequest(200, "response")
	response, err := c.ExtractOne("http://www.theonion.com/articles/fasttalking-computer-hacker-just-has-to-break-thro,32000/", Options{})
	assert.MustNil(err)
	assert.Equal("Fast-Talking Computer Hacker Just Has To Break Through Encryption Shield Before Uploading Nano-Virus", response.Title)
	assert.Equal(TypeHTML, response.Type)

	mockRequest(200, "giphy")
	response, err = c.ExtractOne("http://giphy.com/gifs/XYyT3ZRNzaflK", Options{})
	assert.MustNil(err)
	assert.Equal("Jim Carrey Animated GIF", response.Title)
	assert.Equal(TypeHTML, response.Type)

	mockRequest(200, "responses5")
	urls := []string{
		"http://google.com",
		"http://yahoo.com",
		"http://bing.com",
		"http://cnn.com",
		"http://bbc.com",
	}
	links, err := c.Extract(urls, Options{})
	assert.MustNil(err)
	assert.Equal(5, len(links))

	mockRequest(200, "responses10")
	urls = []string{
		"http://google.com",
		"http://yahoo.com",
		"http://bing.com",
		"http://cnn.com",
		"http://bbc.com",
		"http://google.com",
		"http://yahoo.com",
		"http://bing.com",
		"http://cnn.com",
		"http://bbc.com",
		"http://google.com",
		"http://yahoo.com",
		"http://bing.com",
		"http://cnn.com",
		"http://bbc.com",
	}
	links, err = c.Extract(urls, Options{})
	assert.MustNil(err)
	assert.Equal(15, len(links))
	for i, link := range links {
		assert.True(len(link.Title) > 0, strconv.Itoa(i)+"th link with empty title")
	}

	mockRequest(500, "error_response")
	_, err = c.ExtractOne("nope", Options{})
	assert.MustNotNil(err)
}
开发者ID:mdp,项目名称:embedly,代码行数:59,代码来源:extract_test.go

示例14: TestHelloWorld

func TestHelloWorld(t *testing.T) {
	assert := assrt.NewAssert(t)
	req, _ := http.NewRequest("GET", "http://localhost/hello", nil)
	router := NewRouter(new(Hello))
	recorder := httptest.NewRecorder()
	router.ServeHTTP(recorder, req)
	assert.Equal(`{"data":"hello world","error":null}`, string(recorder.Body.Bytes()))
}
开发者ID:strogo,项目名称:jas,代码行数:8,代码来源:router_test.go

示例15: TestNewGraphInitNewDir

func TestNewGraphInitNewDir(t *testing.T) {
	do(func() {
		assertLegitGraph(
			assrt.NewAssert(t),
			NewGraph("deep"),
		)
	})
}
开发者ID:polydawn,项目名称:hroot,代码行数:8,代码来源:graph_integration_test.go


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