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

Commit 578506b

Browse files
author
Aleksandar Likic
committed
FAB-8101 - .json file extension with filekeyvaluestore
FAB-7513 (change https://gerrit.hyperledger.org/r/#/c/17547/ ) changed the default file extension of the new files produced by the filekeyvaluestore. Previously it was ".json", and now there is no extension (the key becomes the filename). This ticket demonstrates how to construct a new filekeyvaluestore that adds ".json" to the store file names, to keep compatibility with previously created stores. Change-Id: Iddd20a78f941d2d8449e3ef8a970c6d89ba8c8d2 Signed-off-by: Aleksandar Likic <aleksandar.likic@securekey.com>
1 parent f0fbf30 commit 578506b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

pkg/fabric-client/client_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ package fabricclient
88

99
import (
1010
"bytes"
11+
"path"
1112
"testing"
1213

1314
fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient"
15+
"github.com/pkg/errors"
1416

1517
"github.com/hyperledger/fabric-sdk-go/pkg/cryptosuite/bccsp/sw"
1618
kvs "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/keyvaluestore"
@@ -85,7 +87,17 @@ func TestClientMethods(t *testing.T) {
8587
t.Fatalf("client.NewChain create wrong chain")
8688
}
8789

88-
stateStore, err := kvs.NewFileKeyValueStore(&kvs.FileKeyValueStoreOptions{Path: "/tmp/keyvaluestore"})
90+
stateStorePath := "/tmp/keyvaluestore"
91+
stateStore, err := kvs.NewFileKeyValueStore(&kvs.FileKeyValueStoreOptions{
92+
Path: stateStorePath,
93+
KeySerializer: func(key interface{}) (string, error) {
94+
keyString, ok := key.(string)
95+
if !ok {
96+
return "", errors.New("converting key to string failed")
97+
}
98+
return path.Join(stateStorePath, keyString+".json"), nil
99+
},
100+
})
89101
if err != nil {
90102
t.Fatalf("CreateNewFileKeyValueStore return error[%s]", err)
91103
}

test/integration/fab/fabric_ca_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
"bytes"
1111
"crypto/x509"
1212
"encoding/pem"
13+
"errors"
1314
"math/rand"
15+
"path"
1416
"strconv"
1517
"testing"
1618
"time"
@@ -53,9 +55,17 @@ func TestRegisterEnrollRevoke(t *testing.T) {
5355
t.Fatalf("Failed getting cryptosuite from config : %s", err)
5456
}
5557

58+
stateStorePath := "/tmp/enroll_user"
5659
client.SetCryptoSuite(cryptoSuiteProvider)
5760
stateStore, err := kvs.NewFileKeyValueStore(&kvs.FileKeyValueStoreOptions{
58-
Path: "/tmp/enroll_user",
61+
Path: stateStorePath,
62+
KeySerializer: func(key interface{}) (string, error) {
63+
keyString, ok := key.(string)
64+
if !ok {
65+
return "", errors.New("converting key to string failed")
66+
}
67+
return path.Join(stateStorePath, keyString+".json"), nil
68+
},
5969
})
6070
if err != nil {
6171
t.Fatalf("CreateNewFileKeyValueStore return error[%s]", err)

0 commit comments

Comments
 (0)