Skip to content

Commit

Permalink
[FAB-8966] Cleanup user data in tests
Browse files Browse the repository at this point in the history
Integration tests that are sensitive to user data (potentially
performed by previous tests) can now clean up any previous
user data (to start from clean state), and also clean up
user data after they are done.

Change-Id: I75457ae498d108fe0de3bb5fa92461ff737572ca
Signed-off-by: Aleksandar Likic <aleksandar.likic@securekey.com>
  • Loading branch information
Aleksandar Likic committed Mar 19, 2018
1 parent 406f79d commit bc11591
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
5 changes: 5 additions & 0 deletions test/integration/e2e/end_to_end.go
Expand Up @@ -48,6 +48,11 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
}
defer sdk.Close()

// Delete all private keys from the crypto suite store
// and users from the user store at the end
integration.CleanupUserData(t, sdk)
defer integration.CleanupUserData(t, sdk)

//clientContext allows creation of transactions using the supplied identity as the credential.
clientContext := sdk.Context(fabsdk.WithUser(orgAdmin), fabsdk.WithOrg(ordererOrgName))

Expand Down
5 changes: 5 additions & 0 deletions test/integration/e2e/no_orderer_config.go
Expand Up @@ -32,6 +32,11 @@ func runWithNoOrdererConfig(t *testing.T, configOpt core.ConfigProvider, sdkOpts
}
defer sdk.Close()

// Delete all private keys from the crypto suite store
// and users from the user store at the end
integration.CleanupUserData(t, sdk)
defer integration.CleanupUserData(t, sdk)

// ************ Test setup complete ************** //

//TODO : discovery filter should be fixed
Expand Down
7 changes: 2 additions & 5 deletions test/integration/msp/enrollment_test.go
Expand Up @@ -33,11 +33,8 @@ func TestRegisterEnroll(t *testing.T) {

// Delete all private keys from the crypto suite store
// and users from the user store at the end
netConfig := sdk.Config()
keyStorePath := netConfig.KeyStorePath()
credentialStorePath := netConfig.CredentialStorePath()
defer integration.CleanupTestPath(t, keyStorePath)
defer integration.CleanupTestPath(t, credentialStorePath)
integration.CleanupUserData(t, sdk)
defer integration.CleanupUserData(t, sdk)

ctxProvider := sdk.Context()

Expand Down
5 changes: 5 additions & 0 deletions test/integration/orgs/multiple_orgs_test.go
Expand Up @@ -63,6 +63,11 @@ func TestOrgsEndToEnd(t *testing.T) {
}
defer sdk.Close()

// Delete all private keys from the crypto suite store
// and users from the user store at the end
integration.CleanupUserData(t, sdk)
defer integration.CleanupUserData(t, sdk)

expectedValue := testWithOrg1(t, sdk)
expectedValue = testWithOrg2(t, expectedValue)
verifyWithOrg1(t, sdk, expectedValue)
Expand Down
5 changes: 5 additions & 0 deletions test/integration/revoked/revoked_peer_test.go
Expand Up @@ -53,6 +53,11 @@ func TestRevokedPeer(t *testing.T) {
}
defer sdk.Close()

// Delete all private keys from the crypto suite store
// and users from the user store at the end
integration.CleanupUserData(t, sdk)
defer integration.CleanupUserData(t, sdk)

//prepare contexts
ordererClientContext := sdk.Context(fabsdk.WithUser(ordererAdminUser), fabsdk.WithOrg(ordererOrgName))
org1AdminClientContext := sdk.Context(fabsdk.WithUser(org1AdminUser), fabsdk.WithOrg(org1))
Expand Down
5 changes: 5 additions & 0 deletions test/integration/sdk/main_test.go
Expand Up @@ -42,6 +42,10 @@ func setup() {
panic(fmt.Sprintf("Failed to create new SDK: %s", err))
}

// Delete all private keys from the crypto suite store
// and users from the user store
integration.CleanupUserData(nil, sdk)

if err := testSetup.Initialize(sdk); err != nil {
panic(err.Error())
}
Expand All @@ -57,5 +61,6 @@ func setup() {
}

func teardown() {
integration.CleanupUserData(nil, mainSDK)
mainSDK.Close()
}
13 changes: 13 additions & 0 deletions test/integration/utils.go
Expand Up @@ -12,6 +12,8 @@ import (
"testing"
"time"

"fmt"

"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
Expand Down Expand Up @@ -159,6 +161,17 @@ func HasPeerJoinedChannel(client *resmgmt.Client, target string, channel string)
func CleanupTestPath(t *testing.T, storePath string) {
err := os.RemoveAll(storePath)
if err != nil {
if t == nil {
panic(fmt.Sprintf("Cleaning up directory '%s' failed: %v", storePath, err))
}
t.Fatalf("Cleaning up directory '%s' failed: %v", storePath, err)
}
}

func CleanupUserData(t *testing.T, sdk *fabsdk.FabricSDK) {
netConfig := sdk.Config()
keyStorePath := netConfig.KeyStorePath()
credentialStorePath := netConfig.CredentialStorePath()
CleanupTestPath(t, keyStorePath)
CleanupTestPath(t, credentialStorePath)
}

0 comments on commit bc11591

Please sign in to comment.