From 0a7525159615432ff17753e4934bdeffcddae2af Mon Sep 17 00:00:00 2001 From: Ali Ince Date: Thu, 20 Sep 2018 12:02:49 +0100 Subject: [PATCH] Add integration tests for Bolt V3 features on previous versions --- neo4j/test-integration/session_test.go | 64 ++++++++++++++++++++++ neo4j/test-integration/transaction_test.go | 26 +++++++-- neo4j/test-integration/utils_test.go | 20 +++++++ 3 files changed, 106 insertions(+), 4 deletions(-) diff --git a/neo4j/test-integration/session_test.go b/neo4j/test-integration/session_test.go index 71613424..455444c9 100644 --- a/neo4j/test-integration/session_test.go +++ b/neo4j/test-integration/session_test.go @@ -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)) + }) + }) + }) diff --git a/neo4j/test-integration/transaction_test.go b/neo4j/test-integration/transaction_test.go index 060a0140..76d463c7 100644 --- a/neo4j/test-integration/transaction_test.go +++ b/neo4j/test-integration/transaction_test.go @@ -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() { @@ -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()) @@ -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)) + }) + }) }) diff --git a/neo4j/test-integration/utils_test.go b/neo4j/test-integration/utils_test.go index 692faa91..3c85137c 100644 --- a/neo4j/test-integration/utils_test.go +++ b/neo4j/test-integration/utils_test.go @@ -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