From 397ef9bea52002f8f5ad7c9d80ea9d3fdbec98e3 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Wed, 17 Jun 2020 12:26:57 +0200 Subject: [PATCH 1/2] delete collections and views after the test --- test/client_test.go | 1 + test/cluster_test.go | 17 +++++++++++++---- test/server_mode_auth_test.go | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/test/client_test.go b/test/client_test.go index d98b75f4..9c617b45 100644 --- a/test/client_test.go +++ b/test/client_test.go @@ -420,5 +420,6 @@ func TestResponseHeader(t *testing.T) { if x := resp.Header("ETAG"); x != expectedETag { t.Errorf("Unexpected result from Header('ETAG'), got '%s', expected '%s'", x, expectedETag) } + col.Remove(ctx) } } diff --git a/test/cluster_test.go b/test/cluster_test.go index e1ef859a..0bd71b99 100644 --- a/test/cluster_test.go +++ b/test/cluster_test.go @@ -133,7 +133,7 @@ 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) h, err := cl.Health(ctx) @@ -167,7 +167,9 @@ func TestClusterDatabaseInventorySatellite(t *testing.T) { if !foundSatellite { t.Errorf("No satellite collection.") } + col.Remove(ctx) } + } // TestClusterDatabaseInventorySmartJoin tests the Cluster.DatabaseInventory method with smart joins @@ -185,7 +187,7 @@ 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, @@ -207,6 +209,7 @@ func TestClusterDatabaseInventorySmartJoin(t *testing.T) { if !foundSmartJoin { t.Errorf("No smart join attribute.") } + col.Remove(ctx) } } @@ -225,7 +228,7 @@ 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) inv, err := cl.DatabaseInventory(ctx, db) @@ -243,6 +246,7 @@ func TestClusterDatabaseInventoryShardingStrategy(t *testing.T) { break } } + col.Remove(ctx) } } @@ -342,6 +346,7 @@ func TestClusterMoveShard(t *testing.T) { t.Log("Waiting a bit") time.Sleep(time.Second * 5) } + col.Remove(ctx) } } @@ -428,6 +433,7 @@ func TestClusterResignLeadership(t *testing.T) { t.Log("Waiting a bit") time.Sleep(time.Second * 5) } + col.Remove(ctx) } } @@ -457,7 +463,8 @@ 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) + if err != nil { t.Fatalf("Failed to create view '%s': %s", viewName, describe(err)) } h, err := cl.Health(ctx) @@ -538,5 +545,7 @@ func TestClusterMoveShardWithViews(t *testing.T) { t.Log("Waiting a bit") time.Sleep(time.Second * 5) } + view.Remove(ctx) + col.Remove(ctx) } } diff --git a/test/server_mode_auth_test.go b/test/server_mode_auth_test.go index ed38131c..a6b1d2aa 100644 --- a/test/server_mode_auth_test.go +++ b/test/server_mode_auth_test.go @@ -156,5 +156,6 @@ func TestServerModeAndGrants(t *testing.T) { } else if grant != defaultDBAccess { t.Errorf("Collection access using WithConfigured differs, got '%s', expected '%s'", grant, defaultColAccess) } + col.Remove(ctx) } } From cf16de75652720ebf5b404f985a5d57fd305e2ef Mon Sep 17 00:00:00 2001 From: ajanikow <12255597+ajanikow@users.noreply.github.com> Date: Wed, 17 Jun 2020 11:59:38 +0000 Subject: [PATCH 2/2] Improve cleanup --- test/agency_test.go | 13 ++++---- test/clean.go | 38 +++++++++++++++++++++++ test/client_test.go | 2 +- test/cluster_test.go | 21 ++++++------- test/database_collection_defaults_test.go | 3 +- test/database_test.go | 7 +++-- test/foxx_test.go | 5 +-- test/graph_creation_test.go | 6 ++-- test/revisions_test.go | 5 +-- test/server_mode_auth_test.go | 2 +- 10 files changed, 72 insertions(+), 30 deletions(-) create mode 100644 test/clean.go 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 9c617b45..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{ @@ -420,6 +421,5 @@ func TestResponseHeader(t *testing.T) { if x := resp.Header("ETAG"); x != expectedETag { t.Errorf("Unexpected result from Header('ETAG'), got '%s', expected '%s'", x, expectedETag) } - col.Remove(ctx) } } diff --git a/test/cluster_test.go b/test/cluster_test.go index 0bd71b99..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)) } - col := 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)) @@ -167,9 +168,7 @@ func TestClusterDatabaseInventorySatellite(t *testing.T) { if !foundSatellite { t.Errorf("No satellite collection.") } - col.Remove(ctx) } - } // TestClusterDatabaseInventorySmartJoin tests the Cluster.DatabaseInventory method with smart joins @@ -192,6 +191,7 @@ func TestClusterDatabaseInventorySmartJoin(t *testing.T) { 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)) @@ -209,7 +209,6 @@ func TestClusterDatabaseInventorySmartJoin(t *testing.T) { if !foundSmartJoin { t.Errorf("No smart join attribute.") } - col.Remove(ctx) } } @@ -228,9 +227,10 @@ func TestClusterDatabaseInventoryShardingStrategy(t *testing.T) { if err != nil { t.Fatalf("Failed to open _system database: %s", describe(err)) } - col := 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)) @@ -246,7 +246,6 @@ func TestClusterDatabaseInventoryShardingStrategy(t *testing.T) { break } } - col.Remove(ctx) } } @@ -265,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)) } @@ -346,7 +346,6 @@ func TestClusterMoveShard(t *testing.T) { t.Log("Waiting a bit") time.Sleep(time.Second * 5) } - col.Remove(ctx) } } @@ -366,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)) } @@ -433,7 +433,6 @@ func TestClusterResignLeadership(t *testing.T) { t.Log("Waiting a bit") time.Sleep(time.Second * 5) } - col.Remove(ctx) } } @@ -454,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)) } @@ -463,7 +463,8 @@ func TestClusterMoveShardWithViews(t *testing.T) { }, } viewName := "test_move_shard_view" - view, err := db.CreateArangoSearchView(ctx, viewName, opts) + 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)) } @@ -545,7 +546,5 @@ func TestClusterMoveShardWithViews(t *testing.T) { t.Log("Waiting a bit") time.Sleep(time.Second * 5) } - view.Remove(ctx) - col.Remove(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 a6b1d2aa..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) @@ -156,6 +157,5 @@ func TestServerModeAndGrants(t *testing.T) { } else if grant != defaultDBAccess { t.Errorf("Collection access using WithConfigured differs, got '%s', expected '%s'", grant, defaultColAccess) } - col.Remove(ctx) } }