| 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 that UUIDs work |
| 17 | func TestDatumUuidSuite(t *testing.T) { |
| 18 | suite.Run(t, new(DatumUuidSuite)) |
| 19 | } |
| 20 | |
| 21 | type DatumUuidSuite struct { |
| 22 | suite.Suite |
| 23 | |
| 24 | session *r.Session |
| 25 | } |
| 26 | |
| 27 | func (suite *DatumUuidSuite) SetupTest() { |
| 28 | suite.T().Log("Setting up DatumUuidSuite") |
| 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("db_duuid").Exec(suite.session) |
| 40 | err = r.DBCreate("db_duuid").Exec(suite.session) |
| 41 | suite.Require().NoError(err) |
| 42 | err = r.DB("db_duuid").Wait().Exec(suite.session) |
| 43 | suite.Require().NoError(err) |
| 44 | |
| 45 | } |
| 46 | |
| 47 | func (suite *DatumUuidSuite) TearDownSuite() { |
| 48 | suite.T().Log("Tearing down DatumUuidSuite") |
| 49 | |
| 50 | if suite.session != nil { |
| 51 | r.DB("rethinkdb").Table("_debug_scratch").Delete().Exec(suite.session) |
| 52 | r.DBDrop("db_duuid").Exec(suite.session) |
| 53 | |
| 54 | suite.session.Close() |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func (suite *DatumUuidSuite) TestCases() { |
| 59 | suite.T().Log("Running DatumUuidSuite: Test that UUIDs work") |
| 60 | |
| 61 | { |
| 62 | // datum/uuid.yaml line #3 |
| 63 | /* uuid() */ |
| 64 | var expected_ compare.Regex = compare.IsUUID() |
| 65 | /* r.uuid() */ |
| 66 | |
| 67 | suite.T().Log("About to run line #3: r.UUID()") |
| 68 | |
| 69 | runAndAssert(suite.Suite, expected_, r.UUID(), suite.session, r.RunOpts{ |
| 70 | GeometryFormat: "raw", |
| 71 | GroupFormat: "map", |
| 72 | }) |
| 73 | suite.T().Log("Finished running line #3") |
| 74 | } |
| 75 | |
| 76 | { |
| 77 | // datum/uuid.yaml line #5 |
| 78 | /* uuid() */ |
| 79 | var expected_ compare.Regex = compare.IsUUID() |
| 80 | /* r.expr(r.uuid()) */ |
| 81 | |
| 82 | suite.T().Log("About to run line #5: r.Expr(r.UUID())") |
| 83 | |
| 84 | runAndAssert(suite.Suite, expected_, r.Expr(r.UUID()), suite.session, r.RunOpts{ |
| 85 | GeometryFormat: "raw", |
| 86 | GroupFormat: "map", |
| 87 | }) |
| 88 | suite.T().Log("Finished running line #5") |
| 89 | } |
| 90 | |
| 91 | { |
| 92 | // datum/uuid.yaml line #7 |
| 93 | /* 'STRING' */ |
| 94 | var expected_ string = "STRING" |
| 95 | /* r.type_of(r.uuid()) */ |
| 96 | |
| 97 | suite.T().Log("About to run line #7: r.TypeOf(r.UUID())") |
| 98 | |
| 99 | runAndAssert(suite.Suite, expected_, r.TypeOf(r.UUID()), suite.session, r.RunOpts{ |
| 100 | GeometryFormat: "raw", |
| 101 | GroupFormat: "map", |
| 102 | }) |
| 103 | suite.T().Log("Finished running line #7") |
| 104 | } |
| 105 | |
| 106 | { |
| 107 | // datum/uuid.yaml line #9 |
| 108 | /* true */ |
| 109 | var expected_ bool = true |
| 110 | /* r.uuid().ne(r.uuid()) */ |
| 111 | |
| 112 | suite.T().Log("About to run line #9: r.UUID().Ne(r.UUID())") |
| 113 | |
| 114 | runAndAssert(suite.Suite, expected_, r.UUID().Ne(r.UUID()), suite.session, r.RunOpts{ |
| 115 | GeometryFormat: "raw", |
| 116 | GroupFormat: "map", |
| 117 | }) |
| 118 | suite.T().Log("Finished running line #9") |
| 119 | } |
| 120 | |
| 121 | { |
| 122 | // datum/uuid.yaml line #11 |
| 123 | /* ('97dd10a5-4fc4-554f-86c5-0d2c2e3d5330') */ |
| 124 | var expected_ string = "97dd10a5-4fc4-554f-86c5-0d2c2e3d5330" |
| 125 | /* r.uuid('magic') */ |
| 126 | |
| 127 | suite.T().Log("About to run line #11: r.UUID('magic')") |
| 128 | |
| 129 | runAndAssert(suite.Suite, expected_, r.UUID("magic"), suite.session, r.RunOpts{ |
| 130 | GeometryFormat: "raw", |
| 131 | GroupFormat: "map", |
| 132 | }) |
| 133 | suite.T().Log("Finished running line #11") |
| 134 | } |
| 135 | |
| 136 | { |
| 137 | // datum/uuid.yaml line #13 |
| 138 | /* true */ |
| 139 | var expected_ bool = true |
| 140 | /* r.uuid('magic').eq(r.uuid('magic')) */ |
| 141 | |
| 142 | suite.T().Log("About to run line #13: r.UUID('magic').Eq(r.UUID('magic'))") |
| 143 | |
| 144 | runAndAssert(suite.Suite, expected_, r.UUID("magic").Eq(r.UUID("magic")), suite.session, r.RunOpts{ |
| 145 | GeometryFormat: "raw", |
| 146 | GroupFormat: "map", |
| 147 | }) |
| 148 | suite.T().Log("Finished running line #13") |
| 149 | } |
| 150 | |
| 151 | { |
| 152 | // datum/uuid.yaml line #15 |
| 153 | /* true */ |
| 154 | var expected_ bool = true |
| 155 | /* r.uuid('magic').ne(r.uuid('beans')) */ |
| 156 | |
| 157 | suite.T().Log("About to run line #15: r.UUID('magic').Ne(r.UUID('beans'))") |
| 158 | |
| 159 | runAndAssert(suite.Suite, expected_, r.UUID("magic").Ne(r.UUID("beans")), suite.session, r.RunOpts{ |
| 160 | GeometryFormat: "raw", |
| 161 | GroupFormat: "map", |
| 162 | }) |
| 163 | suite.T().Log("Finished running line #15") |
| 164 | } |
| 165 | |
| 166 | { |
| 167 | // datum/uuid.yaml line #17 |
| 168 | /* 10 */ |
| 169 | var expected_ int = 10 |
| 170 | /* r.expr([1,2,3,4,5,6,7,8,9,10]).map(lambda u:r.uuid()).distinct().count() */ |
| 171 | |
| 172 | suite.T().Log("About to run line #17: r.Expr([]interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).Map(func(u r.Term) interface{} { return r.UUID()}).Distinct().Count()") |
| 173 | |
| 174 | runAndAssert(suite.Suite, expected_, r.Expr([]interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).Map(func(u r.Term) interface{} { return r.UUID() }).Distinct().Count(), suite.session, r.RunOpts{ |
| 175 | GeometryFormat: "raw", |
| 176 | GroupFormat: "map", |
| 177 | }) |
| 178 | suite.T().Log("Finished running line #17") |
| 179 | } |
| 180 | } |