diff --git a/go.mod b/go.mod index f53bf08..3a6eb71 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,17 @@ -module github.com/northwesternmutual/grammes +module github.com/Kaleidoscope-Inc/grammes go 1.13 require ( github.com/google/uuid v1.1.0 - github.com/gopherjs/gopherjs v0.0.0-20190309154008-847fc94819f9 // indirect github.com/gorilla/websocket v1.4.0 - github.com/pkg/errors v0.8.1 // indirect - github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac // indirect + github.com/northwesternmutual/grammes v1.2.0 + github.com/pkg/errors v0.9.1 // indirect github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff - github.com/stretchr/testify v1.3.0 // indirect - go.uber.org/atomic v1.3.2 // indirect - go.uber.org/multierr v1.1.0 // indirect + github.com/stretchr/testify v1.8.1 // indirect + go.uber.org/atomic v1.10.0 // indirect + go.uber.org/multierr v1.9.0 // indirect go.uber.org/zap v1.9.1 ) + +replace github.com/northwesternmutual/grammes v1.2.0 => github.com/Kaleidoscope-Inc/grammes v1.2.1-0.20230221065140-059981b86c6f diff --git a/go.sum b/go.sum index 96de978..318c8a1 100644 --- a/go.sum +++ b/go.sum @@ -1,36 +1,42 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/Kaleidoscope-Inc/grammes v1.2.1-0.20230221065140-059981b86c6f h1:8pA4TUmftwBiiD+Oalu80jW37Y6gW2aO7p+IqdcZSxc= +github.com/Kaleidoscope-Inc/grammes v1.2.1-0.20230221065140-059981b86c6f/go.mod h1:Sj+p5edaQt/FUNoNUqQfowy3IUq+WXkoFBEACWSO4AU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s= github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg= -github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gopherjs/gopherjs v0.0.0-20190309154008-847fc94819f9/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE= -github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 h1:Jpy1PXuP99tXNrhbq2BaPz9B+jNAvH1JPQQpG/9GCXY= -github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac h1:wbW+Bybf9pXxnCFAOWZTqkRjAc7rAIwo2e1ArUhiHxg= -github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c h1:Ho+uVpkel/udgjbwB5Lktg9BtvJSh2DT0Hi6LPSyI2w= -github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff h1:86HlEv0yBCry9syNuylzqznKXDK11p6D0DT596yNMys= github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff/go.mod h1:KSQcGKpxUMHk3nbYzs/tIBAM2iDooCn0BmttHOJEbLs= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= -go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= +go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o= go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/gremconnect/websocket.go b/gremconnect/websocket.go old mode 100644 new mode 100755 index 6a6bb40..a2b5c25 --- a/gremconnect/websocket.go +++ b/gremconnect/websocket.go @@ -54,8 +54,8 @@ type WebSocket struct { func (ws *WebSocket) Connect() error { var err error dialer := websocket.Dialer{ - WriteBufferSize: 1024 * 8, // Set up for large messages. - ReadBufferSize: 1024 * 8, // Set up for large messages. + WriteBufferSize: 1024 * 256, // Set up for large messages. + ReadBufferSize: 1024 * 256, // Set up for large messages. HandshakeTimeout: 5 * time.Second, } diff --git a/manager/addvertex.go b/manager/addvertex.go index ce29600..d4930cd 100644 --- a/manager/addvertex.go +++ b/manager/addvertex.go @@ -102,7 +102,15 @@ func (v *addVertexQueryManager) AddVertex(label string, properties ...interface{ query := traversal.NewTraversal().AddV(label) for i := 0; i < len(properties); i += 2 { - query.AddStep("property", properties[i], properties[i+1]) + k := properties[i] + v := properties[i+1] + switch v.(type) { + case []interface{}: + vInterfaceArray := v.([]interface{}) + query.AddSetProperty(k.(string), vInterfaceArray) + default: + query.AddStep("property", k, v) + } } return v.AddVertexByString(query.String()) diff --git a/model/vertex_query.go b/model/vertex_query.go index 3efdf37..f332671 100644 --- a/model/vertex_query.go +++ b/model/vertex_query.go @@ -212,3 +212,54 @@ func (v *Vertex) AddProperty(client queryClient, key string, value interface{}) return v.QueryRefresh(client) } + +type EdgeWithPropsAndLabel struct { + Label string + Id interface{} + Properties []interface{} +} + +func (v *Vertex) AddEdges(client queryClient, inputEdges []EdgeWithPropsAndLabel) ([]Edge, error) { + if client == nil { + return []Edge{}, gremerror.NewGrammesError("AddEdges", gremerror.ErrNilClient) + } + + var query = newTrav().V().HasID(v.ID()) + + for i, edge := range inputEdges { + if i != 0 { + query = query.OutV() + } + query = query.AddE(edge.Label).To(newTrav().V().HasID(edge.Id).Raw()) + + if len(edge.Properties)%2 != 0 { + return []Edge{}, gremerror.NewGrammesError("AddEdges", gremerror.ErrOddNumberOfParameters) + } + + if len(edge.Properties) > 0 { + for i := 0; i < len(edge.Properties); i += 2 { + query.AddStep("property", edge.Properties[i], edge.Properties[i+1]) + } + } + } + + // Execute the built command. + responses, err := client.ExecuteQuery(query) + if err != nil { + return []Edge{}, gremerror.NewQueryError("AddEdges", query.String(), err) + } + + var edges EdgeList + edgeList, err := UnmarshalEdgeList(responses) + if err != nil { + return []Edge{}, err + } + + edges.Edges = edgeList + + if len(edges.Edges) == 0 { + return []Edge{}, gremerror.NewGrammesError("AddEdges", gremerror.ErrEmptyResponse) + } + + return edges.Edges, nil +} diff --git a/model/vertex_test.go b/model/vertex_test.go index 651b2b5..82b7037 100644 --- a/model/vertex_test.go +++ b/model/vertex_test.go @@ -130,7 +130,7 @@ func TestAddEdge(t *testing.T) { Convey("Given a variable that represents the Vertex struct", t, func() { v := Vertex{Type: "tesType"} - Convey("When 'AddEdges' is called with a string and int", func() { + Convey("When 'AddEdge' is called with a string and int", func() { var client queryClient var edge Edge var tstoutVID int64 @@ -143,3 +143,29 @@ func TestAddEdge(t *testing.T) { }) }) } + +func TestAddEdges(t *testing.T) { + Convey("Given a variable that represents the Vertex struct", t, func() { + + v := Vertex{Type: "tesType"} + Convey("When 'AddEdges' is called with two edges", func() { + var client queryClient + var tstoutVID int64 + tstoutVID = 12345 + edge1 := EdgeWithPropsAndLabel{ + Label: "testLbl", + Id: tstoutVID, + Properties: []interface{}{"tstIntrf1", 7777, "tstIntrf2", 9876}, + } + edge2 := EdgeWithPropsAndLabel{ + Label: "testLb2", + Id: tstoutVID, + Properties: []interface{}{"tstIntrf1", 8888, "tstIntrf2", 5432}, + } + result, _ := v.AddEdges(client, []EdgeWithPropsAndLabel{edge1, edge2}) + Convey("Then result should equal two edges", func() { + So(result, ShouldResemble, []Edge{}) + }) + }) + }) +} diff --git a/query/traversal/addproperty.go b/query/traversal/addproperty.go old mode 100644 new mode 100755 diff --git a/query/traversal/graph.go b/query/traversal/graph.go old mode 100644 new mode 100755 diff --git a/query/traversal/pagerank_test.go b/query/traversal/pagerank_test.go index e4d48b3..bda9298 100644 --- a/query/traversal/pagerank_test.go +++ b/query/traversal/pagerank_test.go @@ -38,8 +38,8 @@ func TestPageRank(t *testing.T) { Convey("When 'PageRank' is called with one argument", func() { result := g.PageRank(1.234) - Convey("Then result should equal 'g.pageRank(1.234)'", func() { - So(result.String(), ShouldEqual, "g.pageRank(1.234)") + Convey("Then result should equal 'g.pageRank(1.234000d)'", func() { + So(result.String(), ShouldEqual, "g.pageRank(1.234000d)") }) }) diff --git a/query/traversal/skip_test.go b/query/traversal/skip_test.go index c69135a..b472e9b 100644 --- a/query/traversal/skip_test.go +++ b/query/traversal/skip_test.go @@ -39,8 +39,8 @@ func TestSkip(t *testing.T) { Convey("When 'Skip' is called with multiple extraFloat arguments", func() { result := g.Skip(scope.Local, 1.234) - Convey("Then result should equal 'g.skip(local,1.234)'", func() { - So(result.String(), ShouldEqual, "g.skip(local,1.234)") + Convey("Then result should equal 'g.skip(local,1.234000d)'", func() { + So(result.String(), ShouldEqual, "g.skip(local,1.234000d)") }) }) }) diff --git a/query/traversal/stringstep.go b/query/traversal/stringstep.go new file mode 100644 index 0000000..406a33a --- /dev/null +++ b/query/traversal/stringstep.go @@ -0,0 +1,14 @@ +package traversal + +// StringStep adds a custom string to the traversal. This is not a gremlin step. +// Added for conveninece when the grammes library does not provide a step. +// Sample usage string_step("count()") +// User is responsible for the correctness of the string. +func (g String) StringStep(traversal string) String { + g.buffer.Reset() + + g.buffer.WriteString("." + traversal) + + g.string += g.buffer.String() + return g +} diff --git a/query/traversal/stringstep_test.go b/query/traversal/stringstep_test.go new file mode 100644 index 0000000..b09da1a --- /dev/null +++ b/query/traversal/stringstep_test.go @@ -0,0 +1,46 @@ +// Copyright (c) 2018 Northwestern Mutual. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package traversal + +import ( + "testing" + + . "github.com/smartystreets/goconvey/convey" +) + +func TestStringStep(t *testing.T) { + Convey("Given a ) String { that represents the graph's traversal", t, func() { + g := NewTraversal() + Convey("When 'StringStep' is called with a string step count()", func() { + result := g.StringStep("count()") + Convey("Then result should equal 'g.count()'", func() { + So(result.String(), ShouldEqual, "g.count()") + }) + }) + + Convey("When 'StringStep' is called with a string step values()", func() { + result := g.Values() + Convey("Then result should equal 'g.values()'", func() { + So(result.String(), ShouldEqual, "g.values()") + }) + }) + }) +} diff --git a/query/traversal/timeLimit_test.go b/query/traversal/timeLimit_test.go index f3efd73..9f86217 100644 --- a/query/traversal/timeLimit_test.go +++ b/query/traversal/timeLimit_test.go @@ -31,8 +31,8 @@ func TestTimeLimit(t *testing.T) { g := NewTraversal() Convey("When 'Store' is called", func() { result := g.TimeLimit(1.234) - Convey("Then result should equal 'g.timeLimit(1.234)'", func() { - So(result.String(), ShouldEqual, "g.timeLimit(1.234)") + Convey("Then result should equal 'g.timeLimit(1.234000d)'", func() { + So(result.String(), ShouldEqual, "g.timeLimit(1.234000d)") }) }) }) diff --git a/query/traversal/util.go b/query/traversal/util.go old mode 100644 new mode 100755 index 32cd0ba..6ff2ab0 --- a/query/traversal/util.go +++ b/query/traversal/util.go @@ -88,6 +88,10 @@ func (g *String) AddStep(step string, params ...interface{}) { g.buffer.Write(t) case string: g.buffer.WriteString("\"" + strings.ReplaceAll(t, "\"", "\\\"") + "\"") + case int64, uint64: + g.buffer.WriteString(fmt.Sprintf("%dL", p)) + case float32, float64: + g.buffer.WriteString(fmt.Sprintf("%fd", p)) default: g.buffer.WriteString(fmt.Sprintf("%v", t)) } @@ -118,3 +122,33 @@ func gatherInts(params ...int) string { return "" } } + +func (g *String) AddListProperty(k string, v []string) { + g.buffer.Reset() + + for _, vv := range v { + g.buffer.WriteString(fmt.Sprintf(".property(list, \"%s\", \"%s\")", k, vv)) + } + g.string += g.buffer.String() +} + +func (g *String) AddSetProperty(k string, v []interface{}) { + g.buffer.Reset() + + for _, vv := range v { + switch value := vv.(type) { + case float64, float32: + g.buffer.WriteString(fmt.Sprintf(`.property(set, "%s", %fd)`, k, value)) + case int64: + g.buffer.WriteString(fmt.Sprintf(`.property(set, "%s", %dL)`, k, value)) + case int, bool: + g.buffer.WriteString(fmt.Sprintf(".property(set, \"%s\", %v)", k, value)) + case string: + g.buffer.WriteString(fmt.Sprintf(".property(set, \"%s\", \"%s\")", k, value)) + default: + g.buffer.WriteString(fmt.Sprintf(".property(set, \"%s\", \"%s\")", k, value)) + } + } + + g.string += g.buffer.String() +} diff --git a/query/traversal/util_test.go b/query/traversal/util_test.go index de9bc6c..b993d4e 100644 --- a/query/traversal/util_test.go +++ b/query/traversal/util_test.go @@ -56,8 +56,8 @@ func TestAddStep(t *testing.T) { Convey("When AddStep is called with int64", func() { i := int64(1234) g.AddStep("test", i) - Convey("Then g should equal g.test(1234)", func() { - So(g.String(), ShouldEqual, "g.test(1234)") + Convey("Then g should equal g.test(1234L)", func() { + So(g.String(), ShouldEqual, "g.test(1234L)") }) }) @@ -65,7 +65,7 @@ func TestAddStep(t *testing.T) { i := float64(1.234) g.AddStep("test", i) Convey("Then g should equal g.test(1.234)", func() { - So(g.String(), ShouldEqual, "g.test(1.234)") + So(g.String(), ShouldEqual, "g.test(1.234000d)") }) }) @@ -126,3 +126,44 @@ func TestGatherInts(t *testing.T) { }) }) } + +func TestAddListProperty(t *testing.T) { + Convey("Given a graph traversal", t, func() { + g := NewTraversal() + Convey("When AddListProperty is called with a key and zero properties", func() { + g.AddListProperty("key1", []string{}) + Convey("Then g should equal g", func() { + So(g.String(), ShouldEqual, "g") + }) + }) + + Convey("When AddListProperty is called with a key and 2 properties", func() { + g.AddListProperty("key1", []string{"value1", "value2"}) + Convey("Then g should equal g.property(list, \"key1\", \"value1\").property(list, \"key1\", \"value2\")", func() { + So(g.String(), ShouldEqual, "g.property(list, \"key1\", \"value1\").property(list, \"key1\", \"value2\")") + }) + }) + }) +} + +func TestAddSetProperty(t *testing.T) { + Convey("Given a graph traversal", t, func() { + g := NewTraversal() + Convey("When AddSetProperty is called with a key and zero properties", func() { + var zeroProps []interface{} + g.AddSetProperty("key1", zeroProps) + Convey("Then g should equal g", func() { + So(g.String(), ShouldEqual, "g") + }) + }) + + Convey("When AddSetProperty is called with a key and 6 properties of different types", func() { + var props []interface{} + props = append(props, "value1", 3.4e+38, 1.7e+308, 9223372036854775807, 1, true) + g.AddSetProperty("key1", props) + Convey("Then g should equal g.property(set, \"key1\", \"value1\").property(set, \"key1\", 339999999999999996123846586046231871488.000000d).property(set, \"key1\", 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000d).property(set, \"key1\", 9223372036854775807).property(set, \"key1\", 1).property(set, \"key1\", true)", func() { + So(g.String(), ShouldEqual, "g.property(set, \"key1\", \"value1\").property(set, \"key1\", 339999999999999996123846586046231871488.000000d).property(set, \"key1\", 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000d).property(set, \"key1\", 9223372036854775807).property(set, \"key1\", 1).property(set, \"key1\", true)") + }) + }) + }) +} diff --git a/query/traversal/withsack_test.go b/query/traversal/withsack_test.go index 1e9360e..149856b 100644 --- a/query/traversal/withsack_test.go +++ b/query/traversal/withsack_test.go @@ -31,8 +31,8 @@ func TestWithSack(t *testing.T) { g := NewTraversal() Convey("When WithSack is called with float", func() { result := g.WithSack(1.234) - Convey("Then result should equal g.withSack(1.234)", func() { - So(result.String(), ShouldEqual, "g.withSack(1.234)") + Convey("Then result should equal g.withSack(1.234000d)", func() { + So(result.String(), ShouldEqual, "g.withSack(1.234000d)") }) }) })