File: query_db_test.go

package info (click to toggle)
golang-gopkg-dancannon-gorethink.v1 1.4.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 764 kB
  • sloc: makefile: 3
file content (57 lines) | stat: -rw-r--r-- 1,235 bytes parent folder | download | duplicates (3)
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
package gorethink

import (
	test "gopkg.in/check.v1"
)

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)
}

func (s *RethinkSuite) TestDbList(c *test.C) {
	var response []interface{}

	// create database
	DBCreate("test").Exec(session)

	// Try and find it in the list
	success := false
	res, err := DBList().Run(session)
	c.Assert(err, test.IsNil)

	err = res.All(&response)

	c.Assert(err, test.IsNil)
	c.Assert(response, test.FitsTypeOf, []interface{}{})

	for _, db := range response {
		if db == "test" {
			success = true
		}
	}

	c.Assert(success, test.Equals, true)
}

func (s *RethinkSuite) TestDbDelete(c *test.C) {
	// Delete the test2 database if it already exists
	DBCreate("test").Exec(session)

	// Test database creation
	query := DBDrop("test")

	response, err := query.RunWrite(session)
	c.Assert(err, test.IsNil)
	c.Assert(response.DBsDropped, jsonEquals, 1)

	// Ensure that there is still a test DB after the test has finished
	DBCreate("test").Exec(session)
}