-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from Philip-21/fabric
test environment setups
- Loading branch information
Showing
4 changed files
with
128 additions
and
0 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 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 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,87 @@ | ||
package fabconnect | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-cli/internal/utils" | ||
"github.com/jarcoal/httpmock" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCreateIdentity(t *testing.T) { | ||
utils.StartMockServer(t) | ||
|
||
testContext := utils.NewTestEndPoint(t) | ||
tests := []struct { | ||
Name string | ||
FabconnectURL string | ||
Signer string | ||
ApiResponse string | ||
Method string | ||
ExpectedResponse *CreateIdentityResponse | ||
}{ | ||
{ | ||
Name: "TestIdentity-1", | ||
FabconnectURL: testContext.FabricURL + "/fabconnect/identities", | ||
Signer: "user-1", | ||
Method: "POST", | ||
ApiResponse: ` | ||
{ | ||
"Name": "fabric_user-1", | ||
"Secret": "9876543210987654321098765432109876543210987654321098765432109876" | ||
} | ||
`, | ||
ExpectedResponse: &CreateIdentityResponse{ | ||
Name: "fabric_user-1", | ||
Secret: "9876543210987654321098765432109876543210987654321098765432109876", | ||
}, | ||
}, | ||
{ | ||
Name: "TestIdentity-2", | ||
FabconnectURL: testContext.FabricURL + "/fabconnect/identities", | ||
Signer: "user-2", | ||
Method: "POST", | ||
ApiResponse: ` | ||
{ | ||
"Name": "fabric_user-2", | ||
"Secret": "aabbccddeeff0011223344556677889900112233445566778899aabbccddeeff" | ||
} | ||
`, | ||
ExpectedResponse: &CreateIdentityResponse{ | ||
Name: "fabric_user-2", | ||
Secret: "aabbccddeeff0011223344556677889900112233445566778899aabbccddeeff", | ||
}, | ||
}, | ||
{ | ||
Name: "TestIdentity-3", | ||
FabconnectURL: testContext.FabricURL + "/fabconnect/identities", | ||
Signer: "user-3", | ||
Method: "POST", | ||
ApiResponse: ` | ||
{ | ||
"Name": "fabric_user-3", | ||
"Secret": "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff" | ||
} | ||
`, | ||
ExpectedResponse: &CreateIdentityResponse{ | ||
Name: "fabric_user-3", | ||
Secret: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff", | ||
}, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
//mockResponse | ||
httpmock.RegisterResponder(tc.Method, tc.FabconnectURL, | ||
httpmock.NewStringResponder(200, tc.ApiResponse)) | ||
|
||
identityResp, err := CreateIdentity(tc.FabconnectURL, tc.Signer) | ||
if err != nil { | ||
t.Fatalf("unable to create identity: %v", err) | ||
} | ||
assert.NotNil(t, identityResp) | ||
assert.Equal(t, tc.ExpectedResponse, identityResp) | ||
}) | ||
} | ||
utils.StartMockServer(t) | ||
} |
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,37 @@ | ||
// This file contains different Setup and tools, for the FireFly-CLI testing Environment | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/jarcoal/httpmock" | ||
) | ||
|
||
type TestHelper struct { | ||
FabricURL string | ||
EthConnectURL string | ||
EvmConnectURL string | ||
} | ||
|
||
var ( | ||
FabricEndpoint = "http://localhost:7054" | ||
EthConnectEndpoint = "http://localhost:8080" | ||
EvmConnectEndpoint = "http://localhost:5008" | ||
) | ||
|
||
func StartMockServer(t *testing.T) { | ||
httpmock.Activate() | ||
} | ||
|
||
// mockprotocol endpoints for testing | ||
func NewTestEndPoint(t *testing.T) *TestHelper { | ||
return &TestHelper{ | ||
FabricURL: FabricEndpoint, | ||
EthConnectURL: EthConnectEndpoint, | ||
EvmConnectURL: EvmConnectEndpoint, | ||
} | ||
} | ||
|
||
func StopMockServer(_ *testing.T) { | ||
httpmock.DeactivateAndReset() | ||
} |