Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit bc11591

Browse files
author
Aleksandar Likic
committed
[FAB-8966] Cleanup user data in tests
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>
1 parent 406f79d commit bc11591

File tree

7 files changed

+40
-5
lines changed

7 files changed

+40
-5
lines changed

test/integration/e2e/end_to_end.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
4848
}
4949
defer sdk.Close()
5050

51+
// Delete all private keys from the crypto suite store
52+
// and users from the user store at the end
53+
integration.CleanupUserData(t, sdk)
54+
defer integration.CleanupUserData(t, sdk)
55+
5156
//clientContext allows creation of transactions using the supplied identity as the credential.
5257
clientContext := sdk.Context(fabsdk.WithUser(orgAdmin), fabsdk.WithOrg(ordererOrgName))
5358

test/integration/e2e/no_orderer_config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func runWithNoOrdererConfig(t *testing.T, configOpt core.ConfigProvider, sdkOpts
3232
}
3333
defer sdk.Close()
3434

35+
// Delete all private keys from the crypto suite store
36+
// and users from the user store at the end
37+
integration.CleanupUserData(t, sdk)
38+
defer integration.CleanupUserData(t, sdk)
39+
3540
// ************ Test setup complete ************** //
3641

3742
//TODO : discovery filter should be fixed

test/integration/msp/enrollment_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ func TestRegisterEnroll(t *testing.T) {
3333

3434
// Delete all private keys from the crypto suite store
3535
// and users from the user store at the end
36-
netConfig := sdk.Config()
37-
keyStorePath := netConfig.KeyStorePath()
38-
credentialStorePath := netConfig.CredentialStorePath()
39-
defer integration.CleanupTestPath(t, keyStorePath)
40-
defer integration.CleanupTestPath(t, credentialStorePath)
36+
integration.CleanupUserData(t, sdk)
37+
defer integration.CleanupUserData(t, sdk)
4138

4239
ctxProvider := sdk.Context()
4340

test/integration/orgs/multiple_orgs_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ func TestOrgsEndToEnd(t *testing.T) {
6363
}
6464
defer sdk.Close()
6565

66+
// Delete all private keys from the crypto suite store
67+
// and users from the user store at the end
68+
integration.CleanupUserData(t, sdk)
69+
defer integration.CleanupUserData(t, sdk)
70+
6671
expectedValue := testWithOrg1(t, sdk)
6772
expectedValue = testWithOrg2(t, expectedValue)
6873
verifyWithOrg1(t, sdk, expectedValue)

test/integration/revoked/revoked_peer_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ func TestRevokedPeer(t *testing.T) {
5353
}
5454
defer sdk.Close()
5555

56+
// Delete all private keys from the crypto suite store
57+
// and users from the user store at the end
58+
integration.CleanupUserData(t, sdk)
59+
defer integration.CleanupUserData(t, sdk)
60+
5661
//prepare contexts
5762
ordererClientContext := sdk.Context(fabsdk.WithUser(ordererAdminUser), fabsdk.WithOrg(ordererOrgName))
5863
org1AdminClientContext := sdk.Context(fabsdk.WithUser(org1AdminUser), fabsdk.WithOrg(org1))

test/integration/sdk/main_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func setup() {
4242
panic(fmt.Sprintf("Failed to create new SDK: %s", err))
4343
}
4444

45+
// Delete all private keys from the crypto suite store
46+
// and users from the user store
47+
integration.CleanupUserData(nil, sdk)
48+
4549
if err := testSetup.Initialize(sdk); err != nil {
4650
panic(err.Error())
4751
}
@@ -57,5 +61,6 @@ func setup() {
5761
}
5862

5963
func teardown() {
64+
integration.CleanupUserData(nil, mainSDK)
6065
mainSDK.Close()
6166
}

test/integration/utils.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"testing"
1313
"time"
1414

15+
"fmt"
16+
1517
"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
1618
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
1719
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
@@ -159,6 +161,17 @@ func HasPeerJoinedChannel(client *resmgmt.Client, target string, channel string)
159161
func CleanupTestPath(t *testing.T, storePath string) {
160162
err := os.RemoveAll(storePath)
161163
if err != nil {
164+
if t == nil {
165+
panic(fmt.Sprintf("Cleaning up directory '%s' failed: %v", storePath, err))
166+
}
162167
t.Fatalf("Cleaning up directory '%s' failed: %v", storePath, err)
163168
}
164169
}
170+
171+
func CleanupUserData(t *testing.T, sdk *fabsdk.FabricSDK) {
172+
netConfig := sdk.Config()
173+
keyStorePath := netConfig.KeyStorePath()
174+
credentialStorePath := netConfig.CredentialStorePath()
175+
CleanupTestPath(t, keyStorePath)
176+
CleanupTestPath(t, credentialStorePath)
177+
}

0 commit comments

Comments
 (0)