Skip to content

Commit

Permalink
[FAB-8490] Rename factory methods to Create
Browse files Browse the repository at this point in the history
Change-Id: I010962cc41317f3a31e725effc3bcc74386b3920
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Feb 24, 2018
1 parent 2dbe1a8 commit 834bdb3
Show file tree
Hide file tree
Showing 51 changed files with 227 additions and 227 deletions.
2 changes: 1 addition & 1 deletion def/fabapi/deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func sdkOptionsFromDeprecatedOptions(options Options) []fabsdk.Option {
stateStoreOpts := defcore.StateStoreOptsDeprecated{
Path: options.StateStoreOpts.Path,
}
core := defcore.NewProviderFactoryDeprecated(stateStoreOpts)
core := defcore.CreateProviderFactoryDeprecated(stateStoreOpts)
opts = append(opts, fabsdk.WithCorePkg(core))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/channel/chclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func setupTestChannelService(ctx context.Context, orderers []fab.Orderer) (fab.C
}
chProvider.SetChannel(channelName, testChannel)

chService, err := chProvider.NewChannelService(ctx, channelName)
chService, err := chProvider.ChannelService(ctx, channelName)
if err != nil {
return nil, errors.WithMessage(err, "mock channel service creation failed")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/common/discovery/discoveryfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestDiscoveryFilter(t *testing.T) {
t.Fatalf(err.Error())
}

discoveryProvider, err := staticdiscovery.NewDiscoveryProvider(config)
discoveryProvider, err := staticdiscovery.New(config)
if err != nil {
t.Fatalf("Failed to setup discovery provider: %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type discoveryService struct {
peers []fab.Peer
}

// NewDiscoveryProvider returns discovery provider
func NewDiscoveryProvider(config core.Config) (*DiscoveryProvider, error) {
// New returns discovery provider
func New(config core.Config) (*DiscoveryProvider, error) {
return &DiscoveryProvider{config: config}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestStaticDiscovery(t *testing.T) {
t.Fatalf(err.Error())
}

discoveryProvider, err := NewDiscoveryProvider(config)
discoveryProvider, err := New(config)
if err != nil {
t.Fatalf("Failed to setup discovery provider: %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type SelectionProvider struct {
sdk *fabsdk.FabricSDK
}

// NewSelectionProvider returns dynamic selection provider
func NewSelectionProvider(config core.Config, users []ChannelUser, lbp pgresolver.LoadBalancePolicy) (*SelectionProvider, error) {
// New returns dynamic selection provider
func New(config core.Config, users []ChannelUser, lbp pgresolver.LoadBalancePolicy) (*SelectionProvider, error) {
lbPolicy := lbp
if lbPolicy == nil {
lbPolicy = pgresolver.NewRandomLBP()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func TestDynamicSelection(t *testing.T) {

mychannelUser := ChannelUser{ChannelID: "mychannel", UserName: "User1", OrgName: "Org1"}

selectionProvider, err := NewSelectionProvider(c, []ChannelUser{mychannelUser}, nil)
selectionProvider, err := New(c, []ChannelUser{mychannelUser}, nil)
if err != nil {
t.Fatalf("Failed to setup selection provider: %s", err)
}
Expand Down Expand Up @@ -395,7 +395,7 @@ func TestDynamicSelection(t *testing.T) {
}

// Test custom load balancer
selectionProvider, err = NewSelectionProvider(c, []ChannelUser{mychannelUser}, newCustomLBP())
selectionProvider, err = New(c, []ChannelUser{mychannelUser}, newCustomLBP())
if err != nil {
t.Fatalf("Failed to setup selection provider: %s", err)
}
Expand Down Expand Up @@ -430,8 +430,8 @@ type DynamicSelectionProviderFactory struct {
selectionProvider fab.SelectionProvider
}

// NewSelectionProvider returns a new implementation of dynamic selection provider
func (f *DynamicSelectionProviderFactory) NewSelectionProvider(config core.Config) (fab.SelectionProvider, error) {
// CreateSelectionProvider returns a new implementation of dynamic selection provider
func (f *DynamicSelectionProviderFactory) CreateSelectionProvider(config core.Config) (fab.SelectionProvider, error) {
return f.selectionProvider, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type SelectionProvider struct {
config core.Config
}

// NewSelectionProvider returns static selection provider
func NewSelectionProvider(config core.Config) (*SelectionProvider, error) {
// New returns static selection provider
func New(config core.Config) (*SelectionProvider, error) {
return &SelectionProvider{config: config}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestStaticSelection(t *testing.T) {
t.Fatalf(err.Error())
}

selectionProvider, err := NewSelectionProvider(config)
selectionProvider, err := New(config)
if err != nil {
t.Fatalf("Failed to setup selection provider: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/resmgmt/resmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ func (rc *Client) sendCCProposal(ccProposalType channel.ChaincodeProposalType, c
}

// Get transactor on the channel to create and send the deploy proposal
channelService, err := rc.channelProvider.NewChannelService(rc.identity, channelID)
channelService, err := rc.channelProvider.ChannelService(rc.identity, channelID)
if err != nil {
return errors.WithMessage(err, "Unable to get channel service")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/context/api/fab/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ type Transactor interface {

// ChannelProvider supplies Channel related-objects for the named channel.
type ChannelProvider interface {
NewChannelService(ic context.IdentityContext, channelID string) (ChannelService, error)
ChannelService(ic context.IdentityContext, channelID string) (ChannelService, error)
}
4 changes: 2 additions & 2 deletions pkg/fab/ca/fabricca.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ type FabricCA struct {
registrar config.EnrollCredentials
}

// NewFabricCAClient creates a new fabric-ca client
// New creates a new fabric-ca client
// @param {string} organization for this CA
// @param {Config} client config for fabric-ca services
// @returns {FabricCA} FabricCA implementation
// @returns {error} error, if any
func NewFabricCAClient(org string, config config.Config, cryptoSuite core.CryptoSuite) (*FabricCA, error) {
func New(org string, config config.Config, cryptoSuite core.CryptoSuite) (*FabricCA, error) {

userStorePath := config.CredentialStorePath()
userStore, err := identity.NewCertFileUserStore(userStorePath, cryptoSuite)
Expand Down
24 changes: 12 additions & 12 deletions pkg/fab/ca/fabricca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestMain(m *testing.M) {
// TestEnroll will test multiple enrol scenarios
func TestEnroll(t *testing.T) {

fabricCAClient, err := NewFabricCAClient(org1, configImp, cryptoSuiteProvider)
fabricCAClient, err := New(org1, configImp, cryptoSuiteProvider)
if err != nil {
t.Fatalf("NewFabricCAClient return error: %v", err)
}
Expand All @@ -71,7 +71,7 @@ func TestEnroll(t *testing.T) {
}

wrongConfigImp := mocks.NewMockConfig(wrongCAServerURL)
fabricCAClient, err = NewFabricCAClient(org1, wrongConfigImp, cryptoSuiteProvider)
fabricCAClient, err = New(org1, wrongConfigImp, cryptoSuiteProvider)
if err != nil {
t.Fatalf("NewFabricCAClient return error: %v", err)
}
Expand All @@ -85,7 +85,7 @@ func TestEnroll(t *testing.T) {
// TestRegister tests multiple scenarios of registering a test (mocked or nil user) and their certs
func TestRegister(t *testing.T) {

fabricCAClient, err := NewFabricCAClient(org1, configImp, cryptoSuiteProvider)
fabricCAClient, err := New(org1, configImp, cryptoSuiteProvider)
if err != nil {
t.Fatalf("NewFabricCAClient returned error: %v", err)
}
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestRevoke(t *testing.T) {
t.Fatalf("cryptosuite.GetSuiteByConfig returned error: %v", err)
}

fabricCAClient, err := NewFabricCAClient(org1, configImp, cryptoSuiteProvider)
fabricCAClient, err := New(org1, configImp, cryptoSuiteProvider)
if err != nil {
t.Fatalf("NewFabricCAClient returned error: %v", err)
}
Expand All @@ -145,7 +145,7 @@ func TestRevoke(t *testing.T) {
// TestReenroll will test multiple scenarios of re enrolling a user
func TestReenroll(t *testing.T) {

fabricCAClient, err := NewFabricCAClient(org1, configImp, cryptoSuiteProvider)
fabricCAClient, err := New(org1, configImp, cryptoSuiteProvider)
if err != nil {
t.Fatalf("NewFabricCAClient returned error: %v", err)
}
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestReenroll(t *testing.T) {

// Reenroll with wrong fabric-ca server url
wrongConfigImp := mocks.NewMockConfig(wrongCAServerURL)
fabricCAClient, err = NewFabricCAClient(org1, wrongConfigImp, cryptoSuiteProvider)
fabricCAClient, err = New(org1, wrongConfigImp, cryptoSuiteProvider)
if err != nil {
t.Fatalf("NewFabricCAClient return error: %v", err)
}
Expand All @@ -204,7 +204,7 @@ func TestReenroll(t *testing.T) {

// TestGetCAName will test the CAName is properly created once a new FabricCAClient is created
func TestGetCAName(t *testing.T) {
fabricCAClient, err := NewFabricCAClient(org1, configImp, cryptoSuiteProvider)
fabricCAClient, err := New(org1, configImp, cryptoSuiteProvider)
if err != nil {
t.Fatalf("NewFabricCAClient returned error: %v", err)
}
Expand All @@ -222,7 +222,7 @@ func TestCreateNewFabricCAClientCAConfigMissingFailure(t *testing.T) {
mockConfig.EXPECT().CAConfig(org1).Return(nil, errors.New("CAConfig error"))
mockConfig.EXPECT().CredentialStorePath().Return(userStorePath)

_, err := NewFabricCAClient(org1, mockConfig, cryptoSuiteProvider)
_, err := New(org1, mockConfig, cryptoSuiteProvider)
if err.Error() != "CAConfig error" {
t.Fatalf("Expected error from CAConfig. Got: %s", err.Error())
}
Expand All @@ -236,7 +236,7 @@ func TestCreateNewFabricCAClientCertFilesMissingFailure(t *testing.T) {
mockConfig.EXPECT().CAConfig(org1).Return(&config.CAConfig{}, nil).AnyTimes()
mockConfig.EXPECT().CredentialStorePath().Return(userStorePath)
mockConfig.EXPECT().CAServerCertPaths(org1).Return(nil, errors.New("CAServerCertPaths error"))
_, err := NewFabricCAClient(org1, mockConfig, cryptoSuiteProvider)
_, err := New(org1, mockConfig, cryptoSuiteProvider)
if err.Error() != "CAServerCertPaths error" {
t.Fatalf("Expected error from CAServerCertPaths. Got: %s", err.Error())
}
Expand All @@ -251,7 +251,7 @@ func TestCreateNewFabricCAClientCertFileErrorFailure(t *testing.T) {
mockConfig.EXPECT().CredentialStorePath().Return(userStorePath)
mockConfig.EXPECT().CAServerCertPaths(org1).Return([]string{"test"}, nil)
mockConfig.EXPECT().CAClientCertPath(org1).Return("", errors.New("CAClientCertPath error"))
_, err := NewFabricCAClient(org1, mockConfig, cryptoSuiteProvider)
_, err := New(org1, mockConfig, cryptoSuiteProvider)
if err.Error() != "CAClientCertPath error" {
t.Fatalf("Expected error from CAClientCertPath. Got: %s", err.Error())
}
Expand All @@ -267,7 +267,7 @@ func TestCreateNewFabricCAClientKeyFileErrorFailure(t *testing.T) {
mockConfig.EXPECT().CAServerCertPaths(org1).Return([]string{"test"}, nil)
mockConfig.EXPECT().CAClientCertPath(org1).Return("", nil)
mockConfig.EXPECT().CAClientKeyPath(org1).Return("", errors.New("CAClientKeyPath error"))
_, err := NewFabricCAClient(org1, mockConfig, cryptoSuiteProvider)
_, err := New(org1, mockConfig, cryptoSuiteProvider)
if err.Error() != "CAClientKeyPath error" {
t.Fatalf("Expected error from CAClientKeyPath. Got: %s", err.Error())
}
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestCreateValidBCCSPOptsForNewFabricClient(t *testing.T) {
t.Fatalf("Expected fabric client ryptosuite to be created with SW BCCS provider, but got %v", err.Error())
}

_, err = NewFabricCAClient(org1, mockConfig, newCryptosuiteProvider)
_, err = New(org1, mockConfig, newCryptosuiteProvider)
if err != nil {
t.Fatalf("Expected fabric client to be created with SW BCCS provider, but got %v", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/channel/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type ChaincodeDeployRequest struct {
}

// CreateChaincodeDeployProposal creates an instantiate or upgrade chaincode proposal.
func CreateChaincodeDeployProposal(txh *txn.TransactionHeader, deploy ChaincodeProposalType, channelID string, chaincode ChaincodeDeployRequest) (*fab.TransactionProposal, error) {
func CreateChaincodeDeployProposal(txh fab.TransactionHeader, deploy ChaincodeProposalType, channelID string, chaincode ChaincodeDeployRequest) (*fab.TransactionProposal, error) {

// Generate arguments for deploy (channel, marshaled CCDS, marshaled chaincode policy, marshaled collection policy)
args := [][]byte{}
Expand Down
4 changes: 2 additions & 2 deletions pkg/fab/credentialmgr/credentialmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ type CredentialManager struct {
userStore api.UserStore
}

// NewCredentialManager Constructor for a credential manager.
// New Constructor for a credential manager.
// @param {string} orgName - organisation id
// @returns {CredentialManager} new credential manager
func NewCredentialManager(orgName string, config core.Config, cryptoProvider core.CryptoSuite) (api.CredentialManager, error) {
func New(orgName string, config core.Config, cryptoProvider core.CryptoSuite) (*CredentialManager, error) {

netConfig, err := config.NetworkConfig()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/fab/credentialmgr/credentialmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestCredentialManager(t *testing.T) {
t.Fatalf("Failed to setup userStore: %s", err)
}

credentialMgr, err := NewCredentialManager(msp, config, cryptoSuite)
credentialMgr, err := New(msp, config, cryptoSuite)
if err != nil {
t.Fatalf("Failed to setup credential manager: %s", err)
}
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestInvalidOrgCredentialManager(t *testing.T) {
}

// Invalid Org
_, err = NewCredentialManager("invalidOrg", config, &fcmocks.MockCryptoSuite{})
_, err = New("invalidOrg", config, &fcmocks.MockCryptoSuite{})
if err == nil {
t.Fatalf("Should have failed to setup manager for invalid org")
}
Expand All @@ -171,7 +171,7 @@ func TestCredentialManagerFromEmbeddedCryptoConfig(t *testing.T) {
t.Fatalf(err.Error())
}

credentialMgr, err := NewCredentialManager(msp, config, cryptosuite.GetDefault())
credentialMgr, err := New(msp, config, cryptosuite.GetDefault())
if err != nil {
t.Fatalf("Failed to setup credential manager: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/credentialmgr/enrollment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestCredentialManagerWithEnrollment(t *testing.T) {

cs, err := sw.GetSuiteByConfig(config)

credentialMgr, err := NewCredentialManager(orgName, config, cs)
credentialMgr, err := New(orgName, config, cs)
if err != nil {
t.Fatalf("Failed to setup credential manager: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/credentialmgr/persistence/filecertstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func NewFileCertStore(cryptoConfogMspPath string) (api.KVStore, error) {
return path.Join(certDir, fmt.Sprintf("%s@%s-cert.pem", ck.UserName, orgName)), nil
},
}
return keyvaluestore.NewFileKeyValueStore(opts)
return keyvaluestore.New(opts)
}
2 changes: 1 addition & 1 deletion pkg/fab/credentialmgr/persistence/filekeystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ func NewFileKeyStore(cryptoConfogMspPath string) (api.KVStore, error) {
return path.Join(keyDir, hex.EncodeToString(pkk.SKI)+"_sk"), nil
},
}
return keyvaluestore.NewFileKeyValueStore(opts)
return keyvaluestore.New(opts)
}
2 changes: 1 addition & 1 deletion pkg/fab/identity/certfileuserstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewCertFileUserStore(path string, cryptoSuite core.CryptoSuite) (*CertFileU
if cryptoSuite == nil {
return nil, errors.New("cryptoSuite is nil")
}
store, err := keyvaluestore.NewFileKeyValueStore(&keyvaluestore.FileKeyValueStoreOptions{
store, err := keyvaluestore.New(&keyvaluestore.FileKeyValueStoreOptions{
Path: path,
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/fab/keyvaluestore/filekeyvaluestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (fkvs *FileKeyValueStore) GetPath() string {
return fkvs.path
}

// NewFileKeyValueStore creates a new instance of FileKeyValueStore using provided options
func NewFileKeyValueStore(opts *FileKeyValueStoreOptions) (*FileKeyValueStore, error) {
// New creates a new instance of FileKeyValueStore using provided options
func New(opts *FileKeyValueStoreOptions) (*FileKeyValueStore, error) {
if opts == nil {
return nil, errors.New("FileKeyValueStoreOptions is nil")
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/fab/keyvaluestore/filekeyvaluestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func TestFKVSWithCustomKeySerializer(t *testing.T) {
func testFKVS(t *testing.T, KeySerializer KeySerializer) {
var store api.KVStore
var err error
store, err = NewFileKeyValueStore(
store, err = New(
&FileKeyValueStoreOptions{
Path: storePath,
KeySerializer: KeySerializer,
})
if err != nil {
t.Fatalf("NewFileKeyValueStore failed [%s]", err)
t.Fatalf("New failed [%s]", err)
}
if err := cleanup(storePath); err != nil {
t.Fatalf("%s", err)
Expand Down Expand Up @@ -113,21 +113,21 @@ func testFKVS(t *testing.T, KeySerializer KeySerializer) {

func TestCreateNewFileKeyValueStore(t *testing.T) {

_, err := NewFileKeyValueStore(
_, err := New(
&FileKeyValueStoreOptions{
Path: "",
})
if err == nil || err.Error() != "FileKeyValueStore path is empty" {
t.Fatal("File path validation on NewFileKeyValueStore is not working as expected")
}

_, err = NewFileKeyValueStore(nil)
_, err = New(nil)
if err == nil || err.Error() != "FileKeyValueStoreOptions is nil" {
t.Fatal("File path validation on NewFileKeyValueStore is not working as expected")
}

var store api.KVStore
store, err = NewFileKeyValueStore(
store, err = New(
&FileKeyValueStoreOptions{
Path: storePath,
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/fab/mocks/mockchprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func (cp *MockChannelProvider) SetTransactor(transactor fab.Transactor) {
cp.transactor = transactor
}

// NewChannelService returns a mock ChannelService
func (cp *MockChannelProvider) NewChannelService(ic context.IdentityContext, channelID string) (fab.ChannelService, error) {
// ChannelService returns a mock ChannelService
func (cp *MockChannelProvider) ChannelService(ic context.IdentityContext, channelID string) (fab.ChannelService, error) {
cs := MockChannelService{
provider: cp,
channelID: channelID,
Expand Down
Loading

0 comments on commit 834bdb3

Please sign in to comment.