Skip to content

Commit

Permalink
new tests
Browse files Browse the repository at this point in the history
Signed-off-by: Philip-21 <[email protected]>
  • Loading branch information
Philip-21 committed Jan 25, 2024
1 parent 99ad4ba commit c0ad2ae
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 9 deletions.
12 changes: 6 additions & 6 deletions cmd/accounts_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,32 @@ func TestCreateAccountCmd(t *testing.T) {
}{
{
Name: "testcase1",
Args: []string{"ff", "create", "stack-1"},
Args: []string{"create", "stack-1"},
ExpectedResponse: "account1.output",
},
{
Name: "testcase-2",
Args: []string{"ff", "create", "stack-2"},
Args: []string{"create", "stack-2"},
ExpectedResponse: "account1.output",
},
{
Name: "testcase-3",
Args: []string{"ff", "create", "stack-3"},
Args: []string{"create", "stack-3"},
ExpectedResponse: "account1.output",
},
{
Name: "testcase-4",
Args: []string{"ff", "create", "stack-4"},
Args: []string{"create", "stack-4"},
ExpectedResponse: "account1.output",
},
{
Name: "testcase-5",
Args: []string{"ff", "create", "stack-5"},
Args: []string{"create", "stack-5"},
ExpectedResponse: "account1.output",
},
{
Name: "testcase-6",
Args: []string{"ff", "create", "stack-6"},
Args: []string{"create", "stack-6"},
ExpectedResponse: "account1.output",
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/accounts_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestAccountListCmd(t *testing.T) {
if err != nil {
t.Fatalf("Failed to create account for testing: %v", err)
}
Args := []string{"ff", "ls"}
Args := []string{ "ls"}
t.Run("Test-Account-List", func(t *testing.T) {
cmd := accountsListCmd
cmd.SetArgs(Args)
Expand Down
53 changes: 53 additions & 0 deletions cmd/deploy_fabric_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cmd

import (
"context"
"os"
"path/filepath"
"runtime"
"testing"
"time"

"github.com/hyperledger/firefly-cli/internal/utils"
"github.com/stretchr/testify/assert"
)

func TestDeployFabricCmd(t *testing.T) {
var ctx context.Context
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

createCmd := accountsCreateCmd
createCmd.SetArgs([]string{"create", "stack-1"})
err := createCmd.ExecuteContext(ctx)
if err != nil {
t.Fatalf("unable to execute command :%v", err)
}
_, filename, _, ok := runtime.Caller(0)
if !ok {
t.Fatal("Not able to get current working directory")
}
currDir := filepath.Dir(filename)
chainCodefile := filepath.Join(currDir, "testdata", "fabric_deploy.json")
ChaincodePackage, err := utils.ReadFileToString(chainCodefile)
if err != nil {
t.Fatalf("Failed to read expected response file: %v", err)
}
Args := []string{"fabric", ChaincodePackage, "firefly", "fabric-user-1", "1.0"}

t.Run("Test Deploy Cmd", func(t *testing.T) {
DeployFabric := deployFabricCmd
DeployFabric.SetArgs(Args)
DeployFabric.ExecuteContext(ctx)

originalOutput, outBuffer := utils.CaptureOutput()
defer func() {
os.Stdout = originalOutput
}()
DeployFabric.SetOutput(outBuffer)

actualResponse := outBuffer.String()

assert.NotNil(t, actualResponse)
})
}
4 changes: 2 additions & 2 deletions cmd/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ func TestInfoCmd(t *testing.T) {
accNames := []string{"acc-1", "acc-2", "acc-3"}
for _, stacks := range accNames {
createAcc := accountsCreateCmd
createAcc.SetArgs([]string{"ff", "create", stacks})
createAcc.SetArgs([]string{"create", stacks})
err := createAcc.Execute()
if err != nil {
t.Fatalf("unable to execute command :%v", err)
}
args := []string{"ff", "info"}
args := []string{"info"}
t.Run("Info Cmd Test", func(t *testing.T) {
InfoCmd := infoCmd
InfoCmd.SetArgs(args)
Expand Down
12 changes: 12 additions & 0 deletions cmd/testdata/fabric_deploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "fabric-user-1",
"version": "1.0",
"contracts": {
"MyChaincode": {
"GoPath": "firefly",
"Languages": ["go"],
"Dependencies": [],
"Instantiation": {}
}
}
}

0 comments on commit c0ad2ae

Please sign in to comment.