gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/internal/integration/reql_tests/reql_changefeeds_include_states_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  // Test `include_states`
    17  func TestChangefeedsIncludeStatesSuite(t *testing.T) {
    18  	suite.Run(t, new(ChangefeedsIncludeStatesSuite))
    19  }
    20  
    21  type ChangefeedsIncludeStatesSuite struct {
    22  	suite.Suite
    23  
    24  	session *r.Session
    25  }
    26  
    27  func (suite *ChangefeedsIncludeStatesSuite) SetupTest() {
    28  	suite.T().Log("Setting up ChangefeedsIncludeStatesSuite")
    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 *ChangefeedsIncludeStatesSuite) TearDownSuite() {
    53  	suite.T().Log("Tearing down ChangefeedsIncludeStatesSuite")
    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 *ChangefeedsIncludeStatesSuite) TestCases() {
    65  	suite.T().Log("Running ChangefeedsIncludeStatesSuite: Test `include_states`")
    66  
    67  	tbl := r.DB("test").Table("tbl")
    68  	_ = tbl // Prevent any noused variable errors
    69  
    70  	{
    71  		// changefeeds/include_states.yaml line #4
    72  		/* [{'state':'ready'}] */
    73  		var expected_ []interface{} = []interface{}{map[interface{}]interface{}{"state": "ready"}}
    74  		/* tbl.changes(squash=true, include_states=true).limit(1) */
    75  
    76  		suite.T().Log("About to run line #4: tbl.Changes().OptArgs(r.ChangesOpts{Squash: true, IncludeStates: true, }).Limit(1)")
    77  
    78  		runAndAssert(suite.Suite, expected_, tbl.Changes().OptArgs(r.ChangesOpts{Squash: true, IncludeStates: true}).Limit(1), suite.session, r.RunOpts{
    79  			GeometryFormat: "raw",
    80  			GroupFormat:    "map",
    81  		})
    82  		suite.T().Log("Finished running line #4")
    83  	}
    84  
    85  	{
    86  		// changefeeds/include_states.yaml line #9
    87  		/* [{'state':'initializing'}, {'new_val':null}, {'state':'ready'}] */
    88  		var expected_ []interface{} = []interface{}{map[interface{}]interface{}{"state": "initializing"}, map[interface{}]interface{}{"new_val": nil}, map[interface{}]interface{}{"state": "ready"}}
    89  		/* tbl.get(0).changes(squash=true, include_states=true, include_initial=true).limit(3) */
    90  
    91  		suite.T().Log("About to run line #9: tbl.Get(0).Changes().OptArgs(r.ChangesOpts{Squash: true, IncludeStates: true, IncludeInitial: true, }).Limit(3)")
    92  
    93  		runAndAssert(suite.Suite, expected_, tbl.Get(0).Changes().OptArgs(r.ChangesOpts{Squash: true, IncludeStates: true, IncludeInitial: true}).Limit(3), suite.session, r.RunOpts{
    94  			GeometryFormat: "raw",
    95  			GroupFormat:    "map",
    96  		})
    97  		suite.T().Log("Finished running line #9")
    98  	}
    99  
   100  	{
   101  		// changefeeds/include_states.yaml line #14
   102  		/* [{'state':'initializing'}, {'state':'ready'}] */
   103  		var expected_ []interface{} = []interface{}{map[interface{}]interface{}{"state": "initializing"}, map[interface{}]interface{}{"state": "ready"}}
   104  		/* tbl.order_by(index='id').limit(10).changes(squash=true, include_states=true, include_initial=true).limit(2) */
   105  
   106  		suite.T().Log("About to run line #14: tbl.OrderBy().OptArgs(r.OrderByOpts{Index: 'id', }).Limit(10).Changes().OptArgs(r.ChangesOpts{Squash: true, IncludeStates: true, IncludeInitial: true, }).Limit(2)")
   107  
   108  		runAndAssert(suite.Suite, expected_, tbl.OrderBy().OptArgs(r.OrderByOpts{Index: "id"}).Limit(10).Changes().OptArgs(r.ChangesOpts{Squash: true, IncludeStates: true, IncludeInitial: true}).Limit(2), suite.session, r.RunOpts{
   109  			GeometryFormat: "raw",
   110  			GroupFormat:    "map",
   111  		})
   112  		suite.T().Log("Finished running line #14")
   113  	}
   114  
   115  	{
   116  		// changefeeds/include_states.yaml line #19
   117  		/* AnythingIsFine */
   118  		var expected_ string = compare.AnythingIsFine
   119  		/* tbl.insert({'id':1}) */
   120  
   121  		suite.T().Log("About to run line #19: tbl.Insert(map[interface{}]interface{}{'id': 1, })")
   122  
   123  		runAndAssert(suite.Suite, expected_, tbl.Insert(map[interface{}]interface{}{"id": 1}), suite.session, r.RunOpts{
   124  			GeometryFormat: "raw",
   125  			GroupFormat:    "map",
   126  		})
   127  		suite.T().Log("Finished running line #19")
   128  	}
   129  
   130  	{
   131  		// changefeeds/include_states.yaml line #21
   132  		/* [{'state':'initializing'}, {'new_val':{'id':1}}, {'state':'ready'}] */
   133  		var expected_ []interface{} = []interface{}{map[interface{}]interface{}{"state": "initializing"}, map[interface{}]interface{}{"new_val": map[interface{}]interface{}{"id": 1}}, map[interface{}]interface{}{"state": "ready"}}
   134  		/* tbl.order_by(index='id').limit(10).changes(squash=true, include_states=true, include_initial=true).limit(3) */
   135  
   136  		suite.T().Log("About to run line #21: tbl.OrderBy().OptArgs(r.OrderByOpts{Index: 'id', }).Limit(10).Changes().OptArgs(r.ChangesOpts{Squash: true, IncludeStates: true, IncludeInitial: true, }).Limit(3)")
   137  
   138  		runAndAssert(suite.Suite, expected_, tbl.OrderBy().OptArgs(r.OrderByOpts{Index: "id"}).Limit(10).Changes().OptArgs(r.ChangesOpts{Squash: true, IncludeStates: true, IncludeInitial: true}).Limit(3), suite.session, r.RunOpts{
   139  			GeometryFormat: "raw",
   140  			GroupFormat:    "map",
   141  		})
   142  		suite.T().Log("Finished running line #21")
   143  	}
   144  
   145  	// changefeeds/include_states.yaml line #26
   146  	// tblchanges = tbl.changes(squash=true, include_states=true)
   147  	suite.T().Log("Possibly executing: var tblchanges r.Term = tbl.Changes().OptArgs(r.ChangesOpts{Squash: true, IncludeStates: true, })")
   148  
   149  	tblchanges := maybeRun(tbl.Changes().OptArgs(r.ChangesOpts{Squash: true, IncludeStates: true}), suite.session, r.RunOpts{})
   150  	_ = tblchanges // Prevent any noused variable errors
   151  
   152  	{
   153  		// changefeeds/include_states.yaml line #30
   154  		/* AnythingIsFine */
   155  		var expected_ string = compare.AnythingIsFine
   156  		/* tbl.insert({'id':2}) */
   157  
   158  		suite.T().Log("About to run line #30: tbl.Insert(map[interface{}]interface{}{'id': 2, })")
   159  
   160  		runAndAssert(suite.Suite, expected_, tbl.Insert(map[interface{}]interface{}{"id": 2}), suite.session, r.RunOpts{
   161  			GeometryFormat: "raw",
   162  			GroupFormat:    "map",
   163  		})
   164  		suite.T().Log("Finished running line #30")
   165  	}
   166  
   167  	{
   168  		// changefeeds/include_states.yaml line #32
   169  		/* [{'state':'ready'},{'new_val':{'id':2},'old_val':null}] */
   170  		var expected_ []interface{} = []interface{}{map[interface{}]interface{}{"state": "ready"}, map[interface{}]interface{}{"new_val": map[interface{}]interface{}{"id": 2}, "old_val": nil}}
   171  		/* fetch(tblchanges, 2) */
   172  
   173  		suite.T().Log("About to run line #32: fetch(tblchanges, 2)")
   174  
   175  		fetchAndAssert(suite.Suite, expected_, tblchanges, 2)
   176  		suite.T().Log("Finished running line #32")
   177  	}
   178  
   179  	// changefeeds/include_states.yaml line #35
   180  	// getchanges = tbl.get(2).changes(include_states=true, include_initial=true)
   181  	suite.T().Log("Possibly executing: var getchanges r.Term = tbl.Get(2).Changes().OptArgs(r.ChangesOpts{IncludeStates: true, IncludeInitial: true, })")
   182  
   183  	getchanges := maybeRun(tbl.Get(2).Changes().OptArgs(r.ChangesOpts{IncludeStates: true, IncludeInitial: true}), suite.session, r.RunOpts{})
   184  	_ = getchanges // Prevent any noused variable errors
   185  
   186  	{
   187  		// changefeeds/include_states.yaml line #39
   188  		/* AnythingIsFine */
   189  		var expected_ string = compare.AnythingIsFine
   190  		/* tbl.get(2).update({'a':1}) */
   191  
   192  		suite.T().Log("About to run line #39: tbl.Get(2).Update(map[interface{}]interface{}{'a': 1, })")
   193  
   194  		runAndAssert(suite.Suite, expected_, tbl.Get(2).Update(map[interface{}]interface{}{"a": 1}), suite.session, r.RunOpts{
   195  			GeometryFormat: "raw",
   196  			GroupFormat:    "map",
   197  		})
   198  		suite.T().Log("Finished running line #39")
   199  	}
   200  
   201  	{
   202  		// changefeeds/include_states.yaml line #41
   203  		/* [{'state':'initializing'}, {'new_val':{'id':2}}, {'state':'ready'}, {'old_val':{'id':2},'new_val':{'id':2,'a':1}}] */
   204  		var expected_ []interface{} = []interface{}{map[interface{}]interface{}{"state": "initializing"}, map[interface{}]interface{}{"new_val": map[interface{}]interface{}{"id": 2}}, map[interface{}]interface{}{"state": "ready"}, map[interface{}]interface{}{"old_val": map[interface{}]interface{}{"id": 2}, "new_val": map[interface{}]interface{}{"id": 2, "a": 1}}}
   205  		/* fetch(getchanges, 4) */
   206  
   207  		suite.T().Log("About to run line #41: fetch(getchanges, 4)")
   208  
   209  		fetchAndAssert(suite.Suite, expected_, getchanges, 4)
   210  		suite.T().Log("Finished running line #41")
   211  	}
   212  
   213  	// changefeeds/include_states.yaml line #44
   214  	// limitchanges = tbl.order_by(index='id').limit(10).changes(include_states=true, include_initial=true)
   215  	suite.T().Log("Possibly executing: var limitchanges r.Term = tbl.OrderBy().OptArgs(r.OrderByOpts{Index: 'id', }).Limit(10).Changes().OptArgs(r.ChangesOpts{IncludeStates: true, IncludeInitial: true, })")
   216  
   217  	limitchanges := maybeRun(tbl.OrderBy().OptArgs(r.OrderByOpts{Index: "id"}).Limit(10).Changes().OptArgs(r.ChangesOpts{IncludeStates: true, IncludeInitial: true}), suite.session, r.RunOpts{})
   218  	_ = limitchanges // Prevent any noused variable errors
   219  
   220  	// changefeeds/include_states.yaml line #48
   221  	// limitchangesdesc = tbl.order_by(index=r.desc('id')).limit(10).changes(include_states=true, include_initial=true)
   222  	suite.T().Log("Possibly executing: var limitchangesdesc r.Term = tbl.OrderBy().OptArgs(r.OrderByOpts{Index: r.Desc('id'), }).Limit(10).Changes().OptArgs(r.ChangesOpts{IncludeStates: true, IncludeInitial: true, })")
   223  
   224  	limitchangesdesc := maybeRun(tbl.OrderBy().OptArgs(r.OrderByOpts{Index: r.Desc("id")}).Limit(10).Changes().OptArgs(r.ChangesOpts{IncludeStates: true, IncludeInitial: true}), suite.session, r.RunOpts{})
   225  	_ = limitchangesdesc // Prevent any noused variable errors
   226  
   227  	{
   228  		// changefeeds/include_states.yaml line #52
   229  		/* AnythingIsFine */
   230  		var expected_ string = compare.AnythingIsFine
   231  		/* tbl.insert({'id':3}) */
   232  
   233  		suite.T().Log("About to run line #52: tbl.Insert(map[interface{}]interface{}{'id': 3, })")
   234  
   235  		runAndAssert(suite.Suite, expected_, tbl.Insert(map[interface{}]interface{}{"id": 3}), suite.session, r.RunOpts{
   236  			GeometryFormat: "raw",
   237  			GroupFormat:    "map",
   238  		})
   239  		suite.T().Log("Finished running line #52")
   240  	}
   241  
   242  	{
   243  		// changefeeds/include_states.yaml line #54
   244  		/* [{'state':'initializing'}, {'new_val':{'id':1}}, {'new_val':{'a':1, 'id':2}}, {'state':'ready'}, {'old_val':null, 'new_val':{'id':3}}] */
   245  		var expected_ []interface{} = []interface{}{map[interface{}]interface{}{"state": "initializing"}, map[interface{}]interface{}{"new_val": map[interface{}]interface{}{"id": 1}}, map[interface{}]interface{}{"new_val": map[interface{}]interface{}{"a": 1, "id": 2}}, map[interface{}]interface{}{"state": "ready"}, map[interface{}]interface{}{"old_val": nil, "new_val": map[interface{}]interface{}{"id": 3}}}
   246  		/* fetch(limitchanges, 5) */
   247  
   248  		suite.T().Log("About to run line #54: fetch(limitchanges, 5)")
   249  
   250  		fetchAndAssert(suite.Suite, expected_, limitchanges, 5)
   251  		suite.T().Log("Finished running line #54")
   252  	}
   253  
   254  	{
   255  		// changefeeds/include_states.yaml line #57
   256  		/* [{'state':'initializing'}, {'new_val':{'a':1, 'id':2}}, {'new_val':{'id':1}}, {'state':'ready'}, {'old_val':null, 'new_val':{'id':3}}] */
   257  		var expected_ []interface{} = []interface{}{map[interface{}]interface{}{"state": "initializing"}, map[interface{}]interface{}{"new_val": map[interface{}]interface{}{"a": 1, "id": 2}}, map[interface{}]interface{}{"new_val": map[interface{}]interface{}{"id": 1}}, map[interface{}]interface{}{"state": "ready"}, map[interface{}]interface{}{"old_val": nil, "new_val": map[interface{}]interface{}{"id": 3}}}
   258  		/* fetch(limitchangesdesc, 5) */
   259  
   260  		suite.T().Log("About to run line #57: fetch(limitchangesdesc, 5)")
   261  
   262  		fetchAndAssert(suite.Suite, expected_, limitchangesdesc, 5)
   263  		suite.T().Log("Finished running line #57")
   264  	}
   265  }