Skip to content

Commit cbd9012

Browse files
authored
[Bugfix] 3.7.2 Cluster backup fixes (#280)
1 parent 82b41b0 commit cbd9012

7 files changed

+184
-29
lines changed

go.mod

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ module github.com/arangodb/go-driver
22

33
go 1.12
44

5-
replace github.com/arangodb/go-driver/v2 => ./v2
6-
75
require (
8-
github.com/arangodb/go-driver/v2 v2.0.0-00010101000000-000000000000
96
github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e
107
github.com/coreos/go-iptables v0.4.3
118
github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9
129
github.com/dgrijalva/jwt-go v3.2.0+incompatible
1310
github.com/google/addlicense v0.0.0-20200817051935-6f4cd4aacc89 // indirect
1411
github.com/google/uuid v1.1.1
1512
github.com/pkg/errors v0.9.1
16-
github.com/rs/zerolog v1.19.0
13+
github.com/rs/zerolog v1.19.0 // indirect
1714
github.com/stretchr/testify v1.5.1
1815
golang.org/x/tools v0.0.0-20200818005847-188abfa75333 // indirect
1916
)

test/backup_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ func TestBackupCreateWithLabel(t *testing.T) {
176176
func TestBackupCreateWithAllowInconsistent(t *testing.T) {
177177
c := createClientFromEnv(t, true)
178178
skipIfNoBackup(c, t)
179+
180+
EnsureVersion(t, context.Background(), c).Enterprise().NotCluster().
181+
CheckVersion(BelowPatchRelease("3.7.2")).
182+
CheckVersion(BelowPatchRelease("3.6.6"))
183+
179184
var wg sync.WaitGroup
180185
defer func() {
181186
wg.Wait()

test/collection_schema_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestCollectionSchema(t *testing.T) {
4848
ctx, cancel := context.WithCancel(context.Background())
4949
defer cancel()
5050

51-
EnsureVersion(t, ctx, c).MinimumVersion("3.7.0")
51+
EnsureVersion(t, ctx, c).CheckVersion(MinimumVersion("3.7.0"))
5252

5353
name := "document_schema_validation_test"
5454
db := ensureDatabase(nil, c, name, nil, t)

test/documents_create_overwrite_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestCreateOverwriteDocument(t *testing.T) {
4747
ctx, cancel := context.WithCancel(context.Background())
4848
defer cancel()
4949

50-
EnsureVersion(t, ctx, c).MinimumVersion("3.7.0")
50+
EnsureVersion(t, ctx, c).CheckVersion(MinimumVersion("3.7.0"))
5151

5252
db := ensureDatabase(nil, c, "document_test", nil, t)
5353
col := ensureCollection(nil, db, "document_test", nil, t)

test/graph_creation_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func TestGraphCreation(t *testing.T) {
184184
ctx := context.Background()
185185

186186
c := createClientFromEnv(t, true)
187-
EnsureVersion(t, ctx, c).MinimumVersion("3.7.0").Cluster().Enterprise()
187+
EnsureVersion(t, ctx, c).CheckVersion(MinimumVersion("3.7.0")).Cluster().Enterprise()
188188

189189
t.Run("Satellite", func(t *testing.T) {
190190
db := ensureDatabase(ctx, c, databaseName("graph", "create", "defaults"), nil, t)
@@ -195,6 +195,8 @@ func TestGraphCreation(t *testing.T) {
195195
options, collections := newGraphOpts(db)
196196

197197
options.ReplicationFactor = driver.SatelliteGraph
198+
options.IsSmart = false
199+
options.SmartGraphAttribute = ""
198200

199201
g, err := db.CreateGraph(ctx, graphID, &options)
200202
require.NoError(t, err)
@@ -214,6 +216,8 @@ func TestGraphCreation(t *testing.T) {
214216
options, collections := newGraphOpts(db)
215217

216218
options.ReplicationFactor = driver.SatelliteGraph
219+
options.IsSmart = false
220+
options.SmartGraphAttribute = ""
217221

218222
g, err := db.CreateGraph(ctx, graphID, &options)
219223
require.NoError(t, err)

test/version.go

+26-22
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package test
2424

2525
import (
2626
"context"
27+
"fmt"
2728
"testing"
2829

2930
"github.com/arangodb/go-driver"
@@ -69,36 +70,31 @@ type VersionCheck struct {
6970
mode mode
7071
}
7172

72-
func (v VersionCheck) MinimumVersion(version driver.Version) VersionCheck {
73-
v.t.Logf("Minimum version required: %s", version)
74-
if v.version.CompareTo(version) < 0 {
75-
v.t.Skipf("Required version ArangoDB(%s) >= Expected(%s)", v.version, version)
73+
func (v VersionCheck) CheckVersion(check VersionChecker) VersionCheck {
74+
v.t.Logf("Version check: %s", check.String(v.version))
75+
if !check.Check(v.version) {
76+
v.t.Skipf("Version check failed: %s", check.String(v.version))
7677
}
78+
7779
return v
7880
}
7981

80-
func (v VersionCheck) MaximumVersion(version driver.Version) VersionCheck {
81-
v.t.Logf("Maximum version required: %s", version)
82-
if v.version.CompareTo(version) > 0 {
83-
v.t.Skipf("Required version ArangoDB(%s) <= Expected(%s)", v.version, version)
84-
}
85-
return v
82+
func AbovePatchRelease(version driver.Version) VersionChecker {
83+
currMinor := driver.Version(fmt.Sprintf("%d.%d.0", version.Major(), version.Minor()))
84+
nextMinor := driver.Version(fmt.Sprintf("%d.%d.0", version.Major(), version.Minor()+1))
85+
86+
return LT.Than(currMinor).Or(GE.Than(nextMinor)).Or(LT.Than(nextMinor).And(GE.Than(version)))
8687
}
8788

88-
func (v VersionCheck) AboveVersion(version driver.Version) VersionCheck {
89-
v.t.Logf("Above version required: %s", version)
90-
if v.version.CompareTo(version) <= 0 {
91-
v.t.Skipf("Required version ArangoDB(%s) > Expected(%s)", v.version, version)
92-
}
93-
return v
89+
func BelowPatchRelease(version driver.Version) VersionChecker {
90+
currMinor := driver.Version(fmt.Sprintf("%d.%d.0", version.Major(), version.Minor()))
91+
nextMinor := driver.Version(fmt.Sprintf("%d.%d.0", version.Major(), version.Minor()+1))
92+
93+
return LT.Than(currMinor).Or(GE.Than(nextMinor)).Or(LT.Than(nextMinor).And(LT.Than(version)))
9494
}
9595

96-
func (v VersionCheck) BelowVersion(version driver.Version) VersionCheck {
97-
v.t.Logf("Below version required: %s", version)
98-
if v.version.CompareTo(version) >= 0 {
99-
v.t.Skipf("Required version ArangoDB(%s) < Expected(%s)", v.version, version)
100-
}
101-
return v
96+
func MinimumVersion(version driver.Version) VersionChecker {
97+
return GE.Than(version)
10298
}
10399

104100
func (v VersionCheck) Enterprise() VersionCheck {
@@ -124,3 +120,11 @@ func (v VersionCheck) Cluster() VersionCheck {
124120
}
125121
return v
126122
}
123+
124+
func (v VersionCheck) NotCluster() VersionCheck {
125+
v.t.Logf("Skipping cluster mode")
126+
if v.mode == cluster {
127+
v.t.Skipf("Test should not run on cluster")
128+
}
129+
return v
130+
}

test/version_compare.go

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Adam Janikowski
21+
//
22+
23+
package test
24+
25+
import (
26+
"fmt"
27+
28+
"github.com/arangodb/go-driver"
29+
)
30+
31+
type Operator string
32+
33+
const (
34+
AND Operator = "AND"
35+
OR Operator = "OR"
36+
)
37+
38+
type Compare string
39+
40+
const (
41+
GT Compare = ">"
42+
GE Compare = ">="
43+
LT Compare = "<"
44+
LE Compare = "<="
45+
EQ Compare = "=="
46+
NE Compare = "!="
47+
)
48+
49+
func (c Compare) Compare(a, b driver.Version) bool {
50+
switch c {
51+
case GT:
52+
return a.CompareTo(b) > 0
53+
case GE:
54+
return a.CompareTo(b) >= 0
55+
case LT:
56+
return a.CompareTo(b) < 0
57+
case LE:
58+
return a.CompareTo(b) <= 0
59+
case EQ:
60+
return a.CompareTo(b) == 0
61+
case NE:
62+
return a.CompareTo(b) != 0
63+
default:
64+
return false
65+
}
66+
}
67+
68+
func (c Compare) Than(a driver.Version) VersionChecker {
69+
return &basicVersionChecker{
70+
Compare: c,
71+
Version: a,
72+
}
73+
}
74+
75+
type VersionChecker interface {
76+
Or(v VersionChecker) VersionChecker
77+
And(v VersionChecker) VersionChecker
78+
Check(version driver.Version) bool
79+
String(version driver.Version) string
80+
}
81+
82+
var _ VersionChecker = &basicVersionChecker{}
83+
84+
type basicVersionChecker struct {
85+
Version driver.Version
86+
Compare Compare
87+
}
88+
89+
func (b basicVersionChecker) Or(v VersionChecker) VersionChecker {
90+
return &mergedVersionChecker{
91+
A: b,
92+
B: v,
93+
Operator: OR,
94+
}
95+
}
96+
97+
func (b basicVersionChecker) And(v VersionChecker) VersionChecker {
98+
return &mergedVersionChecker{
99+
A: b,
100+
B: v,
101+
Operator: AND,
102+
}
103+
}
104+
105+
func (b basicVersionChecker) Check(version driver.Version) bool {
106+
return b.Compare.Compare(version, b.Version)
107+
}
108+
109+
func (b basicVersionChecker) String(version driver.Version) string {
110+
return fmt.Sprintf("[%s] %s %s", version, b.Compare, b.Version)
111+
}
112+
113+
var _ VersionChecker = &mergedVersionChecker{}
114+
115+
type mergedVersionChecker struct {
116+
A, B VersionChecker
117+
Operator Operator
118+
}
119+
120+
func (m mergedVersionChecker) Or(v VersionChecker) VersionChecker {
121+
return &mergedVersionChecker{
122+
A: m,
123+
B: v,
124+
Operator: OR,
125+
}
126+
}
127+
128+
func (m mergedVersionChecker) And(v VersionChecker) VersionChecker {
129+
return &mergedVersionChecker{
130+
A: m,
131+
B: v,
132+
Operator: AND,
133+
}
134+
}
135+
136+
func (m mergedVersionChecker) Check(version driver.Version) bool {
137+
if m.Operator == OR {
138+
return m.A.Check(version) || m.B.Check(version)
139+
}
140+
return m.A.Check(version) && m.B.Check(version)
141+
}
142+
143+
func (m mergedVersionChecker) String(version driver.Version) string {
144+
return fmt.Sprintf("(%s) %s (%s)", m.A.String(version), m.Operator, m.B.String(version))
145+
}

0 commit comments

Comments
 (0)