Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
damienfamed75 committed Sep 22, 2019
1 parent b974e37 commit ebc35e4
Show file tree
Hide file tree
Showing 23 changed files with 297 additions and 4,182 deletions.
10 changes: 5 additions & 5 deletions examples/vertex-properties-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package main

import (
"encoding/json"
"flag"
"fmt"

Expand Down Expand Up @@ -92,14 +91,15 @@ func main() {
logger.Fatal("Querying error", zap.Error(err))
}

var props grammes.PropertyList

// Unmarshal raw data into a PropertyList
json.Unmarshal(res, &props)
props, err := grammes.UnmarshalPropertyList(res)
if err != nil {
fmt.Printf("error unmarshalling data: %s", err.Error())
}

// Print out columns of the received data.
fmt.Printf("%-20s %-8s\n", "Label", "Value")
for _, p := range props.Properties {
for _, p := range props {
fmt.Printf("%#-20v %#-8v\n", p.Value.Label, p.GetValue())
}
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/northwesternmutual/grammes

go 1.13

require (
github.com/google/uuid v1.1.0
github.com/gopherjs/gopherjs v0.0.0-20190309154008-847fc94819f9 // indirect
Expand Down
8 changes: 6 additions & 2 deletions grammes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func Example_executeQuery() {
}

// Print out the result as a string
log.Println(string(res))
for _, r := range res {
log.Println(string(r))
}
}

func Example_executeStringQuery() {
Expand All @@ -71,5 +73,7 @@ func Example_executeStringQuery() {
}

// Print out the result as a string
log.Println(string(res))
for _, r := range res {
log.Println(string(r))
}
}
40 changes: 20 additions & 20 deletions manager/addvertex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (mockQuery) String() string { return "TEST" }

func TestAddAPIVertex(t *testing.T) {
Convey("Given a string executor and vertex query manager", t, func() {
execute := func(string) ([]byte, error) { return []byte(vertexResponse), nil }
qm := newAddVertexQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return [][]byte{[]byte(vertexResponse)}, nil }
qm := newAddVertexQueryManager(logging.NewNilLogger(), execute)
Convey("When AddAPIVertex is called", func() {
var data model.APIData
data.Properties = map[string]string{"testkey": "testval"}
Expand All @@ -84,8 +84,8 @@ func TestAddAPIVertex(t *testing.T) {

func TestAddAPIVertexError(t *testing.T) {
Convey("Given a string executor and vertex query manager", t, func() {
execute := func(string) ([]byte, error) { return nil, errors.New("ERROR") }
qm := newAddVertexQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return nil, errors.New("ERROR") }
qm := newAddVertexQueryManager(logging.NewNilLogger(), execute)
Convey("When AddAPIVertex is called and an error occurs", func() {
var data model.APIData
_, err := qm.AddAPIVertex(data)
Expand All @@ -98,8 +98,8 @@ func TestAddAPIVertexError(t *testing.T) {

func TestAddVertexByStruct(t *testing.T) {
Convey("Given a string executor and vertex query manager", t, func() {
execute := func(string) ([]byte, error) { return []byte(vertexResponse), nil }
qm := newAddVertexQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return [][]byte{[]byte(vertexResponse)}, nil }
qm := newAddVertexQueryManager(logging.NewNilLogger(), execute)
Convey("When AddVertexByStruct is called", func() {
res, _ := qm.AddVertexByStruct(testVertex)
Convey("Then the return vertex ID value should be 28720", func() {
Expand All @@ -111,8 +111,8 @@ func TestAddVertexByStruct(t *testing.T) {

func TestAddVertexByStructError(t *testing.T) {
Convey("Given a string executor and vertex query manager", t, func() {
execute := func(string) ([]byte, error) { return nil, errors.New("ERROR") }
qm := newAddVertexQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return nil, errors.New("ERROR") }
qm := newAddVertexQueryManager(logging.NewNilLogger(), execute)
Convey("When AddVertexByStruct is called and an error is thrown", func() {
_, err := qm.AddVertexByStruct(testVertex)
Convey("Then the error should be returned", func() {
Expand All @@ -124,8 +124,8 @@ func TestAddVertexByStructError(t *testing.T) {

func TestAddVertexError(t *testing.T) {
Convey("Given a string executor and vertex query manager", t, func() {
execute := func(string) ([]byte, error) { return []byte(vertexResponse), nil }
qm := newAddVertexQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return [][]byte{[]byte(vertexResponse)}, nil }
qm := newAddVertexQueryManager(logging.NewNilLogger(), execute)
Convey("When AddVertex is called with an odd number of parameters", func() {
_, err := qm.AddVertex("testLabel", "prop1")
Convey("Then the error should be returned", func() {
Expand All @@ -137,8 +137,8 @@ func TestAddVertexError(t *testing.T) {

func TestAddVertexLabels(t *testing.T) {
Convey("Given a string executor and vertex query manager", t, func() {
execute := func(string) ([]byte, error) { return []byte(vertexResponse), nil }
qm := newAddVertexQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return [][]byte{[]byte(vertexResponse)}, nil }
qm := newAddVertexQueryManager(logging.NewNilLogger(), execute)
Convey("When AddVertexLabels is called", func() {
_, err := qm.AddVertexLabels("testlabel")
Convey("Then the error returned should be nil", func() {
Expand All @@ -150,8 +150,8 @@ func TestAddVertexLabels(t *testing.T) {

func TestAddVertexLabelsQueryError(t *testing.T) {
Convey("Given a string executor and vertex query manager", t, func() {
execute := func(string) ([]byte, error) { return nil, errors.New("ERROR") }
qm := newAddVertexQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return nil, errors.New("ERROR") }
qm := newAddVertexQueryManager(logging.NewNilLogger(), execute)
Convey("When AddVertexLabels is called and encounters a querying error", func() {
_, err := qm.AddVertexLabels("testlabel")
Convey("Then the error should be returned", func() {
Expand All @@ -163,8 +163,8 @@ func TestAddVertexLabelsQueryError(t *testing.T) {

func TestAddVertexByQuery(t *testing.T) {
Convey("Given a string executor and vertex query manager", t, func() {
execute := func(string) ([]byte, error) { return []byte(vertexResponse), nil }
qm := newAddVertexQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return [][]byte{[]byte(vertexResponse)}, nil }
qm := newAddVertexQueryManager(logging.NewNilLogger(), execute)
Convey("When AddVertexByQuery is called", func() {
var q mockQuery
res, _ := qm.AddVertexByQuery(q)
Expand All @@ -181,8 +181,8 @@ func TestAddVertexByStringJsonUnmarshalError(t *testing.T) {
}()
jsonUnmarshal = func([]byte, interface{}) error { return errors.New("ERROR") }
Convey("Given a string executor and vertex query manager", t, func() {
execute := func(string) ([]byte, error) { return []byte(vertexResponse), nil }
qm := newAddVertexQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return [][]byte{[]byte(vertexResponse)}, nil }
qm := newAddVertexQueryManager(logging.NewNilLogger(), execute)
Convey("When AddVertexByString throws an error while unmarshalling", func() {
_, err := qm.AddVertexByString("testquery")
Convey("Then the error should be returned", func() {
Expand All @@ -198,8 +198,8 @@ func TestAddVertexByStringReturnnilVertex(t *testing.T) {
}()
jsonUnmarshal = func([]byte, interface{}) error { return nil }
Convey("Given a string executor and vertex query manager", t, func() {
execute := func(string) ([]byte, error) { return []byte(vertexResponse), nil }
qm := newAddVertexQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return [][]byte{[]byte(vertexResponse)}, nil }
qm := newAddVertexQueryManager(logging.NewNilLogger(), execute)
Convey("When AddVertexByString is called and no vertices are added", func() {
res, _ := qm.AddVertexByString("testquery")
Convey("Then the return value should be the nil vertex", func() {
Expand Down
32 changes: 16 additions & 16 deletions manager/dropvertex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (

func TestDropVertexLabel(t *testing.T) {
Convey("Given a string executor and drop query manager", t, func() {
execute := func(string) ([]byte, error) { return nil, nil }
dm := newDropQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return nil, nil }
dm := newDropQueryManager(logging.NewNilLogger(), execute)
Convey("When DropVertexLabel is called", func() {
err := dm.DropVertexLabel("testlabel")
Convey("The return error should be nil", func() {
Expand All @@ -44,8 +44,8 @@ func TestDropVertexLabel(t *testing.T) {

func TestDropVertexLabelError(t *testing.T) {
Convey("Given a string executor and drop query manager", t, func() {
execute := func(string) ([]byte, error) { return nil, errors.New("ERROR") }
dm := newDropQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return nil, errors.New("ERROR") }
dm := newDropQueryManager(logging.NewNilLogger(), execute)
Convey("When DropVertexLabel is called and encounters an error", func() {
err := dm.DropVertexLabel("testlabel")
Convey("Then the error should be returned", func() {
Expand All @@ -57,8 +57,8 @@ func TestDropVertexLabelError(t *testing.T) {

func TestDropVertexByID(t *testing.T) {
Convey("Given a string executor and drop query manager", t, func() {
execute := func(string) ([]byte, error) { return nil, nil }
dm := newDropQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return nil, nil }
dm := newDropQueryManager(logging.NewNilLogger(), execute)
Convey("When DropVertexByID is called", func() {
err := dm.DropVertexByID(1234)
Convey("Then the return error should be nil", func() {
Expand All @@ -70,8 +70,8 @@ func TestDropVertexByID(t *testing.T) {

func TestDropVertexByIDError(t *testing.T) {
Convey("Given a string executor and drop query manager", t, func() {
execute := func(string) ([]byte, error) { return nil, errors.New("ERROR") }
dm := newDropQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return nil, errors.New("ERROR") }
dm := newDropQueryManager(logging.NewNilLogger(), execute)
Convey("When DropVertexByID is called and encounters an error", func() {
err := dm.DropVertexByID(1234)
Convey("Then the error should be returned", func() {
Expand All @@ -83,8 +83,8 @@ func TestDropVertexByIDError(t *testing.T) {

func TestDropVerticesByString(t *testing.T) {
Convey("Given a string executor and drop query manager", t, func() {
execute := func(string) ([]byte, error) { return nil, nil }
dm := newDropQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return nil, nil }
dm := newDropQueryManager(logging.NewNilLogger(), execute)
Convey("When DropVertexByString is called", func() {
err := dm.DropVerticesByString("testquery")
Convey("Then the return error should be nil", func() {
Expand All @@ -96,8 +96,8 @@ func TestDropVerticesByString(t *testing.T) {

func TestDropVerticesByStringError(t *testing.T) {
Convey("Given a string executor and drop query manager", t, func() {
execute := func(string) ([]byte, error) { return nil, errors.New("ERROR") }
dm := newDropQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return nil, errors.New("ERROR") }
dm := newDropQueryManager(logging.NewNilLogger(), execute)
Convey("When DropVertexByString is called and encounters an error", func() {
err := dm.DropVerticesByString("testquery")
Convey("Then the error should be returned", func() {
Expand All @@ -109,8 +109,8 @@ func TestDropVerticesByStringError(t *testing.T) {

func TestDropVerticesByQuery(t *testing.T) {
Convey("Given a string executor and drop query manager", t, func() {
execute := func(string) ([]byte, error) { return nil, nil }
dm := newDropQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return nil, nil }
dm := newDropQueryManager(logging.NewNilLogger(), execute)
Convey("When DropVertexByQuery is called", func() {
var q mockQuery
err := dm.DropVerticesByQuery(q)
Expand All @@ -123,8 +123,8 @@ func TestDropVerticesByQuery(t *testing.T) {

func TestDropVerticesByQueryError(t *testing.T) {
Convey("Given a string executor and drop query manager", t, func() {
execute := func(string) ([]byte, error) { return nil, errors.New("ERROR") }
dm := newDropQueryManager(logging.NewBasicLogger(), execute)
execute := func(string) ([][]byte, error) { return nil, errors.New("ERROR") }
dm := newDropQueryManager(logging.NewNilLogger(), execute)
Convey("When DropVertexByQuery is called and encounters an error", func() {
var q mockQuery
err := dm.DropVerticesByQuery(q)
Expand Down
Loading

0 comments on commit ebc35e4

Please sign in to comment.