本文整理匯總了Golang中github.com/pgpst/pgpst/internal/gopkg/in/check/v1.C類的典型用法代碼示例。如果您正苦於以下問題:Golang C類的具體用法?Golang C怎麽用?Golang C使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了C類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2: 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},
},
},
})
}
示例3: 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
}
}
}
}
示例4: TestOrderByJoinEq
func (s *RethinkSuite) TestOrderByJoinEq(c *test.C) {
type Map map[string]interface{}
var err error
// Ensure table + database exist
DBCreate("test").Exec(session)
DB("test").TableCreate("test").Exec(session)
DB("test").TableCreate("test2").Exec(session)
tab := DB("test").Table("test")
tab2 := DB("test").Table("test2")
// insert rows
err = tab.Insert(Map{"S": "s1", "T": 2}).Exec(session)
err = tab.Insert(Map{"S": "s1", "T": 1}).Exec(session)
err = tab.Insert(Map{"S": "s1", "T": 3}).Exec(session)
err = tab.Insert(Map{"S": "s2", "T": 3}).Exec(session)
c.Assert(err, test.IsNil)
err = tab2.Insert(Map{"id": "s1", "N": "Rob"}).Exec(session)
err = tab2.Insert(Map{"id": "s2", "N": "Zar"}).Exec(session)
c.Assert(err, test.IsNil)
// Test query
var response []Map
res, err := tab.OrderBy("T").EqJoin("S", tab2).Run(session)
c.Assert(err, test.IsNil)
err = res.All(&response)
c.Assert(err, test.IsNil)
c.Check(len(response), test.Equals, 4, test.Commentf("%v", response))
}
示例5: doConcurrentTest
func doConcurrentTest(c *test.C, ct func()) {
maxProcs, numReqs := 1, 150
if testing.Short() {
maxProcs, numReqs = 4, 50
}
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(maxProcs))
var wg sync.WaitGroup
wg.Add(numReqs)
reqs := make(chan bool)
defer close(reqs)
for i := 0; i < maxProcs*2; i++ {
go func() {
for _ = range reqs {
ct()
if c.Failed() {
wg.Done()
continue
}
wg.Done()
}
}()
}
for i := 0; i < numReqs; i++ {
reqs <- true
}
wg.Wait()
}
示例6: 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)
}
}
示例7: 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()
}
示例8: 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},
},
})
}
示例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: 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)
}
}
示例11: 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)
}
示例12: 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)
}
示例13: 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)
}
示例14: TestConcurrentSelectManyRows
func (s *RethinkSuite) TestConcurrentSelectManyRows(c *test.C) {
if testing.Short() {
c.Skip("Skipping long test")
}
// Ensure table + database exist
DBCreate("test").RunWrite(session)
DB("test").TableCreate("TestMany").RunWrite(session)
DB("test").Table("TestMany").Delete().RunWrite(session)
// Insert rows
for i := 0; i < 100; i++ {
DB("test").Table("TestMany").Insert(map[string]interface{}{
"i": i,
}).Exec(session)
}
// Test queries concurrently
attempts := 10
waitChannel := make(chan error, attempts)
for i := 0; i < attempts; i++ {
go func(i int, c chan error) {
res, err := DB("test").Table("TestMany").Run(session)
if err != nil {
c <- err
return
}
var response []map[string]interface{}
err = res.All(&response)
if err != nil {
c <- err
return
}
if len(response) != 100 {
c <- fmt.Errorf("expected response length 100, received %d", len(response))
return
}
res.Close()
c <- nil
}(i, waitChannel)
}
for i := 0; i < attempts; i++ {
ret := <-waitChannel
if ret != nil {
c.Fatalf("non-nil error returned (%s)", ret)
}
}
}
示例15: 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)
}