Skip to content

Commit

Permalink
cmdtest adjustments
Browse files Browse the repository at this point in the history
Signed-off-by: Philip-21 <[email protected]>
  • Loading branch information
Philip-21 committed Feb 15, 2024
1 parent 89db167 commit b3e1818
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 79 deletions.
28 changes: 7 additions & 21 deletions cmd/accounts_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package cmd

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

"github.com/hyperledger/firefly-cli/internal/utils"
Expand All @@ -20,32 +18,32 @@ func TestCreateAccountCmd(t *testing.T) {
{
Name: "testcase1",
Args: []string{"create", "stack-1"},
ExpectedResponse: "account1.output",
ExpectedResponse: "",
},
{
Name: "testcase-2",
Args: []string{"create", "stack-2"},
ExpectedResponse: "account1.output",
ExpectedResponse: "",
},
{
Name: "testcase-3",
Args: []string{"create", "stack-3"},
ExpectedResponse: "account1.output",
ExpectedResponse: "",
},
{
Name: "testcase-4",
Args: []string{"create", "stack-4"},
ExpectedResponse: "account1.output",
ExpectedResponse: "",
},
{
Name: "testcase-5",
Args: []string{"create", "stack-5"},
ExpectedResponse: "account1.output",
ExpectedResponse: "",
},
{
Name: "testcase-6",
Args: []string{"create", "stack-6"},
ExpectedResponse: "account1.output",
ExpectedResponse: "",
},
}
for _, tc := range testcases {
Expand All @@ -70,21 +68,9 @@ func TestCreateAccountCmd(t *testing.T) {

// Get the actual response
actualResponse := outputBuffer.String()
// Load the expected response from file
// get current directory
_, filename, _, ok := runtime.Caller(0)
if !ok {
t.Fatal("Not able to get current working directory")
}
currDir := filepath.Dir(filename)
expectedResponseFile := filepath.Join(currDir, "testdata", tc.ExpectedResponse)
expectedResponse, err := utils.ReadFileToString(expectedResponseFile)
if err != nil {
t.Fatalf("Failed to read expected response file: %v", err)
}

// Compare actual and expected responses
assert.Equal(t, expectedResponse, actualResponse, "Responses do not match")
assert.Equal(t, tc.ExpectedResponse, actualResponse, "Responses do not match")

assert.NotNil(t, actualResponse)
})
Expand Down
9 changes: 2 additions & 7 deletions cmd/deploy_ethereum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"os"
"path/filepath"
"runtime"
"testing"
"time"

Expand All @@ -23,12 +22,8 @@ func TestDeployEthereumCmd(t *testing.T) {
if err != nil {
t.Fatalf("unable to create stack : %v", err)
}
_, filename, _, ok := runtime.Caller(0)
if !ok {
t.Fatal("Not able to get current working directory")
}
currDir := filepath.Dir(filename)
contractFile := filepath.Join(currDir, "testdata", "eth_deploy.json")
currDir := t.TempDir()
contractFile := filepath.Join(currDir + "eth_deploy.json")

ethPackage, err := utils.ReadFileToString(contractFile)
if err != nil {
Expand Down
15 changes: 3 additions & 12 deletions cmd/deploy_fabric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"os"
"path/filepath"
"runtime"
"testing"
"time"

Expand All @@ -23,17 +22,9 @@ func TestDeployFabricCmd(t *testing.T) {
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", "stack-1", ChaincodePackage, "firefly", "fabric-user-1", "1.0"}
currDir := t.TempDir()
chainCodefile := filepath.Join(currDir + "fabric_deploy.json")
Args := []string{"fabric", "stack-1", chainCodefile, "firefly", "fabric-user-1", "1.0"}

t.Run("Test Deploy Cmd", func(t *testing.T) {
DeployFabric := deployFabricCmd
Expand Down
Empty file removed cmd/testdata/account1.output
Empty file.
27 changes: 0 additions & 27 deletions cmd/testdata/eth_deploy.json

This file was deleted.

12 changes: 0 additions & 12 deletions cmd/testdata/fabric_deploy.json

This file was deleted.

0 comments on commit b3e1818

Please sign in to comment.