Skip to content

Commit b083262

Browse files
committed
Create more reliable collection shards test
1 parent b9cbd1e commit b083262

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

33
## [master](https://github.com/arangodb/go-driver/tree/master) (N/A)
4+
- Add support for fetching shards' info by the given collection name.
45

56
## [1.2.0](https://github.com/arangodb/go-driver/tree/1.2.0) (2021-08-04)
67
- Add support for AQL, Pipeline, Stopwords, GeoJSON and GeoPoint Arango Search analyzers.

test/collection_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ func Test_CollectionShards(t *testing.T) {
972972
t.Skipf("Not a cluster mode")
973973
}
974974

975-
databaseName := getThisFunctionName()
975+
databaseName := getCallerFunctionName()
976976
c := createClientFromEnv(t, true)
977977
db := ensureDatabase(nil, c, databaseName, nil, t)
978978
name := "test_collection_set_properties"
@@ -984,11 +984,27 @@ func Test_CollectionShards(t *testing.T) {
984984

985985
shards, err := col.Shards(context.Background(), true)
986986
require.NoError(t, err)
987+
assert.NotEmpty(t, shards.ID)
988+
assert.Equal(t, name, shards.Name)
989+
assert.NotEmpty(t, shards.Status)
990+
assert.Equal(t, driver.CollectionTypeDocument, shards.Type)
991+
assert.Equal(t, false, shards.IsSystem)
992+
assert.NotEmpty(t, shards.GloballyUniqueId)
993+
assert.Equal(t, false, shards.CacheEnabled)
994+
assert.Equal(t, false, shards.IsSmart)
995+
assert.Equal(t, driver.KeyGeneratorTraditional, shards.KeyOptions.Type)
996+
assert.Equal(t, true, shards.KeyOptions.AllowUserKeys)
997+
assert.Equal(t, 2, shards.NumberOfShards)
998+
assert.Equal(t, driver.ShardingStrategyHash, shards.ShardingStrategy)
999+
assert.Equal(t, []string{"_key"}, shards.ShardKeys)
9871000
require.Len(t, shards.Shards, 2, "expected 2 shards")
9881001
var leaders []driver.ServerID
9891002
for _, dbServers := range shards.Shards {
9901003
require.Lenf(t, dbServers, 2, "expected 2 DB servers for the shard")
9911004
leaders = append(leaders, dbServers[0])
9921005
}
9931006
assert.NotEqualf(t, leaders[0], leaders[1], "the leader shard can not be on the same server")
1007+
assert.Equal(t, 2, shards.ReplicationFactor)
1008+
assert.Equal(t, false, shards.WaitForSync)
1009+
assert.Equal(t, 1, shards.WriteConcern)
9941010
}

test/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ func min(max int, ints ...int) int {
215215
return z
216216
}
217217

218-
// getThisFunctionName returns the name of the function of the caller.
219-
func getThisFunctionName() string {
218+
// getCallerFunctionName returns the name of the function of the caller.
219+
func getCallerFunctionName() string {
220220
programCounters := make([]uintptr, 10)
221221
// skip this function and 'runtime.Callers' function
222222
runtime.Callers(2, programCounters)

v2/tests/database_collection_operations_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,29 @@ func Test_CollectionShards(t *testing.T) {
5252
shards, err := col.Shards(context.Background(), true)
5353
require.NoError(t, err)
5454

55+
assert.NotEmpty(t, shards.ID)
56+
assert.Equal(t, col.Name(), shards.Name)
57+
assert.NotEmpty(t, shards.Status)
58+
assert.Equal(t, arangodb.CollectionTypeDocument, shards.Type)
59+
assert.Equal(t, false, shards.IsSystem)
60+
assert.NotEmpty(t, shards.GloballyUniqueId)
61+
assert.Equal(t, false, shards.CacheEnabled)
62+
assert.Equal(t, false, shards.IsSmart)
63+
assert.Equal(t, arangodb.KeyGeneratorTraditional, shards.KeyOptions.Type)
64+
assert.Equal(t, true, shards.KeyOptions.AllowUserKeys)
65+
assert.Equal(t, 2, shards.NumberOfShards)
66+
assert.Equal(t, arangodb.ShardingStrategyHash, shards.ShardingStrategy)
67+
assert.Equal(t, []string{"_key"}, shards.ShardKeys)
5568
require.Len(t, shards.Shards, 2, "expected 2 shards")
5669
var leaders []arangodb.ServerID
57-
5870
for _, dbServers := range shards.Shards {
5971
require.Lenf(t, dbServers, 2, "expected 2 DB servers for the shard")
6072
leaders = append(leaders, dbServers[0])
6173
}
6274
assert.NotEqualf(t, leaders[0], leaders[1], "the leader shard can not be on the same server")
75+
assert.Equal(t, 2, shards.ReplicationFactor)
76+
assert.Equal(t, false, shards.WaitForSync)
77+
assert.Equal(t, 1, shards.WriteConcern)
6378
})
6479
})
6580
})

0 commit comments

Comments
 (0)