gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/internal/integration/reql_tests/reql_geo_geojson_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 geoJSON conversion
    17  func TestGeoGeojsonSuite(t *testing.T) {
    18  	suite.Run(t, new(GeoGeojsonSuite))
    19  }
    20  
    21  type GeoGeojsonSuite struct {
    22  	suite.Suite
    23  
    24  	session *r.Session
    25  }
    26  
    27  func (suite *GeoGeojsonSuite) SetupTest() {
    28  	suite.T().Log("Setting up GeoGeojsonSuite")
    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 *GeoGeojsonSuite) TearDownSuite() {
    48  	suite.T().Log("Tearing down GeoGeojsonSuite")
    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 *GeoGeojsonSuite) TestCases() {
    59  	suite.T().Log("Running GeoGeojsonSuite: Test geoJSON conversion")
    60  
    61  	{
    62  		// geo/geojson.yaml line #4
    63  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[0, 0], 'type':'Point'}) */
    64  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{0, 0}, "type": "Point"}
    65  		/* r.geojson({'coordinates':[0, 0], 'type':'Point'}) */
    66  
    67  		suite.T().Log("About to run line #4: r.GeoJSON(map[interface{}]interface{}{'coordinates': []interface{}{0, 0}, 'type': 'Point', })")
    68  
    69  		runAndAssert(suite.Suite, expected_, r.GeoJSON(map[interface{}]interface{}{"coordinates": []interface{}{0, 0}, "type": "Point"}), suite.session, r.RunOpts{
    70  			GeometryFormat: "raw",
    71  			GroupFormat:    "map",
    72  		})
    73  		suite.T().Log("Finished running line #4")
    74  	}
    75  
    76  	{
    77  		// geo/geojson.yaml line #6
    78  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[[0,0], [0,1]], 'type':'LineString'}) */
    79  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{[]interface{}{0, 0}, []interface{}{0, 1}}, "type": "LineString"}
    80  		/* r.geojson({'coordinates':[[0,0], [0,1]], 'type':'LineString'}) */
    81  
    82  		suite.T().Log("About to run line #6: r.GeoJSON(map[interface{}]interface{}{'coordinates': []interface{}{[]interface{}{0, 0}, []interface{}{0, 1}}, 'type': 'LineString', })")
    83  
    84  		runAndAssert(suite.Suite, expected_, r.GeoJSON(map[interface{}]interface{}{"coordinates": []interface{}{[]interface{}{0, 0}, []interface{}{0, 1}}, "type": "LineString"}), suite.session, r.RunOpts{
    85  			GeometryFormat: "raw",
    86  			GroupFormat:    "map",
    87  		})
    88  		suite.T().Log("Finished running line #6")
    89  	}
    90  
    91  	{
    92  		// geo/geojson.yaml line #8
    93  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[[[0,0], [0,1], [1,0], [0,0]]], 'type':'Polygon'}) */
    94  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{[]interface{}{[]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{1, 0}, []interface{}{0, 0}}}, "type": "Polygon"}
    95  		/* r.geojson({'coordinates':[[[0,0], [0,1], [1,0], [0,0]]], 'type':'Polygon'}) */
    96  
    97  		suite.T().Log("About to run line #8: r.GeoJSON(map[interface{}]interface{}{'coordinates': []interface{}{[]interface{}{[]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{1, 0}, []interface{}{0, 0}}}, 'type': 'Polygon', })")
    98  
    99  		runAndAssert(suite.Suite, expected_, r.GeoJSON(map[interface{}]interface{}{"coordinates": []interface{}{[]interface{}{[]interface{}{0, 0}, []interface{}{0, 1}, []interface{}{1, 0}, []interface{}{0, 0}}}, "type": "Polygon"}), suite.session, r.RunOpts{
   100  			GeometryFormat: "raw",
   101  			GroupFormat:    "map",
   102  		})
   103  		suite.T().Log("Finished running line #8")
   104  	}
   105  
   106  	{
   107  		// geo/geojson.yaml line #12
   108  		/* err('ReqlQueryLogicError', 'Expected type NUMBER but found ARRAY.', [0]) */
   109  		var expected_ Err = err("ReqlQueryLogicError", "Expected type NUMBER but found ARRAY.")
   110  		/* r.geojson({'coordinates':[[], 0], 'type':'Point'}) */
   111  
   112  		suite.T().Log("About to run line #12: r.GeoJSON(map[interface{}]interface{}{'coordinates': []interface{}{[]interface{}{}, 0}, 'type': 'Point', })")
   113  
   114  		runAndAssert(suite.Suite, expected_, r.GeoJSON(map[interface{}]interface{}{"coordinates": []interface{}{[]interface{}{}, 0}, "type": "Point"}), suite.session, r.RunOpts{
   115  			GeometryFormat: "raw",
   116  			GroupFormat:    "map",
   117  		})
   118  		suite.T().Log("Finished running line #12")
   119  	}
   120  
   121  	{
   122  		// geo/geojson.yaml line #14
   123  		/* err('ReqlQueryLogicError', 'Expected type ARRAY but found BOOL.', [0]) */
   124  		var expected_ Err = err("ReqlQueryLogicError", "Expected type ARRAY but found BOOL.")
   125  		/* r.geojson({'coordinates':true, 'type':'Point'}) */
   126  
   127  		suite.T().Log("About to run line #14: r.GeoJSON(map[interface{}]interface{}{'coordinates': true, 'type': 'Point', })")
   128  
   129  		runAndAssert(suite.Suite, expected_, r.GeoJSON(map[interface{}]interface{}{"coordinates": true, "type": "Point"}), suite.session, r.RunOpts{
   130  			GeometryFormat: "raw",
   131  			GroupFormat:    "map",
   132  		})
   133  		suite.T().Log("Finished running line #14")
   134  	}
   135  
   136  	{
   137  		// geo/geojson.yaml line #16
   138  		/* err('ReqlNonExistenceError', 'No attribute `coordinates` in object:', [0]) */
   139  		var expected_ Err = err("ReqlNonExistenceError", "No attribute `coordinates` in object:")
   140  		/* r.geojson({'type':'Point'}) */
   141  
   142  		suite.T().Log("About to run line #16: r.GeoJSON(map[interface{}]interface{}{'type': 'Point', })")
   143  
   144  		runAndAssert(suite.Suite, expected_, r.GeoJSON(map[interface{}]interface{}{"type": "Point"}), suite.session, r.RunOpts{
   145  			GeometryFormat: "raw",
   146  			GroupFormat:    "map",
   147  		})
   148  		suite.T().Log("Finished running line #16")
   149  	}
   150  
   151  	{
   152  		// geo/geojson.yaml line #18
   153  		/* err('ReqlNonExistenceError', 'No attribute `type` in object:', [0]) */
   154  		var expected_ Err = err("ReqlNonExistenceError", "No attribute `type` in object:")
   155  		/* r.geojson({'coordinates':[0, 0]}) */
   156  
   157  		suite.T().Log("About to run line #18: r.GeoJSON(map[interface{}]interface{}{'coordinates': []interface{}{0, 0}, })")
   158  
   159  		runAndAssert(suite.Suite, expected_, r.GeoJSON(map[interface{}]interface{}{"coordinates": []interface{}{0, 0}}), suite.session, r.RunOpts{
   160  			GeometryFormat: "raw",
   161  			GroupFormat:    "map",
   162  		})
   163  		suite.T().Log("Finished running line #18")
   164  	}
   165  
   166  	{
   167  		// geo/geojson.yaml line #20
   168  		/* err('ReqlQueryLogicError', 'Unrecognized GeoJSON type `foo`.', [0]) */
   169  		var expected_ Err = err("ReqlQueryLogicError", "Unrecognized GeoJSON type `foo`.")
   170  		/* r.geojson({'coordinates':[0, 0], 'type':'foo'}) */
   171  
   172  		suite.T().Log("About to run line #20: r.GeoJSON(map[interface{}]interface{}{'coordinates': []interface{}{0, 0}, 'type': 'foo', })")
   173  
   174  		runAndAssert(suite.Suite, expected_, r.GeoJSON(map[interface{}]interface{}{"coordinates": []interface{}{0, 0}, "type": "foo"}), suite.session, r.RunOpts{
   175  			GeometryFormat: "raw",
   176  			GroupFormat:    "map",
   177  		})
   178  		suite.T().Log("Finished running line #20")
   179  	}
   180  
   181  	{
   182  		// geo/geojson.yaml line #22
   183  		/* err('ReqlQueryLogicError', 'Unrecognized field `foo` found in geometry object.', [0]) */
   184  		var expected_ Err = err("ReqlQueryLogicError", "Unrecognized field `foo` found in geometry object.")
   185  		/* r.geojson({'coordinates':[0, 0], 'type':'Point', 'foo':'wrong'}) */
   186  
   187  		suite.T().Log("About to run line #22: r.GeoJSON(map[interface{}]interface{}{'coordinates': []interface{}{0, 0}, 'type': 'Point', 'foo': 'wrong', })")
   188  
   189  		runAndAssert(suite.Suite, expected_, r.GeoJSON(map[interface{}]interface{}{"coordinates": []interface{}{0, 0}, "type": "Point", "foo": "wrong"}), suite.session, r.RunOpts{
   190  			GeometryFormat: "raw",
   191  			GroupFormat:    "map",
   192  		})
   193  		suite.T().Log("Finished running line #22")
   194  	}
   195  
   196  	{
   197  		// geo/geojson.yaml line #26
   198  		/* ({'$reql_type$':'GEOMETRY', 'coordinates':[0, 0], 'type':'Point', 'crs':null}) */
   199  		var expected_ map[interface{}]interface{} = map[interface{}]interface{}{"$reql_type$": "GEOMETRY", "coordinates": []interface{}{0, 0}, "type": "Point", "crs": nil}
   200  		/* r.geojson({'coordinates':[0, 0], 'type':'Point', 'crs':null}) */
   201  
   202  		suite.T().Log("About to run line #26: r.GeoJSON(map[interface{}]interface{}{'coordinates': []interface{}{0, 0}, 'type': 'Point', 'crs': nil, })")
   203  
   204  		runAndAssert(suite.Suite, expected_, r.GeoJSON(map[interface{}]interface{}{"coordinates": []interface{}{0, 0}, "type": "Point", "crs": nil}), suite.session, r.RunOpts{
   205  			GeometryFormat: "raw",
   206  			GroupFormat:    "map",
   207  		})
   208  		suite.T().Log("Finished running line #26")
   209  	}
   210  
   211  	{
   212  		// geo/geojson.yaml line #30
   213  		/* err('ReqlQueryLogicError', 'GeoJSON type `MultiPoint` is not supported.', [0]) */
   214  		var expected_ Err = err("ReqlQueryLogicError", "GeoJSON type `MultiPoint` is not supported.")
   215  		/* r.geojson({'coordinates':[0, 0], 'type':'MultiPoint'}) */
   216  
   217  		suite.T().Log("About to run line #30: r.GeoJSON(map[interface{}]interface{}{'coordinates': []interface{}{0, 0}, 'type': 'MultiPoint', })")
   218  
   219  		runAndAssert(suite.Suite, expected_, r.GeoJSON(map[interface{}]interface{}{"coordinates": []interface{}{0, 0}, "type": "MultiPoint"}), suite.session, r.RunOpts{
   220  			GeometryFormat: "raw",
   221  			GroupFormat:    "map",
   222  		})
   223  		suite.T().Log("Finished running line #30")
   224  	}
   225  }