gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/internal/integration/reql_tests/reql_transform_table_test.go (about)

     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 manipulation operations on tables
    17  func TestTransformTableSuite(t *testing.T) {
    18  	suite.Run(t, new(TransformTableSuite))
    19  }
    20  
    21  type TransformTableSuite struct {
    22  	suite.Suite
    23  
    24  	session *r.Session
    25  }
    26  
    27  func (suite *TransformTableSuite) SetupTest() {
    28  	suite.T().Log("Setting up TransformTableSuite")
    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("test").Exec(suite.session)
    40  	err = r.DBCreate("test").Exec(suite.session)
    41  	suite.Require().NoError(err)
    42  	err = r.DB("test").Wait().Exec(suite.session)
    43  	suite.Require().NoError(err)
    44  
    45  	r.DB("test").TableDrop("tbl").Exec(suite.session)
    46  	err = r.DB("test").TableCreate("tbl").Exec(suite.session)
    47  	suite.Require().NoError(err)
    48  	err = r.DB("test").Table("tbl").Wait().Exec(suite.session)
    49  	suite.Require().NoError(err)
    50  }
    51  
    52  func (suite *TransformTableSuite) TearDownSuite() {
    53  	suite.T().Log("Tearing down TransformTableSuite")
    54  
    55  	if suite.session != nil {
    56  		r.DB("rethinkdb").Table("_debug_scratch").Delete().Exec(suite.session)
    57  		r.DB("test").TableDrop("tbl").Exec(suite.session)
    58  		r.DBDrop("test").Exec(suite.session)
    59  
    60  		suite.session.Close()
    61  	}
    62  }
    63  
    64  func (suite *TransformTableSuite) TestCases() {
    65  	suite.T().Log("Running TransformTableSuite: Tests manipulation operations on tables")
    66  
    67  	tbl := r.DB("test").Table("tbl")
    68  	_ = tbl // Prevent any noused variable errors
    69  
    70  	{
    71  		// transform/table.yaml line #5
    72  		/* AnythingIsFine */
    73  		var expected_ string = compare.AnythingIsFine
    74  		/* tbl.insert([{"a":["k1","v1"]},{"a":["k2","v2"]}]) */
    75  
    76  		suite.T().Log("About to run line #5: tbl.Insert([]interface{}{map[interface{}]interface{}{'a': []interface{}{'k1', 'v1'}, }, map[interface{}]interface{}{'a': []interface{}{'k2', 'v2'}, }})")
    77  
    78  		runAndAssert(suite.Suite, expected_, tbl.Insert([]interface{}{map[interface{}]interface{}{"a": []interface{}{"k1", "v1"}}, map[interface{}]interface{}{"a": []interface{}{"k2", "v2"}}}), suite.session, r.RunOpts{
    79  			GeometryFormat: "raw",
    80  			GroupFormat:    "map",
    81  		})
    82  		suite.T().Log("Finished running line #5")
    83  	}
    84  
    85  	{
    86  		// transform/table.yaml line #10
    87  		/* {"k1":"v1","k2":"v2"} */
    88  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"k1": "v1", "k2": "v2"}
    89  		/* tbl.map(r.row["a"]).coerce_to("object") */
    90  
    91  		suite.T().Log("About to run line #10: tbl.Map(r.Row.AtIndex('a')).CoerceTo('object')")
    92  
    93  		runAndAssert(suite.Suite, expected_, tbl.Map(r.Row.AtIndex("a")).CoerceTo("object"), suite.session, r.RunOpts{
    94  			GeometryFormat: "raw",
    95  			GroupFormat:    "map",
    96  		})
    97  		suite.T().Log("Finished running line #10")
    98  	}
    99  
   100  	{
   101  		// transform/table.yaml line #14
   102  		/* "SELECTION<STREAM>" */
   103  		var expected_ string = "SELECTION<STREAM>"
   104  		/* tbl.limit(1).type_of() */
   105  
   106  		suite.T().Log("About to run line #14: tbl.Limit(1).TypeOf()")
   107  
   108  		runAndAssert(suite.Suite, expected_, tbl.Limit(1).TypeOf(), suite.session, r.RunOpts{
   109  			GeometryFormat: "raw",
   110  			GroupFormat:    "map",
   111  		})
   112  		suite.T().Log("Finished running line #14")
   113  	}
   114  
   115  	{
   116  		// transform/table.yaml line #17
   117  		/* "ARRAY" */
   118  		var expected_ string = "ARRAY"
   119  		/* tbl.limit(1).coerce_to('array').type_of() */
   120  
   121  		suite.T().Log("About to run line #17: tbl.Limit(1).CoerceTo('array').TypeOf()")
   122  
   123  		runAndAssert(suite.Suite, expected_, tbl.Limit(1).CoerceTo("array").TypeOf(), suite.session, r.RunOpts{
   124  			GeometryFormat: "raw",
   125  			GroupFormat:    "map",
   126  		})
   127  		suite.T().Log("Finished running line #17")
   128  	}
   129  }