gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/internal/integration/reql_tests/reql_changefeeds_idxcopy_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 duplicate indexes with squashing
    17  func TestChangefeedsIdxcopySuite(t *testing.T) {
    18  	suite.Run(t, new(ChangefeedsIdxcopySuite))
    19  }
    20  
    21  type ChangefeedsIdxcopySuite struct {
    22  	suite.Suite
    23  
    24  	session *r.Session
    25  }
    26  
    27  func (suite *ChangefeedsIdxcopySuite) SetupTest() {
    28  	suite.T().Log("Setting up ChangefeedsIdxcopySuite")
    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 *ChangefeedsIdxcopySuite) TearDownSuite() {
    53  	suite.T().Log("Tearing down ChangefeedsIdxcopySuite")
    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 *ChangefeedsIdxcopySuite) TestCases() {
    65  	suite.T().Log("Running ChangefeedsIdxcopySuite: Test duplicate indexes with squashing")
    66  
    67  	tbl := r.DB("test").Table("tbl")
    68  	_ = tbl // Prevent any noused variable errors
    69  
    70  	{
    71  		// changefeeds/idxcopy.yaml line #4
    72  		/* partial({'created':1}) */
    73  		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"created": 1})
    74  		/* tbl.index_create('a') */
    75  
    76  		suite.T().Log("About to run line #4: tbl.IndexCreate('a')")
    77  
    78  		runAndAssert(suite.Suite, expected_, tbl.IndexCreate("a"), suite.session, r.RunOpts{
    79  			GeometryFormat: "raw",
    80  			GroupFormat:    "map",
    81  		})
    82  		suite.T().Log("Finished running line #4")
    83  	}
    84  
    85  	{
    86  		// changefeeds/idxcopy.yaml line #6
    87  		/* AnythingIsFine */
    88  		var expected_ string = compare.AnythingIsFine
    89  		/* tbl.index_wait('a') */
    90  
    91  		suite.T().Log("About to run line #6: tbl.IndexWait('a')")
    92  
    93  		runAndAssert(suite.Suite, expected_, tbl.IndexWait("a"), suite.session, r.RunOpts{
    94  			GeometryFormat: "raw",
    95  			GroupFormat:    "map",
    96  		})
    97  		suite.T().Log("Finished running line #6")
    98  	}
    99  
   100  	// changefeeds/idxcopy.yaml line #8
   101  	// feed = tbl.order_by(index='a').limit(10).changes(squash=2)
   102  	suite.T().Log("Possibly executing: var feed r.Term = tbl.OrderBy().OptArgs(r.OrderByOpts{Index: 'a', }).Limit(10).Changes().OptArgs(r.ChangesOpts{Squash: 2, })")
   103  
   104  	feed := maybeRun(tbl.OrderBy().OptArgs(r.OrderByOpts{Index: "a"}).Limit(10).Changes().OptArgs(r.ChangesOpts{Squash: 2}), suite.session, r.RunOpts{
   105  		MaxBatchRows: 1,
   106  	})
   107  	_ = feed // Prevent any noused variable errors
   108  
   109  	{
   110  		// changefeeds/idxcopy.yaml line #15
   111  		/* partial({'inserted':12, 'errors':0}) */
   112  		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"inserted": 12, "errors": 0})
   113  		/* tbl.insert(r.range(0, 12).map({'id':r.row, 'a':5})) */
   114  
   115  		suite.T().Log("About to run line #15: tbl.Insert(r.Range(0, 12).Map(map[interface{}]interface{}{'id': r.Row, 'a': 5, }))")
   116  
   117  		runAndAssert(suite.Suite, expected_, tbl.Insert(r.Range(0, 12).Map(map[interface{}]interface{}{"id": r.Row, "a": 5})), suite.session, r.RunOpts{
   118  			GeometryFormat: "raw",
   119  			GroupFormat:    "map",
   120  		})
   121  		suite.T().Log("Finished running line #15")
   122  	}
   123  
   124  	{
   125  		// changefeeds/idxcopy.yaml line #20
   126  		/* partial({'deleted':3, 'errors':0}) */
   127  		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"deleted": 3, "errors": 0})
   128  		/* tbl.get_all(1, 8, 9, index='id').delete() */
   129  
   130  		suite.T().Log("About to run line #20: tbl.GetAll(1, 8, 9).OptArgs(r.GetAllOpts{Index: 'id', }).Delete()")
   131  
   132  		runAndAssert(suite.Suite, expected_, tbl.GetAll(1, 8, 9).OptArgs(r.GetAllOpts{Index: "id"}).Delete(), suite.session, r.RunOpts{
   133  			GeometryFormat: "raw",
   134  			GroupFormat:    "map",
   135  		})
   136  		suite.T().Log("Finished running line #20")
   137  	}
   138  
   139  	{
   140  		// changefeeds/idxcopy.yaml line #26
   141  		/* AnythingIsFine */
   142  		var expected_ string = compare.AnythingIsFine
   143  		/* wait(2) */
   144  
   145  		suite.T().Log("About to run line #26: wait(2)")
   146  
   147  		actual := wait(2)
   148  
   149  		compare.Assert(suite.T(), expected_, actual)
   150  		suite.T().Log("Finished running line #26")
   151  	}
   152  }