Debian Codegraph @

internal/integration/reql_tests/reql_meta_composite_test.go

raw symbols SCIP
1 // Code generated by gen_tests.py and process_polyglot.py.
2 // Do not edit this file directly.
3 // The template for this file is located at:
4 // ../template.go.tpl
5 package reql_tests
6
7 import (
8 "testing"
9 "time"
10
11 "github.com/stretchr/testify/suite"
12 r "gopkg.in/rethinkdb/rethinkdb-go.v6"
13 "gopkg.in/rethinkdb/rethinkdb-go.v6/internal/compare"
14 )
15
16 // Tests meta operations in composite queries
17 func TestMetaCompositeSuite(t *testing.T) {
18 suite.Run(t, new(MetaCompositeSuite))
19 }
20
21 type MetaCompositeSuite struct {
22 suite.Suite
23
24 session *r.Session
25 }
26
27 func (suite *MetaCompositeSuite) SetupTest() {
28 suite.T().Log("Setting up MetaCompositeSuite")
29 // Use imports to prevent errors
30 _ = time.Time{}
31 _ = compare.AnythingIsFine
32
33 session, err := r.Connect(r.ConnectOpts{
34 Address: url,
35 })
36 suite.Require().NoError(err, "Error returned when connecting to server")
37 suite.session = session
38
39 r.DBDrop("db_composite").Exec(suite.session)
40 err = r.DBCreate("db_composite").Exec(suite.session)
41 suite.Require().NoError(err)
42 err = r.DB("db_composite").Wait().Exec(suite.session)
43 suite.Require().NoError(err)
44
45 }
46
47 func (suite *MetaCompositeSuite) TearDownSuite() {
48 suite.T().Log("Tearing down MetaCompositeSuite")
49
50 if suite.session != nil {
51 r.DB("rethinkdb").Table("_debug_scratch").Delete().Exec(suite.session)
52 r.DBDrop("db_composite").Exec(suite.session)
53
54 suite.session.Close()
55 }
56 }
57
58 func (suite *MetaCompositeSuite) TestCases() {
59 suite.T().Log("Running MetaCompositeSuite: Tests meta operations in composite queries")
60
61 {
62 // meta/composite.py.yaml line #4
63 /* ({'dbs_created':3,'config_changes':arrlen(3)}) */
64 var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"dbs_created": 3, "config_changes": arrlen(3)}
65 /* r.expr([1,2,3]).for_each(r.db_create('db_' + r.row.coerce_to('string'))) */
66
67 suite.T().Log("About to run line #4: r.Expr([]interface{}{1, 2, 3}).ForEach(r.DBCreate(r.Add('db_', r.Row.CoerceTo('string'))))")
68
69 runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{1, 2, 3}).ForEach(r.DBCreate(r.Add("db_", r.Row.CoerceTo("string")))), suite.session, r.RunOpts{
70 GeometryFormat: "raw",
71 GroupFormat: "map",
72 })
73 suite.T().Log("Finished running line #4")
74 }
75
76 {
77 // meta/composite.py.yaml line #8
78 /* partial({'tables_created':9}) */
79 var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"tables_created": 9})
80 /* r.db_list().set_difference(["rethinkdb", "test"]).for_each(lambda db_name:
81 r.expr([1,2,3]).for_each(lambda i:
82 r.db(db_name).table_create('tbl_' + i.coerce_to('string')))) */
83
84 suite.T().Log("About to run line #8: r.DBList().SetDifference([]interface{}{'rethinkdb', 'test'}).ForEach(func(db_name r.Term) interface{} { return r.Expr([]interface{}{1, 2, 3}).ForEach(func(i r.Term) interface{} { return r.DB(db_name).TableCreate(r.Add('tbl_', i.CoerceTo('string')))})})")
85
86 runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{1, 2, 3}).ForEach(
87 func(i r.Term) interface{} {
88 return r.Expr([]interface{}{1, 2, 3}).ForEach(func(j r.Term) interface{} {
89 return r.DB(r.Add("db_", i.CoerceTo("string"))).TableCreate(r.Add("tbl_", j.CoerceTo("string")))
90 })
91 }), suite.session, r.RunOpts{
92 GeometryFormat: "raw",
93 GroupFormat: "map",
94 })
95 suite.T().Log("Finished running line #8")
96 }
97
98 {
99 // meta/composite.py.yaml line #13
100 /* partial({'dbs_dropped':3,'tables_dropped':9}) */
101 var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"dbs_dropped": 3, "tables_dropped": 9})
102 /* r.db_list().set_difference(["rethinkdb", "test"]).for_each(r.db_drop(r.row)) */
103
104 suite.T().Log("About to run line #13: r.DBList().SetDifference([]interface{}{'rethinkdb', 'test'}).ForEach(r.DBDrop(r.Row))")
105
106 runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{1, 2, 3}).ForEach(r.DBDrop(r.Add("db_", r.Row.CoerceTo("string")))), suite.session, r.RunOpts{
107 GeometryFormat: "raw",
108 GroupFormat: "map",
109 })
110 suite.T().Log("Finished running line #13")
111 }
112 }