Skip to content

Commit 53fe58c

Browse files
authored
Merge pull request #10 from ali-ince/1.7-test-unsupported-types
Add tests for unsupported types
2 parents 5a174a1 + 1ff35a4 commit 53fe58c

2 files changed

Lines changed: 144 additions & 0 deletions

File tree

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (c) 2002-2018 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
package integration_tests
21+
22+
import (
23+
"time"
24+
25+
. "github.com/neo4j/neo4j-go-driver"
26+
"github.com/neo4j/neo4j-go-driver/internal/testing"
27+
. "github.com/onsi/ginkgo"
28+
. "github.com/onsi/gomega"
29+
)
30+
31+
var _ = Describe("Unsupported Types [V1]", func() {
32+
const (
33+
WGS84SrId int = 4326
34+
WGS843DSrId int = 4979
35+
CartesianSrId int = 7203
36+
Cartesian3DSrId int = 9157
37+
)
38+
39+
var (
40+
err error
41+
driver Driver
42+
session *Session
43+
result *Result
44+
)
45+
46+
BeforeEach(func() {
47+
driver, err = NewDriver(singleInstanceUri, BasicAuth(username, password, ""))
48+
Expect(err).To(BeNil())
49+
Expect(driver).NotTo(BeNil())
50+
51+
if VersionOfDriver(driver).GreaterThanOrEqual(V3_4_0) {
52+
Skip("this test is targeted for server version less than neo4j 3.4.0")
53+
}
54+
55+
session, err = driver.Session(AccessModeWrite)
56+
Expect(err).To(BeNil())
57+
Expect(session).NotTo(BeNil())
58+
})
59+
60+
AfterEach(func() {
61+
if session != nil {
62+
session.Close()
63+
}
64+
65+
if driver != nil {
66+
driver.Close()
67+
}
68+
})
69+
70+
testSend := func(data interface{}) {
71+
result, err = session.Run("WITH $x RETURN 1", &map[string]interface{}{"x": data})
72+
Expect(err).To(drivertest.BeConnectorErrorWithCode(0x501))
73+
Expect(err).To(drivertest.BeConnectorErrorWithDescription("unable to generate RUN message"))
74+
}
75+
76+
Context("Send", func() {
77+
It("should fail sending Point (2D)", func() {
78+
testSend(NewPoint(WGS84SrId, 1.0, 1.0))
79+
})
80+
81+
It("should fail sending Point (3D)", func() {
82+
testSend(NewPoint3D(WGS843DSrId, 1.0, 1.0, 1.0))
83+
})
84+
85+
It("should fail sending Duration", func() {
86+
testSend(DurationOf(1, 1, 1, 1))
87+
})
88+
89+
It("should fail sending Date", func() {
90+
testSend(DateOf(time.Now()))
91+
})
92+
93+
It("should fail sending LocalDateTime", func() {
94+
testSend(LocalDateTimeOf(time.Now()))
95+
})
96+
97+
It("should fail sending LocalTime", func() {
98+
testSend(LocalTimeOf(time.Now()))
99+
})
100+
101+
It("should fail sending OffsetTime", func() {
102+
testSend(OffsetTimeOf(time.Now()))
103+
})
104+
105+
It("should fail sending DateTime with Offset", func() {
106+
testSend(time.Now().In(time.FixedZone("Offset", 2400)))
107+
})
108+
109+
It("should fail sending DateTime with Zone", func() {
110+
testSend(time.Now().In(time.Local))
111+
})
112+
})
113+
})

internal/testing/omega_error_matchers.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ func BePoolFullError() types.GomegaMatcher {
6565
}
6666
}
6767

68+
func BeConnectorErrorWithState(state uint32) types.GomegaMatcher {
69+
return &connectorErrorMatcher{
70+
stateMatcher: gomega.BeNumerically("==", state),
71+
}
72+
}
73+
74+
func BeConnectorErrorWithCode(code uint32) types.GomegaMatcher {
75+
return &connectorErrorMatcher{
76+
codeMatcher: gomega.BeNumerically("==", code),
77+
}
78+
}
79+
80+
func BeConnectorErrorWithDescription(description string) types.GomegaMatcher {
81+
return &connectorErrorMatcher{
82+
descriptionMatcher: gomega.ContainSubstring(description),
83+
}
84+
}
85+
6886
func BeAuthenticationError() types.GomegaMatcher {
6987
return &connectorErrorMatcher{
7088
stateMatcher: gomega.BeEquivalentTo(4),
@@ -95,6 +113,7 @@ type poolErrorMatcher struct {
95113
type connectorErrorMatcher struct {
96114
stateMatcher types.GomegaMatcher
97115
codeMatcher types.GomegaMatcher
116+
descriptionMatcher types.GomegaMatcher
98117
}
99118

100119
func (matcher *databaseErrorMatcher) Match(actual interface{}) (success bool, err error) {
@@ -228,6 +247,10 @@ func (matcher *connectorErrorMatcher) Match(actual interface{}) (success bool, e
228247
return matcher.codeMatcher.Match(connectorError.Code())
229248
}
230249

250+
if matcher.descriptionMatcher != nil {
251+
return matcher.descriptionMatcher.Match(connectorError.Description())
252+
}
253+
231254
return true, nil
232255
}
233256

@@ -245,6 +268,10 @@ func (matcher *connectorErrorMatcher) FailureMessage(actual interface{}) (messag
245268
return fmt.Sprintf("Expected\n\t%#v\nto have its code to match %s", actual, matcher.codeMatcher.FailureMessage(connectorError.Code()))
246269
}
247270

271+
if matcher.descriptionMatcher != nil {
272+
return fmt.Sprintf("Expected\n\t%#v\nto have its description to match %s", actual, matcher.descriptionMatcher.FailureMessage(connectorError.Description()))
273+
}
274+
248275
return fmt.Sprintf("Unexpected condition in matcher")
249276
}
250277

@@ -262,5 +289,9 @@ func (matcher *connectorErrorMatcher) NegatedFailureMessage(actual interface{})
262289
return fmt.Sprintf("Expected\n\t%#v\nnot to have its code to match %s", actual, matcher.codeMatcher.FailureMessage(connectorError.Code()))
263290
}
264291

292+
if matcher.descriptionMatcher != nil {
293+
return fmt.Sprintf("Expected\n\t%#v\nnot to have its description to match %s", actual, matcher.descriptionMatcher.FailureMessage(connectorError.Description()))
294+
}
295+
265296
return fmt.Sprintf("Unexpected condition in matcher")
266297
}

0 commit comments

Comments
 (0)