forked from rethinkdb/rethinkdb-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_db_test.go
69 lines (48 loc) · 1.39 KB
/
query_db_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package gorethink
import (
test "launchpad.net/gocheck"
)
func (s *RethinkSuite) TestDbCreate(c *test.C) {
var response interface{}
// Delete the test2 database if it already exists
DbDrop("test").Exec(sess)
// Test database creation
query := DbCreate("test")
r, err := query.RunRow(sess)
c.Assert(err, test.IsNil)
err = r.Scan(&response)
c.Assert(err, test.IsNil)
c.Assert(response, JsonEquals, map[string]interface{}{"created": 1})
}
func (s *RethinkSuite) TestDbList(c *test.C) {
var response interface{}
// create database
DbCreate("test").Exec(sess)
// Try and find it in the list
success := false
r, err := DbList().RunRow(sess)
c.Assert(err, test.IsNil)
err = r.Scan(&response)
c.Assert(err, test.IsNil)
c.Assert(response, test.FitsTypeOf, []interface{}{})
for _, db := range response.([]interface{}) {
if db == "test" {
success = true
}
}
c.Assert(success, test.Equals, true)
}
func (s *RethinkSuite) TestDbDelete(c *test.C) {
var response interface{}
// Delete the test2 database if it already exists
DbCreate("test").Exec(sess)
// Test database creation
query := DbDrop("test")
r, err := query.RunRow(sess)
c.Assert(err, test.IsNil)
err = r.Scan(&response)
c.Assert(err, test.IsNil)
c.Assert(response, JsonEquals, map[string]interface{}{"dropped": 1})
// Ensure that there is still a test DB after the test has finished
DbCreate("test").Exec(sess)
}