-
Notifications
You must be signed in to change notification settings - Fork 57
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 #286 from Philip-21/cmdtests
cmd tests implementations
- Loading branch information
Showing
142 changed files
with
2,301 additions
and
2,007 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
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,66 @@ | ||
run: | ||
tests: false | ||
skip-dirs: | ||
- "mocks" | ||
- "ffconfig" | ||
- "test/e2e" | ||
linters-settings: | ||
golint: {} | ||
gocritic: | ||
enabled-checks: [] | ||
disabled-checks: | ||
- regexpMust | ||
revive: | ||
rules: | ||
- name: unused-parameter | ||
disabled: true | ||
gosec: | ||
excludes: | ||
- G306 # Needed file permission for local development | ||
- G601 # Appears not to handle taking an address of a sub-structure, within a pointer to a structure within a loop. Which is valid and safe. | ||
goheader: | ||
values: | ||
regexp: | ||
COMPANY: .* | ||
template: |- | ||
Copyright © {{ YEAR }} {{ COMPANY }} | ||
SPDX-License-Identifier: Apache-2.0 | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
linters: | ||
disable-all: false | ||
disable: | ||
- structcheck | ||
enable: | ||
- dogsled | ||
- errcheck | ||
- goconst | ||
- gocritic | ||
- gocyclo | ||
- gofmt | ||
- goheader | ||
- goimports | ||
- goprintffuncname | ||
- gosec | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- misspell | ||
- nakedret | ||
- revive | ||
- staticcheck | ||
- stylecheck | ||
- typecheck | ||
- unconvert | ||
- unused |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright © 2022 Kaleido, Inc. | ||
# Copyright © 2024 Kaleido, Inc. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
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
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,78 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-cli/internal/utils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCreateAccountCmd(t *testing.T) { | ||
|
||
testcases := []struct { | ||
Name string | ||
Args []string | ||
ExpectedResponse string | ||
}{ | ||
{ | ||
Name: "testcase1", | ||
Args: []string{"create", "stack-1"}, | ||
ExpectedResponse: "", | ||
}, | ||
{ | ||
Name: "testcase-2", | ||
Args: []string{"create", "stack-2"}, | ||
ExpectedResponse: "", | ||
}, | ||
{ | ||
Name: "testcase-3", | ||
Args: []string{"create", "stack-3"}, | ||
ExpectedResponse: "", | ||
}, | ||
{ | ||
Name: "testcase-4", | ||
Args: []string{"create", "stack-4"}, | ||
ExpectedResponse: "", | ||
}, | ||
{ | ||
Name: "testcase-5", | ||
Args: []string{"create", "stack-5"}, | ||
ExpectedResponse: "", | ||
}, | ||
{ | ||
Name: "testcase-6", | ||
Args: []string{"create", "stack-6"}, | ||
ExpectedResponse: "", | ||
}, | ||
} | ||
for _, tc := range testcases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
|
||
cmd := accountsCreateCmd | ||
cmd.SetArgs(tc.Args) | ||
|
||
// Capture the output | ||
originalOutput, outputBuffer := utils.CaptureOutput() | ||
defer func() { | ||
// Restore the original output after capturing | ||
os.Stdout = originalOutput | ||
}() | ||
cmd.SetOut(outputBuffer) | ||
|
||
// Execute the command | ||
err := cmd.Execute() | ||
if err != nil { | ||
t.Fatalf("Command execution failed: %v", err) | ||
} | ||
|
||
// Get the actual response | ||
actualResponse := outputBuffer.String() | ||
|
||
// Compare actual and expected responses | ||
assert.Equal(t, tc.ExpectedResponse, actualResponse, "Responses do not match") | ||
|
||
assert.NotNil(t, actualResponse) | ||
}) | ||
} | ||
} |
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,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-cli/internal/utils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAccountListCmd(t *testing.T) { | ||
testNames := []string{"stack-1", "stack-2", "stack-3","stack-4", "stack-5"} | ||
for _, stackNames := range testNames { | ||
createCmd := accountsCreateCmd | ||
createCmd.SetArgs([]string{"ff", "create", stackNames}) | ||
err := createCmd.Execute() | ||
if err != nil { | ||
t.Fatalf("Failed to create account for testing: %v", err) | ||
} | ||
Args := []string{ "ls"} | ||
t.Run("Test-Account-List", func(t *testing.T) { | ||
cmd := accountsListCmd | ||
cmd.SetArgs(Args) | ||
|
||
_, outputBuffer := utils.CaptureOutput() | ||
cmd.SetOut(outputBuffer) | ||
|
||
err := cmd.Execute() | ||
if err != nil { | ||
t.Fatalf("Command execution failed: %v", err) | ||
} | ||
actualResponse := outputBuffer.String() | ||
|
||
assert.NotNil(t, actualResponse) | ||
|
||
}) | ||
} | ||
|
||
} |
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,40 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/hyperledger/firefly-cli/internal/utils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDeployEthereumCmd(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-2"}) | ||
err := createcmd.ExecuteContext(ctx) | ||
if err != nil { | ||
t.Fatalf("unable to create stack : %v", err) | ||
} | ||
currDir := t.TempDir() | ||
contractFile := filepath.Join(currDir + "eth_deploy.json") | ||
Args := []string{"deploy", "ethereum", "stack-2", contractFile, "param1", "param2"} | ||
ethDeployCmd := deployEthereumCmd | ||
ethDeployCmd.SetArgs(Args) | ||
ethDeployCmd.ExecuteContext(ctx) | ||
|
||
Outputwriter, outputBuffer := utils.CaptureOutput() | ||
defer func() { | ||
os.Stdout = Outputwriter | ||
}() | ||
ethDeployCmd.SetOutput(outputBuffer) | ||
|
||
actualResponse := outputBuffer.String() | ||
assert.NotNil(t, actualResponse) | ||
} |
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.