本文整理匯總了Golang中github.com/pgpst/pgpst/internal/gopkg/in/check/v1.C.Assert方法的典型用法代碼示例。如果您正苦於以下問題:Golang C.Assert方法的具體用法?Golang C.Assert怎麽用?Golang C.Assert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pgpst/pgpst/internal/gopkg/in/check/v1.C
的用法示例。
在下文中一共展示了C.Assert方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: BenchmarkGetStruct
func (s *RethinkSuite) BenchmarkGetStruct(c *test.C) {
// Ensure table + database exist
DBCreate("test").RunWrite(session)
DB("test").TableCreate("TestMany").RunWrite(session)
DB("test").Table("TestMany").Delete().RunWrite(session)
// Insert rows
data := []interface{}{}
for i := 0; i < 100; i++ {
data = append(data, map[string]interface{}{
"id": i,
"name": "Object 1",
"Attrs": []interface{}{map[string]interface{}{
"Name": "attr 1",
"Value": "value 1",
}},
})
}
DB("test").Table("TestMany").Insert(data).Run(session)
for i := 0; i < c.N; i++ {
n := rand.Intn(100)
// Test query
var resObj object
query := DB("test").Table("TestMany").Get(n)
res, err := query.Run(session)
c.Assert(err, test.IsNil)
err = res.One(&resObj)
c.Assert(err, test.IsNil)
}
}
示例2: TestTableChangesExitNoResults
func (s *RethinkSuite) TestTableChangesExitNoResults(c *test.C) {
DB("test").TableDrop("changes").Exec(session)
DB("test").TableCreate("changes").Exec(session)
var n int
res, err := DB("test").Table("changes").Changes().Run(session)
if err != nil {
c.Fatal(err.Error())
}
c.Assert(res.Type(), test.Equals, "Feed")
change := make(chan ChangeResponse)
// Close cursor after one second
go func() {
<-time.After(time.Second)
res.Close()
}()
// Listen for changes
res.Listen(change)
for _ = range change {
n++
}
if res.Err() == nil {
c.Fatal("No error returned, expected connection closed")
}
c.Assert(n, test.Equals, 0)
}
示例3: TestJoinInnerJoin
func (s *RethinkSuite) TestJoinInnerJoin(c *test.C) {
// Ensure table + database exist
DBCreate("test").Exec(session)
DB("test").TableCreate("Join1").Exec(session)
DB("test").TableCreate("Join2").Exec(session)
// Insert rows
DB("test").Table("Join1").Insert(joinTable1).Exec(session)
DB("test").Table("Join2").Insert(joinTable2).Exec(session)
// Test query
var response []interface{}
query := DB("test").Table("Join1").InnerJoin(DB("test").Table("Join2"), func(a, b Term) Term {
return a.Field("id").Eq(b.Field("id"))
})
res, err := query.Run(session)
c.Assert(err, test.IsNil)
err = res.All(&response)
c.Assert(response, jsonEquals, []interface{}{
map[string]interface{}{
"right": map[string]interface{}{"title": "goof", "id": 0},
"left": map[string]interface{}{"name": "bob", "id": 0},
},
map[string]interface{}{
"right": map[string]interface{}{"title": "lmoe", "id": 2},
"left": map[string]interface{}{"name": "joe", "id": 2},
},
})
}
示例4: TestSelectGetAllCompoundIndex
func (s *RethinkSuite) TestSelectGetAllCompoundIndex(c *test.C) {
// Ensure table + database exist
DBCreate("test").Exec(session)
DB("test").TableDrop("TableCompound").Exec(session)
DB("test").TableCreate("TableCompound").Exec(session)
write, err := DB("test").Table("TableCompound").IndexCreateFunc("full_name", func(row Term) interface{} {
return []interface{}{row.Field("first_name"), row.Field("last_name")}
}).RunWrite(session)
DB("test").Table("TableCompound").IndexWait().Exec(session)
c.Assert(err, test.IsNil)
c.Assert(write.Created, test.Equals, 1)
// Insert rows
DB("test").Table("TableCompound").Insert(nameList).Exec(session)
// Test query
var response interface{}
query := DB("test").Table("TableCompound").GetAllByIndex("full_name", []interface{}{"John", "Smith"})
res, err := query.Run(session)
c.Assert(err, test.IsNil)
err = res.One(&response)
c.Assert(err, test.IsNil)
c.Assert(response, jsonEquals, map[string]interface{}{"id": 1, "first_name": "John", "last_name": "Smith", "gender": "M"})
res.Close()
}
示例5: TestStringMatchFail
func (s *RethinkSuite) TestStringMatchFail(c *test.C) {
query := Expr("id:0,foo:bar").Match("name:(\\w+)")
res, err := query.Run(session)
c.Assert(err, test.IsNil)
c.Assert(res.IsNil(), test.Equals, true)
}
示例6: TestClusterRecoverAfterNoNodes
func (s *RethinkSuite) TestClusterRecoverAfterNoNodes(c *test.C) {
session, err := Connect(ConnectOpts{
Addresses: []string{url, url2},
DiscoverHosts: true,
NodeRefreshInterval: time.Second,
})
c.Assert(err, test.IsNil)
t := time.NewTimer(time.Second * 30)
hasHadZeroNodes := false
for {
select {
// Fail if deadline has passed
case <-t.C:
c.Fatal("No node was added to the cluster")
default:
// Check if there are no nodes
if len(session.cluster.GetNodes()) == 0 {
hasHadZeroNodes = true
}
// Pass if another node was added
if len(session.cluster.GetNodes()) >= 1 && hasHadZeroNodes {
return
}
}
}
}
示例7: TestGeospatialEncodeGeometryPseudoType
func (s *RethinkSuite) TestGeospatialEncodeGeometryPseudoType(c *test.C) {
encoded, err := encode(types.Geometry{
Type: "Polygon",
Lines: types.Lines{
types.Line{
types.Point{Lon: -122.423246, Lat: 37.779388},
types.Point{Lon: -122.423246, Lat: 37.329898},
types.Point{Lon: -121.88642, Lat: 37.329898},
types.Point{Lon: -121.88642, Lat: 37.779388},
types.Point{Lon: -122.423246, Lat: 37.779388},
},
},
})
c.Assert(err, test.IsNil)
c.Assert(encoded, jsonEquals, map[string]interface{}{
"$reql_type$": "GEOMETRY",
"type": "Polygon",
"coordinates": []interface{}{
[]interface{}{
[]interface{}{-122.423246, 37.779388},
[]interface{}{-122.423246, 37.329898},
[]interface{}{-121.88642, 37.329898},
[]interface{}{-121.88642, 37.779388},
[]interface{}{-122.423246, 37.779388},
},
},
})
}
示例8: BenchmarkNoReplyExpr
func (s *RethinkSuite) BenchmarkNoReplyExpr(c *test.C) {
for i := 0; i < c.N; i++ {
// Test query
query := Expr(true)
err := query.Exec(session, ExecOpts{NoReply: true})
c.Assert(err, test.IsNil)
}
}
示例9: TestSessionConnectError
func (s *RethinkSuite) TestSessionConnectError(c *test.C) {
var err error
_, err = Connect(ConnectOpts{
Address: "nonexistanturl",
Timeout: time.Second,
})
c.Assert(err, test.NotNil)
}
示例10: TestWriteDelete
func (s *RethinkSuite) TestWriteDelete(c *test.C) {
query := DB("test").Table("test").Insert(map[string]interface{}{"num": 1})
_, err := query.Run(session)
c.Assert(err, test.IsNil)
// Delete the first row in the table
query = DB("test").Table("test").Sample(1).Delete()
_, err = query.Run(session)
c.Assert(err, test.IsNil)
}
示例11: TestTableCompoundIndexCreate
func (s *RethinkSuite) TestTableCompoundIndexCreate(c *test.C) {
DBCreate("test").Exec(session)
DB("test").TableDrop("TableCompound").Exec(session)
DB("test").TableCreate("TableCompound").Exec(session)
response, err := DB("test").Table("TableCompound").IndexCreateFunc("full_name", func(row Term) interface{} {
return []interface{}{row.Field("first_name"), row.Field("last_name")}
}).RunWrite(session)
c.Assert(err, test.IsNil)
c.Assert(response.Created, test.Equals, 1)
}
示例12: TestTableCreate
func (s *RethinkSuite) TestTableCreate(c *test.C) {
DB("test").TableDrop("test").Exec(session)
// Test database creation
query := DB("test").TableCreate("test")
response, err := query.RunWrite(session)
c.Assert(err, test.IsNil)
c.Assert(response.TablesCreated, jsonEquals, 1)
}
示例13: TestDbCreate
func (s *RethinkSuite) TestDbCreate(c *test.C) {
// Delete the test2 database if it already exists
DBDrop("test").Exec(session)
// Test database creation
query := DBCreate("test")
response, err := query.RunWrite(session)
c.Assert(err, test.IsNil)
c.Assert(response.DBsCreated, jsonEquals, 1)
}
示例14: TestTableCreateSoftDurability
func (s *RethinkSuite) TestTableCreateSoftDurability(c *test.C) {
DB("test").TableDrop("testOpts").Exec(session)
// Test database creation
query := DB("test").TableCreate("testOpts", TableCreateOpts{
Durability: "soft",
})
response, err := query.RunWrite(session)
c.Assert(err, test.IsNil)
c.Assert(response.TablesCreated, jsonEquals, 1)
}
示例15: TestGeospatialPointDistanceRootKm
func (s *RethinkSuite) TestGeospatialPointDistanceRootKm(c *test.C) {
var response float64
f := 734.125249602186
res, err := Distance(Point(-122.423246, 37.779388), Point(-117.220406, 32.719464), DistanceOpts{Unit: "km"}).Run(session)
c.Assert(err, test.IsNil)
err = res.One(&response)
c.Assert(err, test.IsNil)
if !kindaclose(response, f) {
c.Errorf("the deviation between the compared floats is too great [%v:%v]", response, f)
}
}