From 5b310867576229774a659e574fde35d29447ec31 Mon Sep 17 00:00:00 2001 From: Ivan Fraixedes Date: Thu, 20 Jun 2019 17:38:08 +0200 Subject: [PATCH] pkg/audit: Move test helper funcs to separated file (#2259) Move 2 helper function used for test which relay on testplanet from the test file where they were created to separated file to contain them because they are not only used in the test file were initially they were created. --- pkg/audit/testplanet_helpers_test.go | 38 ++++++++++++++++++++++++++++ pkg/audit/verifier_test.go | 27 -------------------- 2 files changed, 38 insertions(+), 27 deletions(-) create mode 100644 pkg/audit/testplanet_helpers_test.go diff --git a/pkg/audit/testplanet_helpers_test.go b/pkg/audit/testplanet_helpers_test.go new file mode 100644 index 000000000..11e1c70aa --- /dev/null +++ b/pkg/audit/testplanet_helpers_test.go @@ -0,0 +1,38 @@ +// Copyright (C) 2019 Storj Labs, Inc. +// See LICENSE for copying information. + +package audit_test + +import ( + "context" + "fmt" + + "storj.io/storj/internal/testplanet" + "storj.io/storj/pkg/storj" + "storj.io/storj/storagenode" +) + +func getStorageNode(planet *testplanet.Planet, nodeID storj.NodeID) *storagenode.Peer { + for _, node := range planet.StorageNodes { + if node.ID() == nodeID { + return node + } + } + return nil +} + +func stopStorageNode(ctx context.Context, planet *testplanet.Planet, nodeID storj.NodeID) error { + node := getStorageNode(planet, nodeID) + if node == nil { + return fmt.Errorf("no such node: %s", nodeID.String()) + } + + err := planet.StopPeer(node) + if err != nil { + return err + } + + // mark stopped node as offline in overlay cache + _, err = planet.Satellites[0].Overlay.Service.UpdateUptime(ctx, nodeID, false) + return err +} diff --git a/pkg/audit/verifier_test.go b/pkg/audit/verifier_test.go index 2ee6d20ea..3681b1d62 100644 --- a/pkg/audit/verifier_test.go +++ b/pkg/audit/verifier_test.go @@ -5,7 +5,6 @@ package audit_test import ( "context" - "fmt" "math/rand" "testing" "time" @@ -24,7 +23,6 @@ import ( "storj.io/storj/pkg/peertls/tlsopts" "storj.io/storj/pkg/storj" "storj.io/storj/pkg/transport" - "storj.io/storj/storagenode" "storj.io/storj/uplink" ) @@ -634,28 +632,3 @@ func TestVerifierModifiedSegment(t *testing.T) { assert.Empty(t, report) }) } - -func getStorageNode(planet *testplanet.Planet, nodeID storj.NodeID) *storagenode.Peer { - for _, node := range planet.StorageNodes { - if node.ID() == nodeID { - return node - } - } - return nil -} - -func stopStorageNode(ctx context.Context, planet *testplanet.Planet, nodeID storj.NodeID) error { - node := getStorageNode(planet, nodeID) - if node == nil { - return fmt.Errorf("no such node: %s", nodeID.String()) - } - - err := planet.StopPeer(node) - if err != nil { - return err - } - - // mark stopped node as offline in overlay cache - _, err = planet.Satellites[0].Overlay.Service.UpdateUptime(ctx, nodeID, false) - return err -}