コード例 #1
0
func (suite *MetaCompositeSuite) TestCases() {
	suite.T().Log("Running MetaCompositeSuite: Tests meta operations in composite queries")

	{
		// meta/composite.py.yaml line #4
		/* ({'dbs_created':3,'config_changes':arrlen(3)}) */
		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"dbs_created": 3, "config_changes": arrlen(3)}
		/* r.expr([1,2,3]).for_each(r.db_create('db_' + r.row.coerce_to('string'))) */

		suite.T().Log("About to run line #4: r.Expr([]interface{}{1, 2, 3}).ForEach(r.DBCreate(r.Add('db_', r.Row.CoerceTo('string'))))")

		runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{1, 2, 3}).ForEach(r.DBCreate(r.Add("db_", r.Row.CoerceTo("string")))), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #4")
	}

	{
		// meta/composite.py.yaml line #8
		/* partial({'tables_created':9}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"tables_created": 9})
		/* r.db_list().set_difference(["rethinkdb", "test"]).for_each(lambda db_name:
		r.expr([1,2,3]).for_each(lambda i:
		r.db(db_name).table_create('tbl_' + i.coerce_to('string')))) */

		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')))})})")

		runAndAssert(suite.Suite, expected_, 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"))) })
		}), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #8")
	}

	{
		// meta/composite.py.yaml line #13
		/* partial({'dbs_dropped':3,'tables_dropped':9}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"dbs_dropped": 3, "tables_dropped": 9})
		/* r.db_list().set_difference(["rethinkdb", "test"]).for_each(r.db_drop(r.row)) */

		suite.T().Log("About to run line #13: r.DBList().SetDifference([]interface{}{'rethinkdb', 'test'}).ForEach(r.DBDrop(r.Row))")

		runAndAssert(suite.Suite, expected_, r.DBList().SetDifference([]interface{}{"rethinkdb", "test"}).ForEach(r.DBDrop(r.Row)), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #13")
	}
}
コード例 #2
0
ファイル: backend_connections.go プロジェクト: jemacom/hydra
func (c *RethinkDBConnection) GetSession() *r.Session {
	if c.session != nil {
		return c.session
	}

	var err error
	var username, password string
	database := c.URL.Path[1:]
	if c.URL.User != nil {
		password, _ = c.URL.User.Password()
		username = c.URL.User.Username()
	}

	if err := pkg.Retry(time.Second*15, time.Minute*2, func() error {
		logrus.Infof("Connecting with RethinkDB: %s (%s) (%s)", c.URL.String(), c.URL.Host, database)
		if c.session, err = r.Connect(r.ConnectOpts{
			Address:  c.URL.Host,
			Username: username,
			Password: password,
		}); err != nil {
			return errors.Errorf("Could not connect to RethinkDB: %s", err)
		}

		if _, err := r.DBList().Contains(database).Do(func(e r.Term) r.Term {
			return r.Branch(
				e,
				map[string]interface{}{"dbs_created": 0},
				r.DBCreate(database),
			)
		}).RunWrite(c.session); err != nil {
			return errors.Errorf("Could not create database: %s", err)
		}

		c.session.Use(database)
		logrus.Infof("Connected to RethinkDB!")
		return nil
	}); err != nil {
		logrus.Fatalf("Could not connect to RethinkDB: %s", err)
	}

	return c.session
}
コード例 #3
0
func (suite *MetaDbsSuite) TestCases() {
	suite.T().Log("Running MetaDbsSuite: Tests meta queries for databases")

	{
		// meta/dbs.yaml line #6
		/* bag(['rethinkdb', 'test']) */
		var expected_ compare.Expected = compare.UnorderedMatch([]interface{}{"rethinkdb", "test"})
		/* r.db_list() */

		suite.T().Log("About to run line #6: r.DBList()")

		runAndAssert(suite.Suite, expected_, r.DBList(), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #6")
	}

	{
		// meta/dbs.yaml line #11
		/* partial({'dbs_created':1}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"dbs_created": 1})
		/* r.db_create('a') */

		suite.T().Log("About to run line #11: r.DBCreate('a')")

		runAndAssert(suite.Suite, expected_, r.DBCreate("a"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #11")
	}

	{
		// meta/dbs.yaml line #13
		/* partial({'dbs_created':1}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"dbs_created": 1})
		/* r.db_create('b') */

		suite.T().Log("About to run line #13: r.DBCreate('b')")

		runAndAssert(suite.Suite, expected_, r.DBCreate("b"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #13")
	}

	{
		// meta/dbs.yaml line #18
		/* bag(['rethinkdb', 'a', 'b', 'test']) */
		var expected_ compare.Expected = compare.UnorderedMatch([]interface{}{"rethinkdb", "a", "b", "test"})
		/* r.db_list() */

		suite.T().Log("About to run line #18: r.DBList()")

		runAndAssert(suite.Suite, expected_, r.DBList(), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #18")
	}

	{
		// meta/dbs.yaml line #23
		/* {'name':'a','id':uuid()} */
		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"name": "a", "id": compare.IsUUID()}
		/* r.db('a').config() */

		suite.T().Log("About to run line #23: r.DB('a').Config()")

		runAndAssert(suite.Suite, expected_, r.DB("a").Config(), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #23")
	}

	{
		// meta/dbs.yaml line #28
		/* partial({'dbs_dropped':1}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"dbs_dropped": 1})
		/* r.db_drop('b') */

		suite.T().Log("About to run line #28: r.DBDrop('b')")

		runAndAssert(suite.Suite, expected_, r.DBDrop("b"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #28")
	}

	{
		// meta/dbs.yaml line #31
		/* bag(['rethinkdb', 'a', 'test']) */
		var expected_ compare.Expected = compare.UnorderedMatch([]interface{}{"rethinkdb", "a", "test"})
		/* r.db_list() */

		suite.T().Log("About to run line #31: r.DBList()")

		runAndAssert(suite.Suite, expected_, r.DBList(), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #31")
	}

	{
		// meta/dbs.yaml line #34
		/* partial({'dbs_dropped':1}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"dbs_dropped": 1})
		/* r.db_drop('a') */

		suite.T().Log("About to run line #34: r.DBDrop('a')")

		runAndAssert(suite.Suite, expected_, r.DBDrop("a"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #34")
	}

	{
		// meta/dbs.yaml line #37
		/* bag(['rethinkdb', 'test']) */
		var expected_ compare.Expected = compare.UnorderedMatch([]interface{}{"rethinkdb", "test"})
		/* r.db_list() */

		suite.T().Log("About to run line #37: r.DBList()")

		runAndAssert(suite.Suite, expected_, r.DBList(), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #37")
	}

	{
		// meta/dbs.yaml line #41
		/* partial({'dbs_created':1}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"dbs_created": 1})
		/* r.db_create('bar') */

		suite.T().Log("About to run line #41: r.DBCreate('bar')")

		runAndAssert(suite.Suite, expected_, r.DBCreate("bar"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #41")
	}

	{
		// meta/dbs.yaml line #44
		/* err('ReqlOpFailedError', 'Database `bar` already exists.', [0]) */
		var expected_ Err = err("ReqlOpFailedError", "Database `bar` already exists.")
		/* r.db_create('bar') */

		suite.T().Log("About to run line #44: r.DBCreate('bar')")

		runAndAssert(suite.Suite, expected_, r.DBCreate("bar"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #44")
	}

	{
		// meta/dbs.yaml line #47
		/* partial({'dbs_dropped':1}) */
		var expected_ compare.Expected = compare.PartialMatch(map[interface{}]interface{}{"dbs_dropped": 1})
		/* r.db_drop('bar') */

		suite.T().Log("About to run line #47: r.DBDrop('bar')")

		runAndAssert(suite.Suite, expected_, r.DBDrop("bar"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #47")
	}

	{
		// meta/dbs.yaml line #50
		/* err('ReqlOpFailedError', 'Database `bar` does not exist.', [0]) */
		var expected_ Err = err("ReqlOpFailedError", "Database `bar` does not exist.")
		/* r.db_drop('bar') */

		suite.T().Log("About to run line #50: r.DBDrop('bar')")

		runAndAssert(suite.Suite, expected_, r.DBDrop("bar"), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #50")
	}
}