Skip to content

Commit

Permalink
Merge pull request #34 from mindstand/decoder_fix
Browse files Browse the repository at this point in the history
Decoder fix
  • Loading branch information
Eric Solender authored Jul 31, 2020
2 parents 2136adf + 6257b13 commit 300551e
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 1 deletion.
5 changes: 5 additions & 0 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ import (
func decode(result neo4j.Result, respObj interface{}) (err error) {
var rows [][]interface{}

numRows := 0
for result.Next() {
rows = append(rows, result.Record().Values())
numRows++
}

if numRows == 0 {
return ErrNotFound
}
return innerDecode(rows, respObj)
}

Expand Down
19 changes: 18 additions & 1 deletion decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,24 @@ type propsTest struct {
Props map[string]interface{} `gogm:"name=props;properties"`
}

func TestDecoder(t *testing.T) {
func TestDecode(t *testing.T) {

req := require.New(t)
req.Nil(setupInit(true, nil, &a{}, &b{}, &c{}, &f{}, &propsTest{}))

var fNode f
t1 := testResult{
empty: true,
}

req.True(errors.Is(decode(&t1, &fNode), ErrNotFound))

t1.empty = false

req.Nil(decode(&t1, &fNode))
}

func TestInnerDecode(t *testing.T) {
req := require.New(t)

req.Nil(setupInit(true, nil, &a{}, &b{}, &c{}, &f{}, &propsTest{}))
Expand Down
98 changes: 98 additions & 0 deletions test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,101 @@ func (t testPath) Relationships() []neo4j.Relationship {
}
return nodes
}

type testRecord struct {

}

func (t *testRecord) Keys() []string {
panic("implement me")
}

func (t *testRecord) Values() []interface{} {
return []interface{}{
testPath{
nodes: []*testNode{
{
labels: []string{"f"},
props: map[string]interface{}{
"uuid": "0",
},
id: 0,
},
{
labels: []string{"f"},
props: map[string]interface{}{
"uuid": "1",
},
id: 1,
},
{
labels: []string{"f"},
props: map[string]interface{}{
"uuid": "2",
},
id: 2,
},
},
relNodes: []*testRelationship{
{
id: 3,
startId: 0,
endId: 1,
_type: "test",
props: nil,
},
{
id: 4,
startId: 1,
endId: 2,
_type: "test",
props: nil,
},
},
},
}

}

func (t testRecord) Get(key string) (interface{}, bool) {
panic("implement me")
}

func (t testRecord) GetByIndex(index int) interface{} {
panic("implement me")
}

type testResult struct {
empty bool
num int
}

func (t *testResult) Keys() ([]string, error) {
panic("implement me")
}

func (t *testResult) Next() bool {
toRet := !t.empty && t.num == 0

if !t.empty {
t.num++
}

return toRet
}

func (t *testResult) Err() error {
panic("implement me")
}

func (t *testResult) Record() neo4j.Record {
return &testRecord{}
}

func (t *testResult) Summary() (neo4j.ResultSummary, error) {
panic("implement me")
}

func (t *testResult) Consume() (neo4j.ResultSummary, error) {
panic("implement me")
}

0 comments on commit 300551e

Please sign in to comment.