diff --git a/test/agency_test.go b/test/agency_test.go index 5f5287a5..384eba69 100644 --- a/test/agency_test.go +++ b/test/agency_test.go @@ -26,6 +26,13 @@ import ( "context" "crypto/tls" "fmt" + "net/http" + "os" + "reflect" + "strings" + "testing" + "time" + driver "github.com/arangodb/go-driver" "github.com/arangodb/go-driver/agency" httpdriver "github.com/arangodb/go-driver/http" @@ -33,12 +40,6 @@ import ( "github.com/arangodb/go-driver/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "net/http" - "os" - "reflect" - "strings" - "testing" - "time" ) // getAgencyEndpoints queries the cluster to get all agency endpoints. diff --git a/test/clean.go b/test/clean.go new file mode 100644 index 00000000..9be9d862 --- /dev/null +++ b/test/clean.go @@ -0,0 +1,38 @@ +// +// DISCLAIMER +// +// Copyright 2018 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// +// Author Ewout Prangsma +// + +package test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" +) + +type remove interface { + Remove(ctx context.Context) error +} + +func clean(t *testing.T, ctx context.Context, col remove) { + require.NoError(t, col.Remove(ctx)) +} diff --git a/test/client_test.go b/test/client_test.go index d98b75f4..d08197c6 100644 --- a/test/client_test.go +++ b/test/client_test.go @@ -397,6 +397,7 @@ func TestResponseHeader(t *testing.T) { var resp driver.Response db := ensureDatabase(ctx, c, "_system", nil, t) col := ensureCollection(ctx, db, "response_header_test", nil, t) + defer clean(t, ctx, col) // `ETag` header must contain the `_rev` of the new document in quotes. doc := map[string]string{ diff --git a/test/cluster_test.go b/test/cluster_test.go index e1ef859a..6a88a14f 100644 --- a/test/cluster_test.go +++ b/test/cluster_test.go @@ -133,9 +133,10 @@ func TestClusterDatabaseInventorySatellite(t *testing.T) { if err != nil { t.Fatalf("Failed to open _system database: %s", describe(err)) } - ensureCollection(ctx, db, name, &driver.CreateCollectionOptions{ + col := ensureCollection(ctx, db, name, &driver.CreateCollectionOptions{ ReplicationFactor: driver.ReplicationFactorSatellite, }, t) + defer clean(t, ctx, col) h, err := cl.Health(ctx) if err != nil { t.Fatalf("Health failed: %s", describe(err)) @@ -185,11 +186,12 @@ func TestClusterDatabaseInventorySmartJoin(t *testing.T) { if err != nil { t.Fatalf("Failed to open _system database: %s", describe(err)) } - ensureCollection(ctx, db, name, &driver.CreateCollectionOptions{ + col := ensureCollection(ctx, db, name, &driver.CreateCollectionOptions{ ShardKeys: []string{"_key:"}, SmartJoinAttribute: "smart", NumberOfShards: 2, }, t) + defer clean(t, ctx, col) inv, err := cl.DatabaseInventory(ctx, db) if err != nil { t.Fatalf("DatabaseInventory failed: %s", describe(err)) @@ -225,9 +227,10 @@ func TestClusterDatabaseInventoryShardingStrategy(t *testing.T) { if err != nil { t.Fatalf("Failed to open _system database: %s", describe(err)) } - ensureCollection(ctx, db, name, &driver.CreateCollectionOptions{ + col := ensureCollection(ctx, db, name, &driver.CreateCollectionOptions{ ShardingStrategy: driver.ShardingStrategyCommunityCompat, }, t) + defer clean(t, ctx, col) inv, err := cl.DatabaseInventory(ctx, db) if err != nil { t.Fatalf("DatabaseInventory failed: %s", describe(err)) @@ -261,6 +264,7 @@ func TestClusterMoveShard(t *testing.T) { col, err := db.CreateCollection(ctx, "test_move_shard", &driver.CreateCollectionOptions{ NumberOfShards: 12, }) + defer clean(t, ctx, col) if err != nil { t.Fatalf("CreateCollection failed: %s", describe(err)) } @@ -361,6 +365,7 @@ func TestClusterResignLeadership(t *testing.T) { NumberOfShards: 12, ReplicationFactor: 2, }) + defer clean(t, ctx, col) if err != nil { t.Fatalf("CreateCollection failed: %s", describe(err)) } @@ -448,6 +453,7 @@ func TestClusterMoveShardWithViews(t *testing.T) { col, err := db.CreateCollection(ctx, "test_move_shard_with_view", &driver.CreateCollectionOptions{ NumberOfShards: 12, }) + clean(t, ctx, col) if err != nil { t.Fatalf("CreateCollection failed: %s", describe(err)) } @@ -457,7 +463,9 @@ func TestClusterMoveShardWithViews(t *testing.T) { }, } viewName := "test_move_shard_view" - if _, err := db.CreateArangoSearchView(ctx, viewName, opts); err != nil { + view, err := db.CreateArangoSearchView(ctx, viewName, opts) + clean(t, ctx, view) + if err != nil { t.Fatalf("Failed to create view '%s': %s", viewName, describe(err)) } h, err := cl.Health(ctx) diff --git a/test/database_collection_defaults_test.go b/test/database_collection_defaults_test.go index d287ce34..4ded40ba 100644 --- a/test/database_collection_defaults_test.go +++ b/test/database_collection_defaults_test.go @@ -23,10 +23,11 @@ package test import ( - "github.com/dchest/uniuri" "strings" "testing" + "github.com/dchest/uniuri" + "github.com/arangodb/go-driver" "github.com/stretchr/testify/require" ) diff --git a/test/database_test.go b/test/database_test.go index b3fd5f7c..423de814 100644 --- a/test/database_test.go +++ b/test/database_test.go @@ -25,16 +25,17 @@ package test import ( "context" "fmt" - "github.com/dchest/uniuri" - "github.com/stretchr/testify/require" "strings" "testing" + "github.com/dchest/uniuri" + "github.com/stretchr/testify/require" + "github.com/arangodb/go-driver" ) // databaseName is helper to create database name in non-colliding way -func databaseName(parts ... string) string { +func databaseName(parts ...string) string { return fmt.Sprintf("%s_%s", strings.Join(parts, "_"), uniuri.NewLen(8)) } diff --git a/test/foxx_test.go b/test/foxx_test.go index 9f6ab1b6..363d238c 100644 --- a/test/foxx_test.go +++ b/test/foxx_test.go @@ -23,11 +23,12 @@ package test import ( "context" - "github.com/arangodb/go-driver" - "github.com/stretchr/testify/require" "os" "testing" "time" + + "github.com/arangodb/go-driver" + "github.com/stretchr/testify/require" ) func TestFoxxItzpapalotlService(t *testing.T) { diff --git a/test/graph_creation_test.go b/test/graph_creation_test.go index 5eec9e93..4ec62764 100644 --- a/test/graph_creation_test.go +++ b/test/graph_creation_test.go @@ -24,10 +24,11 @@ package test import ( "context" - "github.com/arangodb/go-driver" - "github.com/stretchr/testify/require" "testing" "time" + + "github.com/arangodb/go-driver" + "github.com/stretchr/testify/require" ) func newGraphOpts(db driver.Database) (driver.CreateGraphOptions, []string) { @@ -137,7 +138,6 @@ func Test_Graph_AdvancedCreate(t *testing.T) { }) } - // Test_Graph_AdvancedCreate_Defaults will check if graph created have properly set replication factor // and write concern by default func Test_Graph_AdvancedCreate_Defaults(t *testing.T) { diff --git a/test/revisions_test.go b/test/revisions_test.go index 30df996d..2abb12ef 100644 --- a/test/revisions_test.go +++ b/test/revisions_test.go @@ -4,11 +4,12 @@ import ( "context" "encoding/json" "fmt" - "github.com/arangodb/go-driver" - "github.com/stretchr/testify/require" "net/http" "testing" "time" + + "github.com/arangodb/go-driver" + "github.com/stretchr/testify/require" ) func TestRevisionTree(t *testing.T) { diff --git a/test/server_mode_auth_test.go b/test/server_mode_auth_test.go index ed38131c..cd988060 100644 --- a/test/server_mode_auth_test.go +++ b/test/server_mode_auth_test.go @@ -62,6 +62,7 @@ func TestServerModeAndGrants(t *testing.T) { db := ensureDatabase(ctx, c, "_system", nil, t) colName := "server_mode_and_grants_test1" col := ensureCollection(ctx, db, colName, nil, t) + clean(t, ctx, col) // Get database & collection access defaultDBAccess, err := u.GetDatabaseAccess(ctx, db)