-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-7661] Functional parameters for fabsdk.New
This patch adjusts fabsdk to use a functional parameter style to provide more explicit options and better flexibility. Change-Id: Ib2bc77062f68447d3550aff82952e756fd5f1556 Signed-off-by: Troy Ronda <troy@troyronda.com>
- Loading branch information
Showing
9 changed files
with
248 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// Package defpkgsuite provides a default implementation of the fabric API for fabsdk | ||
package defpkgsuite | ||
|
||
import ( | ||
"github.com/hyperledger/fabric-sdk-go/def/factory/defclient" | ||
"github.com/hyperledger/fabric-sdk-go/def/factory/defcore" | ||
"github.com/hyperledger/fabric-sdk-go/def/factory/defsvc" | ||
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk" | ||
sdkapi "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/api" | ||
"github.com/hyperledger/fabric-sdk-go/pkg/logging/deflogger" | ||
) | ||
|
||
// SDKOpt provides the default implementation for the SDK | ||
func SDKOpt() fabsdk.SDKOption { | ||
return fabsdk.PkgSuiteAsOpt(newPkgSuite()) | ||
} | ||
|
||
func newPkgSuite() sdkapi.PkgSuite { | ||
pkgSuite := sdkapi.PkgSuite{ | ||
Core: defcore.NewProviderFactory(), | ||
Service: defsvc.NewProviderFactory(), | ||
Context: defclient.NewOrgClientFactory(), | ||
Session: defclient.NewSessionClientFactory(), | ||
Logger: deflogger.LoggerProvider(), | ||
} | ||
return pkgSuite | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package defpkgsuite | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk" | ||
) | ||
|
||
func TestSDKOpt(t *testing.T) { | ||
opt := SDKOpt() | ||
|
||
_, err := fabsdk.New(opt, fabsdk.ConfigFile("../../../test/fixtures/config/config_test.yaml")) | ||
if err != nil { | ||
t.Fatalf("Unexpected error constructing SDK: %v", err) | ||
} | ||
} | ||
|
||
func TestNewPkgSuite(t *testing.T) { | ||
pkgsuite := newPkgSuite() | ||
|
||
if pkgsuite.Context == nil { | ||
t.Fatalf("Context is nil") | ||
} | ||
if pkgsuite.Core == nil { | ||
t.Fatalf("Core is nil") | ||
} | ||
if pkgsuite.Logger == nil { | ||
t.Fatalf("Logger is nil") | ||
} | ||
if pkgsuite.Service == nil { | ||
t.Fatalf("Service is nil") | ||
} | ||
if pkgsuite.Session == nil { | ||
t.Fatalf("Session is nil") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.