Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions tests/e2e/commandse2e/blockchain/deploy/suite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package deploy

import (
"fmt"

"github.com/ava-labs/avalanche-cli/tests/e2e/commandse2e"

"github.com/ava-labs/avalanche-cli/tests/e2e/commands"
ginkgo "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)

const (
subnetName = "testSubnet"
)

var (

Check failure on line 20 in tests/e2e/commandse2e/blockchain/deploy/suite.go

View workflow job for this annotation

GitHub Actions / Lint

File is not properly formatted (gofumpt)
err error

Check failure on line 21 in tests/e2e/commandse2e/blockchain/deploy/suite.go

View workflow job for this annotation

GitHub Actions / Lint

var `err` is unused (unused)
)

const ewoqEVMAddress = "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"

var _ = ginkgo.Describe("[Blockchain Deploy Flags]", ginkgo.Ordered, func() {
_ = ginkgo.BeforeEach(func() {
// Create test subnet config
commands.CreateEtnaSubnetEvmConfig(subnetName, ewoqEVMAddress, commands.PoA)
})

ginkgo.AfterEach(func() {
commands.CleanNetwork()
// Cleanup test subnet config
commands.DeleteSubnetConfig(subnetName)
})
blockchainCmdArgs := []string{subnetName}
ginkgo.It("HAPPY PATH: local deploy default", func() {
testFlags := commandse2e.TestFlags{}
output, err := commandse2e.TestCommand(commandse2e.BlockchainCmd, "deploy", blockchainCmdArgs, testFlags)
gomega.Expect(output).Should(gomega.ContainSubstring("L1 is successfully deployed on Local Network"))
gomega.Expect(err).Should(gomega.BeNil())
})

ginkgo.It("ERROR PATH: invalid_version", func() {
testFlags := commandse2e.TestFlags{
"avalanchego-version": "invalid_version",
}
output, err := commandse2e.TestCommand(commandse2e.BlockchainCmd, "deploy", blockchainCmdArgs, testFlags)
fmt.Printf("obtained output %s \n", string(output))

Check failure on line 50 in tests/e2e/commandse2e/blockchain/deploy/suite.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary conversion (unconvert)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("invalid version string"))
})
})
Comment on lines 24 to 47
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of how to use it

74 changes: 74 additions & 0 deletions tests/e2e/commandse2e/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package commandse2e

import (
"errors"
"fmt"
"os/exec"

"github.com/ava-labs/avalanche-cli/tests/e2e/utils"
)

type TestFlags map[string]string

// CommandGroup represents the different command groups available in the CLI
type CommandGroup string

const (
BlockchainCmd CommandGroup = "blockchain"
)

var avalancheBinaryPath = "./bin/avalanche"

var GlobalFlags = map[string]interface{}{
"local": true,
"skip-icm-deploy": true,
"skip-update-check": true,
}

// TestCommand tests a CLI command with flag inputs
func TestCommand(commandGroup CommandGroup, command string, args []string, testFlags TestFlags) (string, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core test function

// Build command arguments
cmdArgs := []string{string(commandGroup), command}

// Append any additional arguments
if len(args) > 0 {
cmdArgs = append(cmdArgs, args...)
}

// Create a map to store all flags, starting with global flags
allFlags := make(map[string]interface{})
for flag, value := range GlobalFlags {
allFlags[flag] = value
}

// Override with test case specific flags if provided
for flag, value := range testFlags {
allFlags[flag] = value
}

// Add all flags to command arguments
for flag, value := range allFlags {
cmdArgs = append(cmdArgs, "--"+flag+"="+fmt.Sprintf("%v", value))
}

// Execute the command
cmd := exec.Command(avalancheBinaryPath, cmdArgs...)
fmt.Println(cmd)
output, err := cmd.CombinedOutput()
if err != nil {
var (
exitErr *exec.ExitError
stderr string
)
if errors.As(err, &exitErr) {
stderr = string(exitErr.Stderr)
}
fmt.Println(string(output))
utils.PrintStdErr(err)
fmt.Println(stderr)
}

return string(output), err
}
1 change: 1 addition & 0 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/ava-labs/avalanche-cli/pkg/utils"
_ "github.com/ava-labs/avalanche-cli/tests/e2e/commandse2e/blockchain/deploy"
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/apm"
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/errhandling"
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/key"
Expand Down
Loading