Add test for parsing times and records within json

This commit is contained in:
Tobie Morgan Hitchcock 2018-01-10 14:54:09 +00:00
parent 2f23e84877
commit d0d1316449

View file

@ -15,8 +15,11 @@
package db package db
import ( import (
"time"
"testing" "testing"
"github.com/abcum/surreal/sql"
"github.com/abcum/surreal/util/data" "github.com/abcum/surreal/util/data"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
) )
@ -634,4 +637,28 @@ func TestUpdate(t *testing.T) {
}) })
Convey("Update a set of records using CONTENT with embedded times / records", t, func() {
clock, _ := time.Parse(time.RFC3339, "1987-06-22T08:00:00.123456789Z")
setupDB()
txt := `
USE NS test DB test;
CREATE person:test CONTENT {"time":"1987-06-22T08:00:00.123456789Z","test":"person:other"};
SELECT * FROM person;
`
res, err := Execute(setupKV(), txt, nil)
So(err, ShouldBeNil)
So(res, ShouldHaveLength, 3)
So(res[1].Result, ShouldHaveLength, 1)
So(data.Consume(res[1].Result[0]).Get("time").Data(), ShouldEqual, clock)
So(data.Consume(res[1].Result[0]).Get("test").Data(), ShouldResemble, sql.NewThing("person", "other"))
So(res[2].Result, ShouldHaveLength, 1)
So(data.Consume(res[2].Result[0]).Get("time").Data(), ShouldEqual, clock)
So(data.Consume(res[2].Result[0]).Get("test").Data(), ShouldResemble, sql.NewThing("person", "other"))
})
} }