File: reql_polymorphism_test.go

package info (click to toggle)
golang-gopkg-rethinkdb-rethinkdb-go.v6 6.2.1-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,736 kB
  • sloc: python: 1,382; makefile: 16; sh: 9
file content (188 lines) | stat: -rw-r--r-- 6,103 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Code generated by gen_tests.py and process_polyglot.py.
// Do not edit this file directly.
// The template for this file is located at:
// ../template.go.tpl
package reql_tests

import (
	"testing"
	"time"

	"github.com/stretchr/testify/suite"
	r "gopkg.in/rethinkdb/rethinkdb-go.v6"
	"gopkg.in/rethinkdb/rethinkdb-go.v6/internal/compare"
)

// Tests that manipulation data in tables
func TestPolymorphismSuite(t *testing.T) {
	suite.Run(t, new(PolymorphismSuite))
}

type PolymorphismSuite struct {
	suite.Suite

	session *r.Session
}

func (suite *PolymorphismSuite) SetupTest() {
	suite.T().Log("Setting up PolymorphismSuite")
	// Use imports to prevent errors
	_ = time.Time{}
	_ = compare.AnythingIsFine

	session, err := r.Connect(r.ConnectOpts{
		Address: url,
	})
	suite.Require().NoError(err, "Error returned when connecting to server")
	suite.session = session

	r.DBDrop("db_poly").Exec(suite.session)
	err = r.DBCreate("db_poly").Exec(suite.session)
	suite.Require().NoError(err)
	err = r.DB("db_poly").Wait().Exec(suite.session)
	suite.Require().NoError(err)

	r.DB("db_poly").TableDrop("table_test_poly").Exec(suite.session)
	err = r.DB("db_poly").TableCreate("table_test_poly").Exec(suite.session)
	suite.Require().NoError(err)
	err = r.DB("db_poly").Table("table_test_poly").Wait().Exec(suite.session)
	suite.Require().NoError(err)
}

func (suite *PolymorphismSuite) TearDownSuite() {
	suite.T().Log("Tearing down PolymorphismSuite")

	if suite.session != nil {
		r.DB("rethinkdb").Table("_debug_scratch").Delete().Exec(suite.session)
		r.DB("db_poly").TableDrop("table_test_poly").Exec(suite.session)
		r.DBDrop("db_poly").Exec(suite.session)

		suite.session.Close()
	}
}

func (suite *PolymorphismSuite) TestCases() {
	suite.T().Log("Running PolymorphismSuite: Tests that manipulation data in tables")

	table_test_poly := r.DB("db_poly").Table("table_test_poly")
	_ = table_test_poly // Prevent any noused variable errors

	// polymorphism.yaml line #5
	// obj = r.expr({'id':0,'a':0})
	suite.T().Log("Possibly executing: var obj r.Term = r.Expr(map[interface{}]interface{}{'id': 0, 'a': 0, })")

	obj := r.Expr(map[interface{}]interface{}{"id": 0, "a": 0})
	_ = obj // Prevent any noused variable errors

	{
		// polymorphism.yaml line #7
		/* ({'deleted':0,'replaced':0,'unchanged':0,'errors':0,'skipped':0,'inserted':3}) */
		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"deleted": 0, "replaced": 0, "unchanged": 0, "errors": 0, "skipped": 0, "inserted": 3}
		/* table_test_poly.insert([{'id':i, 'a':i} for i in xrange(3)]) */

		suite.T().Log("About to run line #7: table_test_poly.Insert((func() []interface{} {\n    res := []interface{}{}\n    for iterator_ := 0; iterator_ < 3; iterator_++ {\n        i := iterator_\n        res = append(res, map[interface{}]interface{}{'id': i, 'a': i, })\n    }\n    return res\n}()))")

		runAndAssert(suite.Suite, expected_, table_test_poly.Insert((func() []interface{} {
			res := []interface{}{}
			for iterator_ := 0; iterator_ < 3; iterator_++ {
				i := iterator_
				res = append(res, map[interface{}]interface{}{"id": i, "a": i})
			}
			return res
		}())), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #7")
	}

	{
		// polymorphism.yaml line #21
		/* ({'id':0,'c':1,'a':0}) */
		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"id": 0, "c": 1, "a": 0}
		/* table_test_poly.merge({'c':1}).nth(0) */

		suite.T().Log("About to run line #21: table_test_poly.Merge(map[interface{}]interface{}{'c': 1, }).Nth(0)")

		runAndAssert(suite.Suite, expected_, table_test_poly.Merge(map[interface{}]interface{}{"c": 1}).Nth(0), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #21")
	}

	{
		// polymorphism.yaml line #22
		/* ({'id':0,'c':1,'a':0}) */
		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"id": 0, "c": 1, "a": 0}
		/* obj.merge({'c':1}) */

		suite.T().Log("About to run line #22: obj.Merge(map[interface{}]interface{}{'c': 1, })")

		runAndAssert(suite.Suite, expected_, obj.Merge(map[interface{}]interface{}{"c": 1}), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #22")
	}

	{
		// polymorphism.yaml line #26
		/* ({'id':0}) */
		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"id": 0}
		/* table_test_poly.without('a').nth(0) */

		suite.T().Log("About to run line #26: table_test_poly.Without('a').Nth(0)")

		runAndAssert(suite.Suite, expected_, table_test_poly.Without("a").Nth(0), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #26")
	}

	{
		// polymorphism.yaml line #27
		/* ({'id':0}) */
		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"id": 0}
		/* obj.without('a') */

		suite.T().Log("About to run line #27: obj.Without('a')")

		runAndAssert(suite.Suite, expected_, obj.Without("a"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #27")
	}

	{
		// polymorphism.yaml line #31
		/* ({'a':0}) */
		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"a": 0}
		/* table_test_poly.pluck('a').nth(0) */

		suite.T().Log("About to run line #31: table_test_poly.Pluck('a').Nth(0)")

		runAndAssert(suite.Suite, expected_, table_test_poly.Pluck("a").Nth(0), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #31")
	}

	{
		// polymorphism.yaml line #32
		/* ({'a':0}) */
		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"a": 0}
		/* obj.pluck('a') */

		suite.T().Log("About to run line #32: obj.Pluck('a')")

		runAndAssert(suite.Suite, expected_, obj.Pluck("a"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #32")
	}
}