Skip to content

Commit

Permalink
Add integration tests for Bolt V3 features on previous versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ince committed Sep 20, 2018
1 parent 54de538 commit 0a75251
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 4 deletions.
64 changes: 64 additions & 0 deletions neo4j/test-integration/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,68 @@ var _ = Describe("Session", func() {
})
})

Context("V3 API on V1 & V2", func() {
var (
err error
driver neo4j.Driver
session neo4j.Session
)

metadata := map[string]interface{}{"id": 4, "name": "x"}

BeforeEach(func() {
driver, err = server.Driver()
Expect(err).To(BeNil())
Expect(driver).NotTo(BeNil())

if VersionOfDriver(driver).GreaterThanOrEqual(V3_5_0) {
Skip("this test is targeted for server versions less than neo4j 3.5.0")
}

session, err = driver.Session(neo4j.AccessModeRead)
Expect(err).To(BeNil())
Expect(session).NotTo(BeNil())
})

AfterEach(func() {
if session != nil {
session.Close()
}

if driver != nil {
driver.Close()
}
})

It("should fail when transaction timeout is set for Session.Run", func() {
_, err := session.Run("RETURN 1", nil, neo4j.WithTxTimeout(1*time.Second))
Expect(err).To(BeConnectorErrorWithCode(0x504))
})

It("should fail when transaction timeout is set for Session.ReadTransaction", func() {
_, err := session.ReadTransaction(createNodeWork("Test", nil), neo4j.WithTxTimeout(1*time.Second))
Expect(err).To(BeConnectorErrorWithCode(0x504))
})

It("should fail when transaction timeout is set for Session.WriteTransaction", func() {
_, err := session.WriteTransaction(createNodeWork("Test", nil), neo4j.WithTxTimeout(1*time.Second))
Expect(err).To(BeConnectorErrorWithCode(0x504))
})

It("should fail when transaction metadata is set for Session.Run", func() {
_, err := session.Run("RETURN 1", nil, neo4j.WithTxMetadata(metadata))
Expect(err).To(BeConnectorErrorWithCode(0x504))
})

It("should fail when transaction metadata is set for Session.ReadTransaction", func() {
_, err := session.ReadTransaction(createNodeWork("Test", nil), neo4j.WithTxMetadata(metadata))
Expect(err).To(BeConnectorErrorWithCode(0x504))
})

It("should fail when transaction metadata is set for Session.WriteTransaction", func() {
_, err := session.WriteTransaction(createNodeWork("Test", nil), neo4j.WithTxMetadata(metadata))
Expect(err).To(BeConnectorErrorWithCode(0x504))
})
})

})
26 changes: 22 additions & 4 deletions neo4j/test-integration/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
package test_integration

import (
"github.com/neo4j/neo4j-go-driver/neo4j/utils/test"
"fmt"
"time"

"github.com/neo4j-drivers/gobolt"
"github.com/neo4j/neo4j-go-driver/neo4j"
"github.com/neo4j/neo4j-go-driver/neo4j/test-integration/control"

. "github.com/neo4j/neo4j-go-driver/neo4j/utils/test"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
)

var _ = Describe("Transaction", func() {
Expand Down Expand Up @@ -108,7 +108,7 @@ var _ = Describe("Transaction", func() {
Expect(err).To(BeNil())
Expect(innerResult).To(BeEquivalentTo(1))

return nil, errors.New("some error")
return nil, fmt.Errorf("some error")
})
Expect(err).NotTo(BeNil())
Expect(createResult).To(BeNil())
Expand Down Expand Up @@ -258,8 +258,26 @@ var _ = Describe("Transaction", func() {
defer tx3.Close()

_, err := updateNodeWork("TxTimeOut", map[string]interface{}{"id": 2})(tx3)
Expect(err).To(test.BeTransientError(nil, ContainSubstring("terminated")))
Expect(err).To(BeTransientError(nil, ContainSubstring("terminated")))
})

})

FContext("V3 API on V1 & V2", func() {
BeforeEach(func() {
if VersionOfDriver(driver).GreaterThanOrEqual(V3_5_0) {
Skip("this test is targeted for server versions less than neo4j 3.5.0")
}
})

It("should fail when transaction timeout is set for Session.BeginTransaction", func() {
_, err := session.BeginTransaction(neo4j.WithTxTimeout(1 * time.Second))
Expect(err).To(BeConnectorErrorWithCode(0x504))
})

It("should fail when transaction metadata is set for Session.BeginTransaction", func() {
_, err := session.BeginTransaction(neo4j.WithTxMetadata(map[string]interface{}{"x": 1}))
Expect(err).To(BeConnectorErrorWithCode(0x504))
})
})
})
20 changes: 20 additions & 0 deletions neo4j/test-integration/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ func createNodeInTx(tx neo4j.Transaction, label string, props map[string]interfa
Expect(summary.Counters().ContainsUpdates()).To(BeTrue())
}

func createNodeWork(label string, props map[string]interface{}) neo4j.TransactionWork {
return func(tx neo4j.Transaction) (interface{}, error) {
var (
err error
result neo4j.Result
)

if len(props) > 0 {
result, err = tx.Run(fmt.Sprintf("CREATE (n:%s) SET n = $props", label), map[string]interface{}{"props": props})
} else {
result, err = tx.Run(fmt.Sprintf("CREATE (n:%s)", label), nil)
}
if err != nil {
return nil, err
}

return result.Consume()
}
}

func updateNode(session neo4j.Session, label string, newProps map[string]interface{}) {
var (
err error
Expand Down

0 comments on commit 0a75251

Please sign in to comment.