diff --git a/cmd/accounts_create_test.go b/cmd/accounts_create_test.go index e7ecb873..0fbf6f71 100644 --- a/cmd/accounts_create_test.go +++ b/cmd/accounts_create_test.go @@ -2,8 +2,6 @@ package cmd import ( "os" - "path/filepath" - "runtime" "testing" "github.com/hyperledger/firefly-cli/internal/utils" @@ -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 { @@ -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) }) diff --git a/cmd/deploy_ethereum_test.go b/cmd/deploy_ethereum_test.go index 92573087..6827cbdc 100644 --- a/cmd/deploy_ethereum_test.go +++ b/cmd/deploy_ethereum_test.go @@ -4,7 +4,6 @@ import ( "context" "os" "path/filepath" - "runtime" "testing" "time" @@ -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 { diff --git a/cmd/deploy_fabric_test.go b/cmd/deploy_fabric_test.go index e65f3215..348b9453 100644 --- a/cmd/deploy_fabric_test.go +++ b/cmd/deploy_fabric_test.go @@ -4,7 +4,6 @@ import ( "context" "os" "path/filepath" - "runtime" "testing" "time" @@ -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 diff --git a/cmd/testdata/account1.output b/cmd/testdata/account1.output deleted file mode 100644 index e69de29b..00000000 diff --git a/cmd/testdata/eth_deploy.json b/cmd/testdata/eth_deploy.json deleted file mode 100644 index 1e71824e..00000000 --- a/cmd/testdata/eth_deploy.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "contracts": { - "firefly-Ethereum-contrats": { - "abi": [ - { - "constant": false, - "inputs": [ - { - "name": "param1", - "type": "uint256" - }, - { - "name": "param2", - "type": "string" - } - ], - "name": "myFunction", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - } - ], - "bin": "0x606060..." - } - } -} diff --git a/cmd/testdata/fabric_deploy.json b/cmd/testdata/fabric_deploy.json deleted file mode 100644 index ea751709..00000000 --- a/cmd/testdata/fabric_deploy.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "fabric-user-1", - "version": "1.0", - "contracts": { - "MyChaincode": { - "GoPath": "firefly", - "Languages": ["go"], - "Dependencies": [], - "Instantiation": {} - } - } -}