Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd tests implementations #286

Merged
merged 35 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a1898bc
Update dependencies and Go version
nguyer Jan 11, 2024
9871897
Update to Go 1.21
nguyer Jan 12, 2024
27d2432
cmd test implementations
Philip-21 Jan 19, 2024
213753e
account cmd tests
Philip-21 Jan 20, 2024
1d6fded
account cmd tests
Philip-21 Jan 22, 2024
88336be
account cmd tests
Philip-21 Jan 22, 2024
78813c9
info cmd tests
Philip-21 Jan 23, 2024
bdeda39
Fix unit tests and add to Makefile
nguyer Jan 24, 2024
a36b224
Remove lint
nguyer Jan 24, 2024
670bcf8
Apply firefly golangci rules
nguyer Jan 24, 2024
70c0c6a
Merge branch 'dependencies' into fix-tests
nguyer Jan 24, 2024
8c2a78a
Merge branch 'main' into fix-tests
nguyer Jan 24, 2024
4e9dd15
Add go mod tidy to Makefile
nguyer Jan 24, 2024
8f78516
Fix unit test
nguyer Jan 24, 2024
99ad4ba
Merge remote-tracking branch 'origin/main' into cmdtests
Philip-21 Jan 24, 2024
c0ad2ae
new tests
Philip-21 Jan 25, 2024
128d3b7
eth cmd tests
Philip-21 Jan 25, 2024
c6946cd
eth cmd tests
Philip-21 Jan 27, 2024
4dcceb0
tezos tests
Philip-21 Jan 29, 2024
2a29589
eth tests
Philip-21 Jan 31, 2024
0080595
eth tests
Philip-21 Feb 1, 2024
4c08dc4
eth tests
Philip-21 Feb 2, 2024
409b9b2
tezos tests
Philip-21 Feb 7, 2024
663c5c2
tezos tests
Philip-21 Feb 7, 2024
13a31f4
evm connect tests
Philip-21 Feb 8, 2024
45862d3
eth connect tests
Philip-21 Feb 8, 2024
875c779
Merge fix-tests branch from fixtests remote
Philip-21 Feb 14, 2024
c7e5a95
tidying modules
Philip-21 Feb 14, 2024
3eebaed
working on failed tests, removing testfiles
Philip-21 Feb 14, 2024
e971aac
working on failed tests, removing testfiles
Philip-21 Feb 14, 2024
fc98ebb
blockchain signer tests
Philip-21 Feb 14, 2024
1cc11e9
using temDir() and removing testfiles
Philip-21 Feb 14, 2024
89db167
fabric tests, tempDir() adjustments
Philip-21 Feb 14, 2024
b3e1818
cmdtest adjustments
Philip-21 Feb 15, 2024
c7061ab
asjustment and new signer test
Philip-21 Feb 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.18
go-version: "1.21"
- name: Compile FireFly CLI
run: make
10 changes: 5 additions & 5 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ jobs:
fail-fast: false
steps:
- name: Checkout FireFly CLI
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: firefly-cli
fetch-depth: 0
- name: Checkout FireFly Core repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: hyperledger/firefly
path: firefly

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.18
go-version: "1.21"

- name: Compile FireFly CLI
working-directory: firefly-cli
Expand All @@ -63,7 +63,7 @@ jobs:
run: ./test/e2e/run.sh

- name: Archive container logs
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: container-logs-${{ matrix.test-suite }}-${{ matrix.blockchain-provider }}-${{ matrix.database-type }}-${{ matrix.token-provider }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.18
go-version: "1.21"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright © 2021 Kaleido, Inc.
# Copyright © 2024 Kaleido, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
Expand All @@ -22,3 +22,4 @@ dist/
*.iml
.idea/
docs/command_docs
coverage.txt
66 changes: 66 additions & 0 deletions .golangci.yml
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
2 changes: 1 addition & 1 deletion .goreleaser.yml
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
#
Expand Down
14 changes: 9 additions & 5 deletions Makefile
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
#
Expand All @@ -20,7 +20,9 @@ GITREF := $(shell git rev-parse --short HEAD)
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LINT := $(GOBIN)/golangci-lint

all: build
all: build lint test tidy
test: deps
$(VGO) test ./internal/... ./pkg/... ./cmd/... -cover -coverprofile=coverage.txt -covermode=atomic -timeout=30s ${TEST_ARGS}
build: ## Builds all go code
cd ff && go build -ldflags="-X 'github.com/hyperledger/firefly-cli/cmd.BuildDate=$(DATE)' -X 'github.com/hyperledger/firefly-cli/cmd.BuildCommit=$(GITREF)'"
install: ## Installs the package
Expand All @@ -31,10 +33,12 @@ lint: ${LINT} ## Checks and reports lint errors

${LINT}:
$(VGO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest


deps:
cd ff && $(VGO) get
help: ## Show this help
@echo 'usage: make [target] ...'
@echo ''
@echo 'targets:'
@egrep '^(.+)\:\ .*##\ (.+)' ${MAKEFILE_LIST} | sed 's/:.*##/#/' | column -t -c 2 -s '#'
@egrep '^(.+)\:\ .*##\ (.+)' ${MAKEFILE_LIST} | sed 's/:.*##/#/' | column -t -c 2 -s '#'
tidy:
$(VGO) mod tidy
2 changes: 1 addition & 1 deletion cmd/accounts.go
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
//
Expand Down
2 changes: 1 addition & 1 deletion cmd/accounts_create.go
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
//
Expand Down
78 changes: 78 additions & 0 deletions cmd/accounts_create_test.go
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)
})
}
}
2 changes: 1 addition & 1 deletion cmd/accounts_list.go
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
//
Expand Down
38 changes: 38 additions & 0 deletions cmd/accounts_list_test.go
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)

})
}

}
2 changes: 1 addition & 1 deletion cmd/deploy.go
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
//
Expand Down
2 changes: 1 addition & 1 deletion cmd/deploy_ethereum.go
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
//
Expand Down
40 changes: 40 additions & 0 deletions cmd/deploy_ethereum_test.go
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)
}
2 changes: 1 addition & 1 deletion cmd/deploy_fabric.go
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
//
Expand Down