gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/internal/integration/reql_tests/reql_mutation_sync_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 syncing tables
    17  func TestMutationSyncSuite(t *testing.T) {
    18  	suite.Run(t, new(MutationSyncSuite))
    19  }
    20  
    21  type MutationSyncSuite struct {
    22  	suite.Suite
    23  
    24  	session *r.Session
    25  }
    26  
    27  func (suite *MutationSyncSuite) SetupTest() {
    28  	suite.T().Log("Setting up MutationSyncSuite")
    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  }
    46  
    47  func (suite *MutationSyncSuite) TearDownSuite() {
    48  	suite.T().Log("Tearing down MutationSyncSuite")
    49  
    50  	if suite.session != nil {
    51  		r.DB("rethinkdb").Table("_debug_scratch").Delete().Exec(suite.session)
    52  		r.DBDrop("test").Exec(suite.session)
    53  
    54  		suite.session.Close()
    55  	}
    56  }
    57  
    58  func (suite *MutationSyncSuite) TestCases() {
    59  	suite.T().Log("Running MutationSyncSuite: Tests syncing tables")
    60  
    61  	{
    62  		// mutation/sync.yaml line #5
    63  		/* partial({'tables_created':1}) */
    64  		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"tables_created": 1})
    65  		/* r.db('test').table_create('test1') */
    66  
    67  		suite.T().Log("About to run line #5: r.DB('test').TableCreate('test1')")
    68  
    69  		runAndAssert(suite.Suite, expected_, r.DB("test").TableCreate("test1"), suite.session, r.RunOpts{
    70  			GeometryFormat: "raw",
    71  			GroupFormat:    "map",
    72  		})
    73  		suite.T().Log("Finished running line #5")
    74  	}
    75  
    76  	{
    77  		// mutation/sync.yaml line #7
    78  		/* partial({'tables_created':1}) */
    79  		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"tables_created": 1})
    80  		/* r.db('test').table_create('test1soft') */
    81  
    82  		suite.T().Log("About to run line #7: r.DB('test').TableCreate('test1soft')")
    83  
    84  		runAndAssert(suite.Suite, expected_, r.DB("test").TableCreate("test1soft"), suite.session, r.RunOpts{
    85  			GeometryFormat: "raw",
    86  			GroupFormat:    "map",
    87  		})
    88  		suite.T().Log("Finished running line #7")
    89  	}
    90  
    91  	{
    92  		// mutation/sync.yaml line #9
    93  		/* {'skipped':0, 'deleted':0, 'unchanged':0, 'errors':0, 'replaced':1, 'inserted':0} */
    94  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"skipped": 0, "deleted": 0, "unchanged": 0, "errors": 0, "replaced": 1, "inserted": 0}
    95  		/* r.db('test').table('test1soft').config().update({'durability':'soft'}) */
    96  
    97  		suite.T().Log("About to run line #9: r.DB('test').Table('test1soft').Config().Update(map[interface{}]interface{}{'durability': 'soft', })")
    98  
    99  		runAndAssert(suite.Suite, expected_, r.DB("test").Table("test1soft").Config().Update(map[interface{}]interface{}{"durability": "soft"}), suite.session, r.RunOpts{
   100  			GeometryFormat: "raw",
   101  			GroupFormat:    "map",
   102  		})
   103  		suite.T().Log("Finished running line #9")
   104  	}
   105  
   106  	// mutation/sync.yaml line #11
   107  	// tbl = r.db('test').table('test1')
   108  	suite.T().Log("Possibly executing: var tbl r.Term = r.DB('test').Table('test1')")
   109  
   110  	tbl := r.DB("test").Table("test1")
   111  	_ = tbl // Prevent any noused variable errors
   112  
   113  	// mutation/sync.yaml line #12
   114  	// tbl_soft = r.db('test').table('test1soft')
   115  	suite.T().Log("Possibly executing: var tbl_soft r.Term = r.DB('test').Table('test1soft')")
   116  
   117  	tbl_soft := r.DB("test").Table("test1soft")
   118  	_ = tbl_soft // Prevent any noused variable errors
   119  
   120  	{
   121  		// mutation/sync.yaml line #13
   122  		/* partial({'created':1}) */
   123  		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"created": 1})
   124  		/* tbl.index_create('x') */
   125  
   126  		suite.T().Log("About to run line #13: tbl.IndexCreate('x')")
   127  
   128  		runAndAssert(suite.Suite, expected_, tbl.IndexCreate("x"), suite.session, r.RunOpts{
   129  			GeometryFormat: "raw",
   130  			GroupFormat:    "map",
   131  		})
   132  		suite.T().Log("Finished running line #13")
   133  	}
   134  
   135  	{
   136  		// mutation/sync.yaml line #15
   137  		/* [{'ready':True, 'index':'x'}] */
   138  		var expected_ []interface{} = []interface{}{map[interface{}]interface{}{"ready": true, "index": "x"}}
   139  		/* tbl.index_wait('x').pluck('index', 'ready') */
   140  
   141  		suite.T().Log("About to run line #15: tbl.IndexWait('x').Pluck('index', 'ready')")
   142  
   143  		runAndAssert(suite.Suite, expected_, tbl.IndexWait("x").Pluck("index", "ready"), suite.session, r.RunOpts{
   144  			GeometryFormat: "raw",
   145  			GroupFormat:    "map",
   146  		})
   147  		suite.T().Log("Finished running line #15")
   148  	}
   149  
   150  	{
   151  		// mutation/sync.yaml line #19
   152  		/* {'synced':1} */
   153  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"synced": 1}
   154  		/* tbl.sync() */
   155  
   156  		suite.T().Log("About to run line #19: tbl.Sync()")
   157  
   158  		runAndAssert(suite.Suite, expected_, tbl.Sync(), suite.session, r.RunOpts{
   159  			GeometryFormat: "raw",
   160  			GroupFormat:    "map",
   161  		})
   162  		suite.T().Log("Finished running line #19")
   163  	}
   164  
   165  	{
   166  		// mutation/sync.yaml line #21
   167  		/* {'synced':1} */
   168  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"synced": 1}
   169  		/* tbl_soft.sync() */
   170  
   171  		suite.T().Log("About to run line #21: tbl_soft.Sync()")
   172  
   173  		runAndAssert(suite.Suite, expected_, tbl_soft.Sync(), suite.session, r.RunOpts{
   174  			GeometryFormat: "raw",
   175  			GroupFormat:    "map",
   176  		})
   177  		suite.T().Log("Finished running line #21")
   178  	}
   179  
   180  	{
   181  		// mutation/sync.yaml line #23
   182  		/* {'synced':1} */
   183  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"synced": 1}
   184  		/* tbl.sync() */
   185  
   186  		suite.T().Log("About to run line #23: tbl.Sync()")
   187  
   188  		runAndAssert(suite.Suite, expected_, tbl.Sync(), suite.session, r.RunOpts{
   189  			Durability:     "soft",
   190  			GeometryFormat: "raw",
   191  			GroupFormat:    "map",
   192  		})
   193  		suite.T().Log("Finished running line #23")
   194  	}
   195  
   196  	{
   197  		// mutation/sync.yaml line #27
   198  		/* {'synced':1} */
   199  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"synced": 1}
   200  		/* tbl.sync() */
   201  
   202  		suite.T().Log("About to run line #27: tbl.Sync()")
   203  
   204  		runAndAssert(suite.Suite, expected_, tbl.Sync(), suite.session, r.RunOpts{
   205  			Durability:     "hard",
   206  			GeometryFormat: "raw",
   207  			GroupFormat:    "map",
   208  		})
   209  		suite.T().Log("Finished running line #27")
   210  	}
   211  
   212  	{
   213  		// mutation/sync.yaml line #48
   214  		/* partial({'tables_dropped':1}) */
   215  		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"tables_dropped": 1})
   216  		/* r.db('test').table_drop('test1') */
   217  
   218  		suite.T().Log("About to run line #48: r.DB('test').TableDrop('test1')")
   219  
   220  		runAndAssert(suite.Suite, expected_, r.DB("test").TableDrop("test1"), suite.session, r.RunOpts{
   221  			GeometryFormat: "raw",
   222  			GroupFormat:    "map",
   223  		})
   224  		suite.T().Log("Finished running line #48")
   225  	}
   226  
   227  	{
   228  		// mutation/sync.yaml line #50
   229  		/* partial({'tables_dropped':1}) */
   230  		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"tables_dropped": 1})
   231  		/* r.db('test').table_drop('test1soft') */
   232  
   233  		suite.T().Log("About to run line #50: r.DB('test').TableDrop('test1soft')")
   234  
   235  		runAndAssert(suite.Suite, expected_, r.DB("test").TableDrop("test1soft"), suite.session, r.RunOpts{
   236  			GeometryFormat: "raw",
   237  			GroupFormat:    "map",
   238  		})
   239  		suite.T().Log("Finished running line #50")
   240  	}
   241  }